use of java.io.OutputStream in project grails-core by grails.
the class StreamByteBufferTest method testStreamByteBuffer.
public void testStreamByteBuffer() throws Exception {
StreamByteBuffer streamBuf = new StreamByteBuffer(32000);
OutputStream output = streamBuf.getOutputStream();
output.write(1);
output.write(2);
output.write(3);
output.write(255);
output.close();
InputStream input = streamBuf.getInputStream();
assertEquals(1, input.read());
assertEquals(2, input.read());
assertEquals(3, input.read());
assertEquals(255, input.read());
assertEquals(-1, input.read());
input.close();
}
use of java.io.OutputStream in project grails-core by grails.
the class StreamByteBufferTest method createTestInstance.
private StreamByteBuffer createTestInstance() throws IOException {
StreamByteBuffer byteBuffer = new StreamByteBuffer();
OutputStream output = byteBuffer.getOutputStream();
copyAllFromTestBuffer(output, 27);
return byteBuffer;
}
use of java.io.OutputStream in project grails-core by grails.
the class StreamByteBufferTest method bufferTest.
private void bufferTest(int streamByteBufferSize, int testBufferSize) throws IOException {
StreamByteBuffer streamBuf = new StreamByteBuffer(streamByteBufferSize);
OutputStream output = streamBuf.getOutputStream();
for (int i = 0; i < testBufferSize; i++) {
output.write(i % (Byte.MAX_VALUE * 2));
}
output.close();
byte[] buffer = new byte[testBufferSize];
InputStream input = streamBuf.getInputStream();
assertEquals(testBufferSize, input.available());
int readBytes = input.read(buffer);
assertEquals(readBytes, testBufferSize);
for (int i = 0; i < buffer.length; i++) {
assertEquals((byte) (i % (Byte.MAX_VALUE * 2)), buffer[i]);
}
assertEquals(-1, input.read());
assertEquals(-1, input.read());
assertEquals(-1, input.read());
assertEquals(-1, input.read());
input.close();
}
use of java.io.OutputStream in project gradle by gradle.
the class MapFileTreeTest method containsWontCreateFiles.
@Test
public void containsWontCreateFiles() {
final AtomicInteger callCounter = new AtomicInteger(0);
Action<OutputStream> fileAction = new Action<OutputStream>() {
@Override
public void execute(OutputStream outputStream) {
callCounter.incrementAndGet();
}
};
tree.add("file.txt", fileAction);
FileTreeAdapter fileTreeAdapter = new FileTreeAdapter(tree);
File file = rootDir.file("file.txt");
assertTrue(fileTreeAdapter.contains(file));
assertTrue(fileTreeAdapter.contains(file));
assertFalse(fileTreeAdapter.contains(rootDir.file("file2.txt")));
assertEquals(0, callCounter.get());
}
use of java.io.OutputStream in project gradle by gradle.
the class MapFileTreeTest method overwritesFileWhenGeneratedContentChanges.
@Test
public void overwritesFileWhenGeneratedContentChanges() {
final AtomicReference<String> currentContentReference = new AtomicReference<String>("content");
tree.add("path/file.txt", new Action<OutputStream>() {
@Override
public void execute(OutputStream outputStream) {
try {
outputStream.write(currentContentReference.get().getBytes());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
});
assertVisits(tree, toList("path/file.txt"), toList("path"));
TestFile file = rootDir.file("path/file.txt");
file.assertContents(equalTo("content"));
TestFile.Snapshot snapshot = file.snapshot();
currentContentReference.set("updated content");
assertVisits(tree, toList("path/file.txt"), toList("path"));
file.assertContents(equalTo("updated content"));
file.assertHasChangedSince(snapshot);
}
Aggregations