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();
}
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);
}
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()));
}
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));
}
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();
}
}
Aggregations