List of usage examples for org.apache.hadoop.io Writable write
void write(DataOutput out) throws IOException;
out
. From source file:com.google.mr4c.hadoop.HadoopTestUtils.java
License:Open Source License
/** * Copies writable using the readFields() and write() methods *//*from w ww .j a v a 2s. c o m*/ public static void copyWritable(Writable src, Writable target) throws IOException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); ObjectOutputStream oos = new ObjectOutputStream(baos); try { src.write(oos); } finally { oos.close(); } byte[] bytes = baos.toByteArray(); ByteArrayInputStream bais = new ByteArrayInputStream(bytes); ObjectInputStream ois = new ObjectInputStream(bais); try { target.readFields(ois); } finally { ois.close(); } }
From source file:com.hazelcast.jet.hadoop.impl.WritableSerializerHook.java
License:Open Source License
@Override public Serializer createSerializer() { return new StreamSerializer<Writable>() { @Override/*from ww w.j a va 2 s . co m*/ public int getTypeId() { return typeId; } @Override public void destroy() { } @Override public void write(ObjectDataOutput out, Writable writable) throws IOException { writable.write(out); } @Override public Writable read(ObjectDataInput in) throws IOException { T writable = constructor.get(); writable.readFields(in); return writable; } }; }
From source file:com.hortonworks.hbase.replication.bridge.HBaseServer.java
License:Apache License
/** * Setup response for the IPC Call.//from w ww.j a v a 2s. c o m * * @param response buffer to serialize the response into * @param call {@link Call} to which we are setting up the response * @param status {@link Status} of the IPC call * @param rv return value for the IPC Call, if the call was successful * @param errorClass error class, if the the call failed * @param error error message, if the call failed * @throws IOException */ private void setupResponse(ByteArrayOutputStream response, Call call, Status status, Writable rv, String errorClass, String error) throws IOException { response.reset(); DataOutputStream out = new DataOutputStream(response); if (status == Status.SUCCESS) { try { rv.write(out); call.setResponse(rv, status, null, null); } catch (Throwable t) { LOG.warn("Error serializing call response for call " + call, t); // Call back to same function - this is OK since the // buffer is reset at the top, and since status is changed // to ERROR it won't infinite loop. call.setResponse(null, status.ERROR, t.getClass().getName(), StringUtils.stringifyException(t)); } } else { call.setResponse(rv, status, errorClass, error); } }
From source file:com.ibm.jaql.io.serialization.binary.def.JsonJavaObjectSerializer.java
License:Apache License
@Override public void write(DataOutput out, JsonJavaObject value) throws IOException { Writable o = value.getInternalValue(); out.writeUTF(o.getClass().getName()); o.write(out); }
From source file:com.jfolson.hive.serde.RTypedBytesWritableOutput.java
License:Apache License
public void writeWritable(Writable w) throws IOException { DataOutputStream dos = null;/*from w ww . jav a 2 s. c o m*/ try { ByteArrayOutputStream baos = new ByteArrayOutputStream(); dos = new DataOutputStream(baos); WritableUtils.writeString(dos, w.getClass().getName()); w.write(dos); out.writeBytes(baos.toByteArray(), RType.WRITABLE.code); dos.close(); dos = null; } finally { IOUtils.closeStream(dos); } }
From source file:com.kylinolap.common.util.BytesUtil.java
License:Apache License
public static byte[] toBytes(Writable writable) { try {//from w w w .ja v a 2 s. c o m ByteArrayOutputStream bout = new ByteArrayOutputStream(); DataOutputStream out = new DataOutputStream(bout); writable.write(out); out.close(); bout.close(); return bout.toByteArray(); } catch (IOException e) { throw new RuntimeException(e); } }
From source file:com.linkedin.cubert.io.rubix.RubixFileKeyData.java
License:Open Source License
@Override public void write(DataOutput out) throws IOException { if (!(key instanceof Writable)) throw new RuntimeException("Key Class is not Writable"); Writable keyWritable = (Writable) key; keyWritable.write(out); out.writeLong(blockId);//w ww. j av a 2s. c o m out.writeLong(offset); out.writeLong(numRecords); }
From source file:com.mongodb.hadoop.io.BSONWritable.java
License:Apache License
/** * Used by child copy constructors.//from w w w. j a v a 2s . c o m */ protected synchronized void copy(final Writable other) { if (other != null) { try { DataOutputBuffer out = new DataOutputBuffer(); other.write(out); DataInputBuffer in = new DataInputBuffer(); in.reset(out.getData(), out.getLength()); readFields(in); } catch (IOException e) { throw new IllegalArgumentException("map cannot be copied: " + e.getMessage()); } } else { throw new IllegalArgumentException("source map cannot be null"); } }
From source file:com.moz.fiji.hive.utils.ByteWritable.java
License:Apache License
public static byte[] serialize(Writable writable) throws IOException { ByteArrayOutputStream out = new ByteArrayOutputStream(); DataOutputStream dataOut = null; try {/*w w w . jav a 2 s . c o m*/ dataOut = new DataOutputStream(out); writable.write(dataOut); return out.toByteArray(); } finally { IOUtils.closeQuietly(dataOut); } }
From source file:com.sequoiadb.hadoop.io.BSONWritable.java
License:Apache License
protected synchronized void copy(Writable other) { if (other != null) { try {/*from w w w .j av a 2s .c om*/ DataOutputBuffer out = new DataOutputBuffer(); other.write(out); DataInputBuffer in = new DataInputBuffer(); in.reset(out.getData(), out.getLength()); readFields(in); } catch (IOException e) { throw new IllegalArgumentException("map cannot be copied: " + e.getMessage()); } } else { throw new IllegalArgumentException("source map cannot be null"); } }