use of java.io.ObjectInput in project sessdb by ppdai.
the class SampleValue method fromBytes.
public static SampleValue fromBytes(byte[] bytes) throws ClassNotFoundException, IOException {
ByteArrayInputStream bis = new ByteArrayInputStream(bytes);
ObjectInput in = null;
try {
in = new ObjectInputStream(bis);
Object o = in.readObject();
return (SampleValue) o;
} finally {
try {
bis.close();
} catch (IOException ex) {
// ignore close exception
}
try {
if (in != null) {
in.close();
}
} catch (IOException ex) {
// ignore close exception
}
}
}
use of java.io.ObjectInput in project geode by apache.
the class GMSLocator method recoverFromFile.
/* package */
boolean recoverFromFile(File file) throws InternalGemFireException {
if (!file.exists()) {
logger.info("recovery file not found: " + file.getAbsolutePath());
return false;
}
logger.info("Peer locator recovering from " + file.getAbsolutePath());
try (ObjectInput ois = new ObjectInputStream(new FileInputStream(file))) {
if (ois.readInt() != LOCATOR_FILE_STAMP) {
return false;
}
ObjectInput ois2 = ois;
int version = ois2.readInt();
if (version != Version.CURRENT_ORDINAL) {
Version geodeVersion = Version.fromOrdinalNoThrow((short) version, false);
logger.info("Peer locator found that persistent view was written with {}", geodeVersion);
ois2 = new VersionedObjectInput(ois2, geodeVersion);
}
Object o = DataSerializer.readObject(ois2);
this.view = (NetView) o;
logger.info("Peer locator initial membership is " + view);
return true;
} catch (Exception e) {
String msg = LOCATOR_UNABLE_TO_RECOVER_VIEW.toLocalizedString(file.toString());
logger.warn(msg, e);
if (!file.delete() && file.exists()) {
logger.warn("Peer locator was unable to recover from or delete " + file);
this.viewFile = null;
}
throw new InternalGemFireException(msg, e);
}
}
use of java.io.ObjectInput in project ignite by apache.
the class GridClientJdkMarshaller method unmarshal.
/** {@inheritDoc} */
@SuppressWarnings("unchecked")
@Override
public <T> T unmarshal(byte[] bytes) throws IOException {
ByteArrayInputStream tmp = new ByteArrayInputStream(bytes);
ObjectInput in = new ObjectInputStream(tmp);
try {
return (T) in.readObject();
} catch (ClassNotFoundException e) {
throw new IOException("Failed to unmarshal target object: " + e.getMessage(), e);
}
}
use of java.io.ObjectInput in project jackrabbit by apache.
the class AsyncUploadCache method deserializeAsyncUploadMap.
/**
* Deserialize {@link #asyncUploadMap} from local file system.
*/
private synchronized void deserializeAsyncUploadMap() throws IOException, ClassNotFoundException {
// use buffering
InputStream fis = new FileInputStream(pendingUploads);
InputStream buffer = new BufferedInputStream(fis);
ObjectInput input = new ObjectInputStream(buffer);
try {
asyncUploadMap = (Map<String, Long>) input.readObject();
} finally {
input.close();
IOUtils.closeQuietly(buffer);
}
}
use of java.io.ObjectInput in project jackrabbit-oak by apache.
the class DataStoreCacheUpgradeUtils method deSerializeUploadMap.
/**
* De-serialize the pending uploads map from {@link org.apache.jackrabbit.core.data.AsyncUploadCache}.
*
* @param homeDir the directory where the serialized file is maintained
* @return the de-serialized map
*/
private static Map<String, Long> deSerializeUploadMap(File homeDir) {
Map<String, Long> asyncUploadMap = Maps.newHashMap();
File asyncUploadMapFile = new File(homeDir, UPLOAD_MAP);
if (asyncUploadMapFile.exists()) {
String path = asyncUploadMapFile.getAbsolutePath();
InputStream fis = null;
try {
fis = new BufferedInputStream(new FileInputStream(path));
ObjectInput input = new ObjectInputStream(fis);
asyncUploadMap = (Map<String, Long>) input.readObject();
} catch (Exception e) {
LOG.warn("Error in reading pending uploads map [{}] from location [{}]", UPLOAD_MAP, homeDir);
} finally {
IOUtils.closeQuietly(fis);
}
LOG.debug("AsyncUploadMap read [{}]", asyncUploadMap);
}
return asyncUploadMap;
}
Aggregations