Update OutputStreamToByteArrayUnitTest.java
This commit is contained in:
parent
3ca05da859
commit
47baa5041b
|
@ -22,7 +22,7 @@ public class OutputStreamToByteArrayUnitTest {
|
||||||
outputStream.write(data.getBytes(StandardCharsets.UTF_8));
|
outputStream.write(data.getBytes(StandardCharsets.UTF_8));
|
||||||
}
|
}
|
||||||
|
|
||||||
byte[] writtenData = FileUtils.readFileToByteArray(new File(filePath.toUri()));
|
byte[] writtenData = FileUtils.readFileToByteArray(filePath.toFile());
|
||||||
String result = new String(writtenData, StandardCharsets.UTF_8);
|
String result = new String(writtenData, StandardCharsets.UTF_8);
|
||||||
assertEquals(data, result);
|
assertEquals(data, result);
|
||||||
}
|
}
|
||||||
|
@ -34,15 +34,19 @@ public class OutputStreamToByteArrayUnitTest {
|
||||||
String fileName = "file.txt";
|
String fileName = "file.txt";
|
||||||
Path filePath = tempDir.resolve(fileName);
|
Path filePath = tempDir.resolve(fileName);
|
||||||
|
|
||||||
try (DrainableOutputStream drainableOutputStream = new DrainableOutputStream(new FileOutputStream(filePath.toFile()))) {
|
DrainableOutputStream drainableOutputStream = new DrainableOutputStream(new FileOutputStream(filePath.toFile()));
|
||||||
|
|
||||||
|
try {
|
||||||
drainableOutputStream.write(data.getBytes(StandardCharsets.UTF_8));
|
drainableOutputStream.write(data.getBytes(StandardCharsets.UTF_8));
|
||||||
byte[] writtenData = drainableOutputStream.toByteArray();
|
} finally {
|
||||||
assertEquals(data, new String(writtenData, StandardCharsets.UTF_8));
|
drainableOutputStream.close();
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
byte[] writtenData = drainableOutputStream.toByteArray();
|
||||||
|
assertEquals(data, new String(writtenData, StandardCharsets.UTF_8));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public class DrainableOutputStream extends FilterOutputStream {
|
public class DrainableOutputStream extends FilterOutputStream {
|
||||||
private final ByteArrayOutputStream buffer;
|
private final ByteArrayOutputStream buffer;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue