Search in sources :

Example 81 with ByteArrayOutputStream

use of java.io.ByteArrayOutputStream in project commons by twitter.

the class TokenStreamSerializer method serialize.

/**
   * Same as above but serializers a lucene TwitterTokenStream.
   */
public final byte[] serialize(final org.apache.lucene.analysis.TokenStream tokenStream) throws IOException {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    AttributeOutputStream output = new AttributeOutputStream(baos);
    for (AttributeSerializer serializer : attributeSerializers) {
        serializer.initialize(tokenStream, CURRENT_VERSION);
    }
    int numTokens = 0;
    while (tokenStream.incrementToken()) {
        serializeAttributes(output);
        numTokens++;
    }
    output.flush();
    byte[] data = baos.toByteArray();
    baos.close();
    baos = new ByteArrayOutputStream(8 + data.length);
    output = new AttributeOutputStream(baos);
    output.writeVInt(CURRENT_VERSION.ordinal());
    output.writeInt(attributeSerializersFingerprint);
    output.writeVInt(numTokens);
    output.write(data);
    output.flush();
    return baos.toByteArray();
}
Also used : ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 82 with ByteArrayOutputStream

use of java.io.ByteArrayOutputStream in project robospice by stephanenicolas.

the class OkHttpSmallBinaryRequest method processStream.

@Override
public InputStream processStream(final int contentLength, final InputStream inputStream) throws IOException {
    final ByteArrayOutputStream bos = new ByteArrayOutputStream();
    readBytes(inputStream, new ProgressByteProcessor(this, bos, contentLength));
    final byte[] bytes = bos.toByteArray();
    return new ByteArrayInputStream(bytes);
}
Also used : ProgressByteProcessor(com.octo.android.robospice.request.ProgressByteProcessor) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 83 with ByteArrayOutputStream

use of java.io.ByteArrayOutputStream in project robospice by stephanenicolas.

the class InFileBigInputStreamObjectPersisterTest method testSaveDataToCacheAndReturnData.

public void testSaveDataToCacheAndReturnData() throws Exception {
    inputStreamPersister.saveDataToCacheAndReturnData(new ByteArrayInputStream("coucou".getBytes()), TEST_CACHE_KEY);
    File cachedFile = inputStreamPersister.getCacheFile(TEST_CACHE_KEY);
    assertTrue(cachedFile.exists());
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    IOUtils.copy(new FileInputStream(cachedFile), bos);
    assertTrue(Arrays.equals("coucou".getBytes(), bos.toByteArray()));
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) File(java.io.File) FileInputStream(java.io.FileInputStream)

Example 84 with ByteArrayOutputStream

use of java.io.ByteArrayOutputStream in project skype-java-api by taksan.

the class AutoDebugOutTest method initSysOutRecorder.

private void initSysOutRecorder() {
    out = new ByteArrayOutputStream();
    System.setOut(new PrintStream(out));
}
Also used : PrintStream(java.io.PrintStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 85 with ByteArrayOutputStream

use of java.io.ByteArrayOutputStream in project playn by threerings.

the class AndroidAssets method getBytesSync.

@Override
public byte[] getBytesSync(String path) throws Exception {
    InputStream is = openAsset(path);
    try {
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        byte[] buf = new byte[1024];
        while (true) {
            int r = is.read(buf);
            if (r == -1) {
                break;
            }
            out.write(buf, 0, r);
        }
        return out.toByteArray();
    } finally {
        is.close();
    }
}
Also used : InputStream(java.io.InputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Aggregations

ByteArrayOutputStream (java.io.ByteArrayOutputStream)8438 Test (org.junit.Test)2232 ByteArrayInputStream (java.io.ByteArrayInputStream)2148 IOException (java.io.IOException)2037 PrintStream (java.io.PrintStream)800 InputStream (java.io.InputStream)765 ObjectOutputStream (java.io.ObjectOutputStream)759 DataOutputStream (java.io.DataOutputStream)705 ObjectInputStream (java.io.ObjectInputStream)361 File (java.io.File)331 OutputStream (java.io.OutputStream)318 HashMap (java.util.HashMap)279 ArrayList (java.util.ArrayList)264 FileInputStream (java.io.FileInputStream)211 OutputStreamWriter (java.io.OutputStreamWriter)207 DataInputStream (java.io.DataInputStream)198 Test (org.testng.annotations.Test)184 PrintWriter (java.io.PrintWriter)162 URL (java.net.URL)160 Map (java.util.Map)158