/** Convert writables to a byte array */ public static byte[] toByteArray(Writable... writables) { final DataOutputBuffer out = new DataOutputBuffer(); try { for(Writable w : writables) { w.write(out); } out.close(); } catch (IOException e) { throw new RuntimeException("Fail to convert writables to a byte array",e); } return out.getData(); }
@Override public void close() throws IOException { inBuf.close(); outBuf.close(); deserializer.close(); serializer.close(); }
@Override public byte[] serialize() throws IOException { DataOutputBuffer dob = new DataOutputBuffer(5); dob.writeInt(masterKeyId); dob.write(index); byte[] b = dob.getData(); dob.close(); return b; }
/** Read a compressed buffer */ private synchronized void readBuffer(DataInputBuffer buffer, CompressionInputStream filter) throws IOException { // Read data into a temporary buffer DataOutputBuffer dataBuffer = new DataOutputBuffer(); try { int dataBufferLength = WritableUtils.readVInt(in); dataBuffer.write(in, dataBufferLength); // Set up 'buffer' connected to the input-stream buffer.reset(dataBuffer.getData(), 0, dataBuffer.getLength()); } finally { dataBuffer.close(); } // Reset the codec filter.resetState(); }
/** * Closes open buffers * * @throws IOException */ @Override public void close() throws IOException { fsin.close(); buffer.close(); }
/** * Closes open buffers * * @throws IOException */ @Override public void close() throws IOException { fsin.close(); buffer.close(); }
@Test public void testFSCheckpointIDSerialization() throws IOException { Path inpath = new Path("/tmp/blah"); FSCheckpointID cidin = new FSCheckpointID(inpath); DataOutputBuffer out = new DataOutputBuffer(); cidin.write(out); out.close(); FSCheckpointID cidout = new FSCheckpointID(null); DataInputBuffer in = new DataInputBuffer(); in.reset(out.getData(), 0, out.getLength()); cidout.readFields(in); in.close(); assert cidin.equals(cidout); }
@Override public void close() throws IOException { if (closed) { return; } out.close(); closed = true; }
@Override public void close() throws IOException { if (closed) { return; } out.close(); closed = true; }
/** * Close the file. */ public synchronized void close() throws IOException { outputBuffer.close(); ser.close(); innerWriter.close(); }
@Override public void close() throws IOException { inBuf.close(); outBuf.close(); deserializer.close(); serializer.close(); }
@Override public void close() throws IOException { inBuf.close(); outBuf.close(); deserializer.close(); serializer.close(); }
@Override public void close() throws IOException { inBuf.close(); outBuf.close(); deserializer.close(); serializer.close(); }
public void close() throws IOException { inBuf.close(); outBuf.close(); deserializer.close(); serializer.close(); }
public void close() throws IOException { inBuf.close(); outBuf.close(); deserializer.close(); serializer.close(); }
@Override public void close() throws IOException { inBuf.close(); outBuf.close(); deserializer.close(); serializer.close(); }
private void validate(KeyValue kv, byte[] row, byte[] family, byte[] qualifier, long ts, Type type, byte[] value) throws IOException { DataOutputBuffer out = new DataOutputBuffer(); kv.write(out); out.close(); byte[] data = out.getData(); // read it back in KeyValue read = new KeyValue(); DataInputBuffer in = new DataInputBuffer(); in.reset(data, data.length); read.readFields(in); in.close(); // validate that its the same assertTrue("Row didn't match!", Bytes.equals(row, read.getRow())); assertTrue("Family didn't match!", Bytes.equals(family, read.getFamily())); assertTrue("Qualifier didn't match!", Bytes.equals(qualifier, read.getQualifier())); assertTrue("Value didn't match!", Bytes.equals(value, read.getValue())); assertEquals("Timestamp didn't match", ts, read.getTimestamp()); assertEquals("Type didn't match", type.getCode(), read.getType()); }