use of java.io.ObjectInput in project azure-tools-for-java by Microsoft.
the class ApplicationInsightsPreferences method loadPreferences.
/**
* Read and load preference file data.
* Converts byte array format data to list of application insights resources.
*/
private void loadPreferences() {
Preferences prefs = PluginUtil.getPrefs(PREF_FILE);
try {
byte[] data = prefs.getByteArray(PREF_KEY, null);
if (data != null) {
ByteArrayInputStream buffer = new ByteArrayInputStream(data);
ObjectInput input = new ObjectInputStream(buffer);
try {
ApplicationInsightsResource[] resources = (ApplicationInsightsResource[]) input.readObject();
for (ApplicationInsightsResource resource : resources) {
if (!ApplicationInsightsResourceRegistry.getAppInsightsResrcList().contains(resource)) {
ApplicationInsightsResourceRegistry.getAppInsightsResrcList().add(resource);
}
}
} finally {
input.close();
}
}
} catch (IOException e) {
Activator.getDefault().log(e.getMessage(), e);
} catch (ClassNotFoundException e) {
Activator.getDefault().log(e.getMessage(), e);
}
}
use of java.io.ObjectInput in project gora by apache.
the class IOUtils method readObject.
public static Object readObject(DataInput in) throws ClassNotFoundException, IOException {
if (in instanceof ObjectInput) {
return ((ObjectInput) in).readObject();
} else {
if (in instanceof InputStream) {
ObjectInput objIn = new ObjectInputStream((InputStream) in);
Object obj = objIn.readObject();
return obj;
}
}
throw new IOException("cannot read from DataInput of instance:" + in.getClass());
}
use of java.io.ObjectInput in project jackrabbit by apache.
the class AsyncUploadCache method deserializeToBeDeleted.
/**
* Deserialize {@link #toBeDeleted} from local file system.
*/
private synchronized void deserializeToBeDeleted() throws IOException, ClassNotFoundException {
// use buffering
InputStream fis = new FileInputStream(toBeDeletedUploads);
InputStream buffer = new BufferedInputStream(fis);
ObjectInput input = new ObjectInputStream(buffer);
try {
toBeDeleted = (Set<String>) input.readObject();
} finally {
input.close();
IOUtils.closeQuietly(buffer);
}
}
use of java.io.ObjectInput in project ddf by codice.
the class FileSystemPersistenceProvider method loadFromPersistence.
Object loadFromPersistence(String key) {
File file = getMapStoreFile(key);
if (!file.exists()) {
return null;
}
InputStream inputStream = null;
try {
inputStream = new FileInputStream(getMapStorePath() + key + SER);
InputStream buffer = new BufferedInputStream(inputStream);
try (ObjectInput input = new ObjectInputStream(buffer)) {
return input.readObject();
}
} catch (IOException e) {
LOGGER.info("Unable to read object.", e);
} catch (ClassNotFoundException e) {
LOGGER.info("Class for object being read from stream does not exist.", e);
} finally {
IOUtils.closeQuietly(inputStream);
}
return null;
}
use of java.io.ObjectInput in project ignite by apache.
the class HadoopSplitWrapperSelfTest method testSerialization.
/**
* Tests serialization of wrapper and the wrapped native split.
* @throws Exception If fails.
*/
public void testSerialization() throws Exception {
FileSplit nativeSplit = new FileSplit(new Path("/path/to/file"), 100, 500, new String[] { "host1", "host2" });
assertEquals("/path/to/file:100+500", nativeSplit.toString());
HadoopSplitWrapper split = HadoopUtils.wrapSplit(10, nativeSplit, nativeSplit.getLocations());
assertEquals("[host1, host2]", Arrays.toString(split.hosts()));
ByteArrayOutputStream buf = new ByteArrayOutputStream();
ObjectOutput out = new ObjectOutputStream(buf);
out.writeObject(split);
ObjectInput in = new ObjectInputStream(new ByteArrayInputStream(buf.toByteArray()));
final HadoopSplitWrapper res = (HadoopSplitWrapper) in.readObject();
assertEquals("/path/to/file:100+500", HadoopUtils.unwrapSplit(res).toString());
GridTestUtils.assertThrows(log, new Callable<Object>() {
@Override
public Object call() throws Exception {
res.hosts();
return null;
}
}, AssertionError.class, null);
}
Aggregations