@Override public Void call() throws Exception { SerializationUtils.deserializeState(ParallelRunner.this.fs, inputFilePath, state); return null; } }), "Deserialize state from " + inputFilePath));
@Override public Void call() throws Exception { SerializationUtils.serializeState(ParallelRunner.this.fs, outputFilePath, state); return null; } }), "Serialize state to " + outputFilePath));
private T deserializeMetadata(byte[] bytes) throws IOException, ClassNotFoundException { return (T) SerializationUtils.deserializeFromBytes(bytes, Metadata.class); }
private byte[] serializeMetadata(T metadata) throws IOException { return SerializationUtils.serializeIntoBytes(metadata); }
/** * Deserialize/read a {@link State} instance from a file. * * @param fs the {@link FileSystem} instance for opening the file * @param jobStateFilePath the path to the file * @param state an empty {@link State} instance to deserialize into * @param <T> the {@link State} object type * @throws IOException if it fails to deserialize the {@link State} instance */ public static <T extends State> void deserializeState(FileSystem fs, Path jobStateFilePath, T state) throws IOException { try (InputStream is = fs.open(jobStateFilePath)) { deserializeStateFromInputStream(is, state); } }
/** * Serialize an object into a String. The object is first serialized into a byte array, * which is converted into a String using {@link BaseEncoding#base64()}. * * @param obj A {@link Serializable} object * @return A String representing the input object * @throws IOException if it fails to serialize the object */ public static <T extends Serializable> String serialize(T obj) throws IOException { return serialize(obj, DEFAULT_ENCODING); }
/** * Deserialize a String obtained via {@link #serialize(Serializable)} into an object, using * {@link BaseEncoding#base64()}. * * @param serialized The serialized String * @param clazz The class the deserialized object should be cast to. * @return The deserialized object * @throws IOException if it fails to deserialize the object */ public static <T extends Serializable> T deserialize(String serialized, Class<T> clazz) throws IOException { return deserialize(serialized, clazz, DEFAULT_ENCODING); }
/** * Serialize an object into a String. The object is first serialized into a byte array, * which is converted into a String using the given {@link BaseEncoding}. * * @param obj A {@link Serializable} object * @param enc The {@link BaseEncoding} used to encode a byte array. * @return A String representing the input object * @throws IOException if it fails to serialize the object */ public static <T extends Serializable> String serialize(T obj, BaseEncoding enc) throws IOException { return enc.encode(serializeIntoBytes(obj)); }
for (Path dcPath : DistributedCache.getLocalCacheFiles(context.getConfiguration())) { if (dcPath.getName().equals(jobStateFileName)) { SerializationUtils.deserializeStateFromInputStream( closer.register(new FileInputStream(dcPath.toUri().getPath())), this.jobState); foundStateFile = true;
/** * Serialize an object into a String. The object is first serialized into a byte array, * which is converted into a String using {@link BaseEncoding#base64()}. * * @param obj A {@link Serializable} object * @return A String representing the input object * @throws IOException if it fails to serialize the object */ public static <T extends Serializable> String serialize(T obj) throws IOException { return serialize(obj, DEFAULT_ENCODING); }
/** * Deserialize a String obtained via {@link #serialize(Serializable)} into an object, using * {@link BaseEncoding#base64()}. * * @param serialized The serialized String * @param clazz The class the deserialized object should be cast to. * @return The deserialized object * @throws IOException if it fails to deserialize the object */ public static <T extends Serializable> T deserialize(String serialized, Class<T> clazz) throws IOException { return deserialize(serialized, clazz, DEFAULT_ENCODING); }
@Override public void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException { WorkUnit workUnit = (value.toString().endsWith(MULTI_WORK_UNIT_FILE_EXTENSION) ? MultiWorkUnit.createEmpty() : WorkUnit.createEmpty()); SerializationUtils.deserializeState(this.fs, new Path(value.toString()), workUnit); if (workUnit instanceof MultiWorkUnit) { List<WorkUnit> flattenedWorkUnits = JobLauncherUtils.flattenWorkUnits(((MultiWorkUnit) workUnit).getWorkUnits()); this.workUnits.addAll(flattenedWorkUnits); } else { this.workUnits.add(workUnit); } } }
/** * Serialize a {@link State} instance to a file. * * @param fs the {@link FileSystem} instance for creating the file * @param jobStateFilePath the path to the file * @param state the {@link State} to serialize * @param <T> the {@link State} object type * @throws IOException if it fails to serialize the {@link State} instance */ public static <T extends State> void serializeState(FileSystem fs, Path jobStateFilePath, T state) throws IOException { serializeState(fs, jobStateFilePath, state, fs.getDefaultReplication(jobStateFilePath)); }
private byte[] serializeMetadata(T metadata) throws IOException { return SerializationUtils.serializeIntoBytes(metadata); }
/** * Deserialize a String obtained via {@link #serialize(Serializable)} into an object, using the * given {@link BaseEncoding}, which must be the same {@link BaseEncoding} used to serialize the object. * * @param serialized The serialized String * @param clazz The class the deserialized object should be cast to. * @param enc The {@link BaseEncoding} used to decode the String. * @return The deserialized object * @throws IOException if it fails to deserialize the object */ public static <T extends Serializable> T deserialize(String serialized, Class<T> clazz, BaseEncoding enc) throws IOException { return deserializeFromBytes(enc.decode(serialized), clazz); }
/** * Deserialize/read a {@link State} instance from a file. * * @param fs the {@link FileSystem} instance for opening the file * @param jobStateFilePath the path to the file * @param state an empty {@link State} instance to deserialize into * @param <T> the {@link State} object type * @throws IOException if it fails to deserialize the {@link State} instance */ public static <T extends State> void deserializeState(FileSystem fs, Path jobStateFilePath, T state) throws IOException { try (InputStream is = fs.open(jobStateFilePath)) { deserializeStateFromInputStream(is, state); } }
private JobState getJobState() throws java.io.IOException { JobState jobState; // read the state from the state store if present, otherwise deserialize directly from the file if (_stateStores.haveJobStateStore()) { jobState = _stateStores.getJobStateStore().get(_jobStateFilePath.getParent().getName(), _jobStateFilePath.getName(), _jobStateFilePath.getParent().getName()); } else { jobState = new JobState(); SerializationUtils.deserializeState(_fs, _jobStateFilePath, jobState); } return jobState; }
@Test public void testSerializeState() throws IOException { WorkUnit workUnit1 = WorkUnit.createEmpty(); workUnit1.setProp("foo", "bar"); workUnit1.setProp("a", 10); SerializationUtils.serializeState(this.fs, new Path(this.outputPath, "wu1"), workUnit1); WorkUnit workUnit2 = WorkUnit.createEmpty(); workUnit2.setProp("foo", "baz"); workUnit2.setProp("b", 20); SerializationUtils.serializeState(this.fs, new Path(this.outputPath, "wu2"), workUnit2); }
/** * Serialize an object into a String. The object is first serialized into a byte array, * which is converted into a String using the given {@link BaseEncoding}. * * @param obj A {@link Serializable} object * @param enc The {@link BaseEncoding} used to encode a byte array. * @return A String representing the input object * @throws IOException if it fails to serialize the object */ public static <T extends Serializable> String serialize(T obj, BaseEncoding enc) throws IOException { return enc.encode(serializeIntoBytes(obj)); }
private T deserializeMetadata(byte[] bytes) throws IOException, ClassNotFoundException { return (T) SerializationUtils.deserializeFromBytes(bytes, Metadata.class); }