-package net.pterodactylus.fcp;\r
-\r
-import org.junit.Test;\r
-\r
-import java.io.ByteArrayInputStream;\r
-import java.io.IOException;\r
-import java.io.InputStream;\r
-import java.util.Arrays;\r
-\r
-import static org.hamcrest.MatcherAssert.assertThat;\r
-import static org.hamcrest.Matchers.is;\r
-import static org.junit.Assert.assertArrayEquals;\r
-\r
-\r
-public class TempInputStreamTest {\r
-\r
- private byte[] prepareArrayOfNBytes(int n) {\r
- byte[] data = new byte[n];\r
- for (int i = 0; i < n; ++i) {\r
- data[i] = (byte)i;\r
- }\r
- return data;\r
- }\r
-\r
- private void checkTempInputStreamStoresPartOfAnotherStream(int length, int maxMemoryLength) throws IOException {\r
- byte[] originalData = prepareArrayOfNBytes(length + 1);\r
- InputStream anotherStream = new ByteArrayInputStream(originalData);\r
- FcpUtils.TempInputStream cut = new FcpUtils.TempInputStream(anotherStream, length, maxMemoryLength);\r
-\r
- // check length bytes are read from anotherStream and are accessible from cut\r
- byte[] buffer = new byte[length];\r
- int n = cut.read(buffer);\r
- assertThat(n, is(length));\r
- assertArrayEquals(Arrays.copyOf(originalData, length), buffer);\r
- assertThat(cut.read(), is(-1)); // check end of cut stream\r
-\r
- // check the rest of data in anotherStream is still there\r
- n = anotherStream.read(buffer);\r
- assertThat(n, is(1));\r
- assertThat(buffer[0], is(originalData[originalData.length - 1]));\r
- assertThat(anotherStream.read(), is(-1)); // check end of another stream\r
- }\r
-\r
- @Test\r
- public void tempInputStreamShouldCorrectlyStorePartOfAnotherStreamInMemory() throws IOException {\r
- checkTempInputStreamStoresPartOfAnotherStream(1, 1);\r
- }\r
-\r
- @Test\r
- public void tempInputStreamShouldCorrectlyStorePartOfAnotherStreamInFile() throws IOException {\r
- checkTempInputStreamStoresPartOfAnotherStream(2, 1);\r
- }\r
-\r
-}\r
+package net.pterodactylus.fcp;
+
+import org.junit.Test;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Arrays;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.is;
+import static org.junit.Assert.assertArrayEquals;
+
+
+public class TempInputStreamTest {
+
+ private byte[] prepareArrayOfNBytes(int n) {
+ byte[] data = new byte[n];
+ for (int i = 0; i < n; ++i) {
+ data[i] = (byte)i;
+ }
+ return data;
+ }
+
+ private void checkTempInputStreamStoresPartOfAnotherStream(int length, int maxMemoryLength) throws IOException {
+ byte[] originalData = prepareArrayOfNBytes(length + 1);
+ InputStream anotherStream = new ByteArrayInputStream(originalData);
+ FcpUtils.TempInputStream cut = new FcpUtils.TempInputStream(anotherStream, length, maxMemoryLength);
+
+ // check length bytes are read from anotherStream and are accessible from cut
+ byte[] buffer = new byte[length];
+ int n = cut.read(buffer);
+ assertThat(n, is(length));
+ assertArrayEquals(Arrays.copyOf(originalData, length), buffer);
+ assertThat(cut.read(), is(-1)); // check end of cut stream
+
+ // check the rest of data in anotherStream is still there
+ n = anotherStream.read(buffer);
+ assertThat(n, is(1));
+ assertThat(buffer[0], is(originalData[originalData.length - 1]));
+ assertThat(anotherStream.read(), is(-1)); // check end of another stream
+ }
+
+ @Test
+ public void tempInputStreamShouldCorrectlyStorePartOfAnotherStreamInMemory() throws IOException {
+ checkTempInputStreamStoresPartOfAnotherStream(1, 1);
+ }
+
+ @Test
+ public void tempInputStreamShouldCorrectlyStorePartOfAnotherStreamInFile() throws IOException {
+ checkTempInputStreamStoresPartOfAnotherStream(2, 1);
+ }
+
+}