Java Code Examples for com.google.common.io.LittleEndianDataOutputStream#close()
The following examples show how to use
com.google.common.io.LittleEndianDataOutputStream#close() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FileSerializationBenchmark.java From imhotep with Apache License 2.0 | 5 votes |
@Override public void serialize(int[] a, File file) throws IOException { LittleEndianDataOutputStream os = new LittleEndianDataOutputStream(new BufferedOutputStream(new FileOutputStream(file))); for (int val : a) { os.writeInt(val); } os.close(); }
Example 2
Source File: TestWeirdStuff.java From util with Apache License 2.0 | 5 votes |
private void writeFile() throws IOException { mmapFile = new File(tmpDir, "mmap"); LittleEndianDataOutputStream out = new LittleEndianDataOutputStream(new BufferedOutputStream(new FileOutputStream(mmapFile), 65536)); //write 8 mb of crap to ensure multiple pages have been written for (int i = 0; i < 2 * 1024 * 1024; i++) { out.writeInt(i); } out.close(); }
Example 3
Source File: GuavaIOUnitTest.java From tutorials with MIT License | 5 votes |
@Test public void whenWriteReadLittleEndian_thenCorrect() throws IOException { final int value = 100; final LittleEndianDataOutputStream writer = new LittleEndianDataOutputStream(new FileOutputStream("src/test/resources/test_le.txt")); writer.writeInt(value); writer.close(); final LittleEndianDataInputStream reader = new LittleEndianDataInputStream(new DataInputStream(new FileInputStream("src/test/resources/test_le.txt"))); final int result = reader.readInt(); reader.close(); assertEquals(value, result); }
Example 4
Source File: ImmutableBTreeIndex.java From lsmtree with Apache License 2.0 | 4 votes |
private static <K,V> WriteLevelResult writeLevel( final CountingOutputStream counter, final Path tempPath, final Iterator<Generation.Entry<K,V>> iterator, final Serializer<K> keySerializer, final Serializer<V> valueSerializer, final int blocksize, final boolean keepDeletions ) throws IOException { Generation.Entry<K,V> next; if (!iterator.hasNext()) { return new WriteLevelResult(0, 0); } next = iterator.next(); final LittleEndianDataOutputStream tmpOut = new LittleEndianDataOutputStream(new BufferedOutputStream(Files.newOutputStream(tempPath), 131072)); final ByteArrayOutputStream buffer = new ByteArrayOutputStream(); final LittleEndianDataOutputStream bufferDataOutput = new LittleEndianDataOutputStream(buffer); final ByteArrayOutputStream currentBlock = new ByteArrayOutputStream(blocksize); final CharArrayList keyOffsets = new CharArrayList(); int tmpCount = 0; boolean done = false; final LittleEndianDataOutputStream out = new LittleEndianDataOutputStream(counter); long count = 0; outer: while (!done) { currentBlock.reset(); keyOffsets.clear(); if (!keepDeletions) { while (next.isDeleted()) { if (!iterator.hasNext()) break outer; next = iterator.next(); } } keySerializer.write(next.getKey(), tmpOut); tmpOut.writeLong(counter.getCount()); tmpCount++; while (true) { buffer.reset(); final boolean skipDeleted = updateBuffer(next, keySerializer, valueSerializer, keepDeletions, bufferDataOutput); if (4+2*keyOffsets.size()+2+currentBlock.size()+buffer.size() > blocksize) { if (currentBlock.size() == 0) { throw new IllegalArgumentException("key value pair is greater than block size"); } break; } if (!skipDeleted) { keyOffsets.add((char)currentBlock.size()); buffer.writeTo(currentBlock); count++; } if (!iterator.hasNext()) { done = true; break; } next = iterator.next(); } if (keyOffsets.size() > 0) { final long start = counter.getCount(); out.writeInt(keyOffsets.size()); for (int i = 0; i < keyOffsets.size(); i++) { out.writeChar(keyOffsets.getChar(i)); } currentBlock.writeTo(out); if (counter.getCount()-start > blocksize) { log.error("too big"); } } } tmpOut.close(); return new WriteLevelResult(tmpCount, count); }