use of java.io.ObjectOutput in project gate-core by GateNLP.
the class LuceneDocument method writeOnDisk.
/**
* This method, given a tokenstream and file name, writes the tokenstream on
* the provided location.
*/
private void writeOnDisk(List<Token> tokenStream, String folderName, String fileName, String location) throws Exception {
// before we write it on a disk, we need to change its name to
// underlying file system name
fileName = getCompatibleName(fileName);
folderName = getCompatibleName(folderName);
if (location.startsWith("file:/"))
location = location.substring(6, location.length());
if (location.charAt(1) != ':')
location = "/" + location;
File locationFile = new File(location);
File folder = new File(locationFile, Constants.SERIALIZED_FOLDER_NAME);
if (!folder.exists()) {
if (!folder.mkdirs()) {
throw new IOException("Directory could not be created :" + folder.getAbsolutePath());
}
}
folder = new File(folder, folderName);
if (!folder.exists()) {
if (!folder.mkdirs()) {
throw new IOException("Directory could not be created :" + folder.getAbsolutePath());
}
}
File outputFile = new File(folder, fileName + ".annic");
try (OutputStream file = new FileOutputStream(outputFile);
OutputStream buffer = new BufferedOutputStream(file);
ObjectOutput output = new ObjectOutputStream(buffer)) {
output.writeObject(tokenStream);
output.flush();
}
}
use of java.io.ObjectOutput in project candlepin by candlepin.
the class EntitleByProductsJobTest method serialize.
private void serialize(Object obj) throws IOException {
ObjectOutput out = new ObjectOutputStream(new FileOutputStream("obj.ser"));
out.writeObject(obj);
out.close();
}
use of java.io.ObjectOutput in project directory-ldap-api by apache.
the class AttributeSerializationTest method testEntryAttributeNoStringValueSerialization.
@Test
public void testEntryAttributeNoStringValueSerialization() throws IOException, ClassNotFoundException {
Attribute attribute1 = new DefaultAttribute("CN");
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ObjectOutput out = new ObjectOutputStream(baos);
attribute1.writeExternal(out);
ObjectInputStream in = null;
byte[] data = baos.toByteArray();
in = new ObjectInputStream(new ByteArrayInputStream(data));
Attribute attribute2 = new DefaultAttribute();
attribute2.readExternal(in);
assertEquals(attribute1, attribute2);
}
use of java.io.ObjectOutput in project SimpleServerClient by DeBukkIt.
the class Crypter method encrypt.
/**
* Encrypts an Object and returns its encrypted equivalent CryptedObject
*
* @param o
* The object to encrypt
* @param password
* The password to use for encryption
* @return The CryptedObject equivalent of the given object
*/
public static CryptedObject encrypt(Object o, String password) {
try {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
ObjectOutput out = new ObjectOutputStream(bos);
out.writeObject(o);
return new CryptedObject(encrypt(bos.toByteArray(), password));
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
use of java.io.ObjectOutput in project azure-tools-for-java by Microsoft.
the class ApplicationInsightsPreferences method savePreferences.
/**
* Stores application insights resources list
* in preference file in the form of byte array.
*/
private void savePreferences() {
try {
Preferences prefs = PluginUtil.getPrefs(PREF_FILE);
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
ObjectOutput output = new ObjectOutputStream(buffer);
List<ApplicationInsightsResource> data = ApplicationInsightsResourceRegistry.getAppInsightsResrcList();
ApplicationInsightsResource[] dataArray = data.stream().filter(a -> !a.isImported()).sorted().toArray(ApplicationInsightsResource[]::new);
/*
* Sort list according to application insights resource name.
* Save only manually added resources
*/
try {
output.writeObject(dataArray);
} finally {
output.close();
}
prefs.putByteArray(PREF_KEY, buffer.toByteArray());
prefs.flush();
} catch (BackingStoreException e) {
Activator.getDefault().log(e.getMessage(), e);
} catch (IOException e) {
Activator.getDefault().log(e.getMessage(), e);
}
}
Aggregations