/** * Serializes the field object using the datumWriter. * * @param <T> class type of object to be serialized. * @param datumWriter AVRO datum writer for given schema. * @param object object to be serialized. * @return serialized byte array. * @throws IOException occurred while serializing the object to bytes. */ public static<T extends SpecificRecord> byte[] serialize(SpecificDatumWriter<T> datumWriter , T object) throws IOException { ByteArrayOutputStream os = new ByteArrayOutputStream(); serialize(os, datumWriter, object); return os.toByteArray(); }
/** * Serializes the field object using the datumWriter. * * @param <T> class type of object to be serialized. * @param datumWriter AVRO datum writer for given schema. * @param object object to be serialized. * @return serialized byte array. * @throws IOException occurred while serializing the object to bytes. */ public static<T> byte[] serialize(SpecificDatumWriter<T> datumWriter , T object) throws IOException { ByteArrayOutputStream os = new ByteArrayOutputStream(); serialize(os, datumWriter, object); return os.toByteArray(); }
/** * Serializes the field object using the datumWriter. * * @param <T> class type of object to be serialized. * @param datumWriter AVRO datum writer for given schema. * @param object object to be serialized. * @return serialized byte array. * @throws IOException occurred while serializing the object to bytes. */ public static<T> byte[] serialize(SpecificDatumWriter<T> datumWriter , T object) throws IOException { ByteArrayOutputStream os = new ByteArrayOutputStream(); serialize(os, datumWriter, object); return os.toByteArray(); }
/** * Serializes the field object using the datumWriter. * * @param <T> class type of object to be serialized. * @param datumWriter AVRO datum writer for given schema. * @param object object to be serialized. * @return serialized byte array. * @throws IOException occurred while serializing the object to bytes. */ public static<T extends SpecificRecord> byte[] serialize(SpecificDatumWriter<T> datumWriter , T object) throws IOException { ByteArrayOutputStream os = new ByteArrayOutputStream(); serialize(os, datumWriter, object); return os.toByteArray(); }
@Override public void write(DataOutput out) throws IOException { IOUtils.serialize(getConf(), out, query); }
@Override public void write(DataOutput out) throws IOException { IOUtils.serialize(getConf(), out, query); }
/** * Serializes the object to the given data output using * available Hadoop serializations. * * @param <T> class type of object to be serialized. * @param conf Hadoop conf. * @param obj object instance to be serialized. * @param out data stream which serialized content is written. * @throws IOException occurred while serializing the object to bytes. */ @SuppressWarnings("unchecked") public static<T> void serialize(Configuration conf, DataOutput out , T obj) throws IOException { Text.writeString(out, obj.getClass().getName()); serialize(conf, out, obj, (Class<T>)obj.getClass()); }
/** * Serializes the object to the given data output using * available Hadoop serializations. * * @param <T> class type of object to be serialized. * @param conf Hadoop conf. * @param obj object instance to be serialized. * @param out data stream which serialized content is written. * @throws IOException occurred while serializing the object to bytes. */ @SuppressWarnings("unchecked") public static<T> void serialize(Configuration conf, DataOutput out , T obj) throws IOException { Text.writeString(out, obj.getClass().getName()); serialize(conf, out, obj, (Class<T>)obj.getClass()); }
/** * Serializes the object to the given data output using * available Hadoop serializations * * @param conf Hadoop conf. * @param <T> class type of object to be serialized. * @param obj object instance to be serialized. * @return serialized byte array. * @throws IOException occurred while serializing the object to bytes. */ public static<T> byte[] serialize(Configuration conf, T obj) throws IOException { DataOutputBuffer buffer = new DataOutputBuffer(); serialize(conf, buffer, obj); return buffer.getData(); }
/** * Serializes the object to the given data output using * available Hadoop serializations * * @param conf Hadoop conf. * @param <T> class type of object to be serialized. * @param obj object instance to be serialized. * @return serialized byte array. * @throws IOException occurred while serializing the object to bytes. */ public static<T> byte[] serialize(Configuration conf, T obj) throws IOException { DataOutputBuffer buffer = new DataOutputBuffer(); serialize(conf, buffer, obj); return buffer.getData(); }
@Override public void write(DataOutput out) throws IOException { super.write(out); IOUtils.serialize(getConf(), out, baseQuery); IOUtils.writeStringArray(out, locations); }
@SuppressWarnings("rawtypes") SpecificDatumWriter writer = getDatumWriter(fieldSchema); data = IOUtils.serialize(writer, fieldValue); } catch (IOException e) { LOG.error(e.getMessage(), e); @SuppressWarnings("rawtypes") SpecificDatumWriter writer = getDatumWriter(fieldSchema); serilazeData = IOUtils.serialize(writer, fieldValue); } catch (IOException e) { LOG.error(e.getMessage(), e);
@Override public void write(DataOutput out) throws IOException { super.write(out); IOUtils.serialize(getConf(), out, baseQuery); IOUtils.writeStringArray(out, locations); }
/** * Utility method for deep clone a given AVRO persistent bean instance. * * @param persistent source persistent bean instance. * @param <T> persistent bean type. * @return cloned persistent bean to be returned. */ public static <T extends PersistentBase> T deepClonePersistent(T persistent) { final SpecificDatumWriter<PersistentBase> writer = new SpecificDatumWriter<>(persistent.getSchema()); final byte[] byteData; try { byteData = IOUtils.serialize(writer, persistent); } catch (IOException e) { throw new RuntimeException( "Unable to serialize avro object to byte buffer - " + "please report this issue to the Gora bugtracker " + "or your administrator."); } @SuppressWarnings("unchecked") final SpecificDatumReader<T> reader = new SpecificDatumReader<>((Class<T>) persistent.getClass()); try { return IOUtils.deserialize(byteData, reader, null); } catch (IOException e) { throw new RuntimeException( "Unable to deserialize avro object from byte buffer - " + "please report this issue to the Gora bugtracker " + "or your administrator."); } }
/** * Utility method for deep clone a given AVRO persistent bean instance. * * @param persistent source persistent bean instance. * @param <T> persistent bean type. * @return cloned persistent bean to be returned. */ public static <T extends PersistentBase> T deepClonePersistent(T persistent) { final SpecificDatumWriter<PersistentBase> writer = new SpecificDatumWriter<>(persistent.getSchema()); final byte[] byteData; try { byteData = IOUtils.serialize(writer, persistent); } catch (IOException e) { throw new RuntimeException( "Unable to serialize avro object to byte buffer - " + "please report this issue to the Gora bugtracker " + "or your administrator."); } @SuppressWarnings("unchecked") final SpecificDatumReader<T> reader = new SpecificDatumReader<>((Class<T>) persistent.getClass()); try { return IOUtils.deserialize(byteData, reader, null); } catch (IOException e) { throw new RuntimeException( "Unable to deserialize avro object from byte buffer - " + "please report this issue to the Gora bugtracker " + "or your administrator."); } }
@SuppressWarnings("unchecked") public static <T> byte[] toBytes(T o, Schema schema , SpecificDatumWriter<T> datumWriter) throws IOException { Type type = schema.getType(); switch (type) { case STRING: return toBytes(((Utf8)o).toString()); // TODO: maybe ((Utf8)o).getBytes(); ? case BYTES: return ((ByteBuffer)o).array(); case INT: return vintToBytes((Integer)o); case LONG: return vintToBytes((Long)o); case FLOAT: return toBytes((Float)o); case DOUBLE: return toBytes((Double)o); case BOOLEAN: return (Boolean)o ? new byte[] {1} : new byte[] {0}; case ENUM: return new byte[] { (byte)((Enum<?>) o).ordinal() }; case RECORD: //fall case MAP: case ARRAY: return IOUtils.serialize((SpecificDatumWriter<SpecificRecord>)datumWriter, (SpecificRecord)o); default: throw new RuntimeException("Unknown type: "+type); } } }
@SuppressWarnings("unchecked") public static <T> byte[] toBytes(T o, Schema schema , SpecificDatumWriter<T> datumWriter) throws IOException { Type type = schema.getType(); switch (type) { case STRING: return toBytes(((Utf8)o).toString()); // TODO: maybe ((Utf8)o).getBytes(); ? case BYTES: return ((ByteBuffer)o).array(); case INT: return vintToBytes((Integer)o); case LONG: return vintToBytes((Long)o); case FLOAT: return toBytes((Float)o); case DOUBLE: return toBytes((Double)o); case BOOLEAN: return (Boolean)o ? new byte[] {1} : new byte[] {0}; case ENUM: return new byte[] { (byte)((Enum<?>) o).ordinal() }; case RECORD: //fall case MAP: case ARRAY: return IOUtils.serialize((SpecificDatumWriter<SpecificRecord>)datumWriter, (SpecificRecord)o); default: throw new RuntimeException("Unknown type: "+type); } } }
public void write(DataOutput out) throws IOException { //write datastore Text.writeString(out, dataStore.getClass().getCanonicalName()); dataStore.write(out); IOUtils.writeNullFieldsInfo(out, queryString, (fields) , startKey, endKey, filter); if(queryString != null) Text.writeString(out, queryString); if(fields != null) IOUtils.writeStringArray(out, fields); if(startKey != null) IOUtils.serialize(getConf(), out, startKey, dataStore.getKeyClass()); if(endKey != null) IOUtils.serialize(getConf(), out, endKey, dataStore.getKeyClass()); if(filter != null) { Text.writeString(out, filter.getClass().getCanonicalName()); filter.write(out); } WritableUtils.writeVLong(out, getStartTime()); WritableUtils.writeVLong(out, getEndTime()); WritableUtils.writeVLong(out, getLimit()); out.writeBoolean(localFilterEnabled); }
public void write(DataOutput out) throws IOException { //write datastore Text.writeString(out, dataStore.getClass().getCanonicalName()); dataStore.write(out); IOUtils.writeNullFieldsInfo(out, queryString, (fields) , startKey, endKey, filter); if(queryString != null) Text.writeString(out, queryString); if(fields != null) IOUtils.writeStringArray(out, fields); if(startKey != null) IOUtils.serialize(getConf(), out, startKey, dataStore.getKeyClass()); if(endKey != null) IOUtils.serialize(getConf(), out, endKey, dataStore.getKeyClass()); if(filter != null) { Text.writeString(out, filter.getClass().getCanonicalName()); filter.write(out); } WritableUtils.writeVLong(out, getStartTime()); WritableUtils.writeVLong(out, getEndTime()); WritableUtils.writeVLong(out, getLimit()); out.writeBoolean(localFilterEnabled); }
IOUtils.serialize(conf, dos , before, (Class<T>)before.getClass()); dos.flush();