Search in sources :

Example 91 with OutputStream

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();
}
Also used : InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) StreamByteBuffer(org.grails.buffer.StreamByteBuffer)

Example 92 with OutputStream

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;
}
Also used : OutputStream(java.io.OutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) StreamByteBuffer(org.grails.buffer.StreamByteBuffer)

Example 93 with OutputStream

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();
}
Also used : InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) StreamByteBuffer(org.grails.buffer.StreamByteBuffer)

Example 94 with OutputStream

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());
}
Also used : Action(org.gradle.api.Action) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) OutputStream(java.io.OutputStream) File(java.io.File) TestFile(org.gradle.test.fixtures.file.TestFile) Test(org.junit.Test)

Example 95 with OutputStream

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);
}
Also used : OutputStream(java.io.OutputStream) TestFile(org.gradle.test.fixtures.file.TestFile) AtomicReference(java.util.concurrent.atomic.AtomicReference) IOException(java.io.IOException) UncheckedIOException(org.gradle.api.UncheckedIOException) Test(org.junit.Test)

Aggregations

OutputStream (java.io.OutputStream)4178 IOException (java.io.IOException)1673 FileOutputStream (java.io.FileOutputStream)1331 InputStream (java.io.InputStream)1304 File (java.io.File)925 ByteArrayOutputStream (java.io.ByteArrayOutputStream)830 Test (org.junit.Test)735 BufferedOutputStream (java.io.BufferedOutputStream)477 FileInputStream (java.io.FileInputStream)431 Socket (java.net.Socket)375 ByteArrayInputStream (java.io.ByteArrayInputStream)233 URL (java.net.URL)231 OutputStreamWriter (java.io.OutputStreamWriter)230 HttpURLConnection (java.net.HttpURLConnection)189 BufferedInputStream (java.io.BufferedInputStream)178 InputStreamReader (java.io.InputStreamReader)176 BufferedReader (java.io.BufferedReader)159 FileNotFoundException (java.io.FileNotFoundException)158 GZIPOutputStream (java.util.zip.GZIPOutputStream)157 Path (java.nio.file.Path)155