Search in sources :

Example 41 with ObjectOutput

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();
    }
}
Also used : ObjectOutput(java.io.ObjectOutput) BufferedOutputStream(java.io.BufferedOutputStream) ObjectOutputStream(java.io.ObjectOutputStream) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) ObjectOutputStream(java.io.ObjectOutputStream) File(java.io.File) BufferedOutputStream(java.io.BufferedOutputStream)

Example 42 with ObjectOutput

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();
}
Also used : ObjectOutput(java.io.ObjectOutput) FileOutputStream(java.io.FileOutputStream) ObjectOutputStream(java.io.ObjectOutputStream)

Example 43 with ObjectOutput

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);
}
Also used : ObjectOutput(java.io.ObjectOutput) DefaultAttribute(org.apache.directory.api.ldap.model.entry.DefaultAttribute) Attribute(org.apache.directory.api.ldap.model.entry.Attribute) ByteArrayInputStream(java.io.ByteArrayInputStream) DefaultAttribute(org.apache.directory.api.ldap.model.entry.DefaultAttribute) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ObjectOutputStream(java.io.ObjectOutputStream) ObjectInputStream(java.io.ObjectInputStream) Test(org.junit.Test)

Example 44 with ObjectOutput

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;
    }
}
Also used : ObjectOutput(java.io.ObjectOutput) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ObjectOutputStream(java.io.ObjectOutputStream)

Example 45 with ObjectOutput

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);
    }
}
Also used : ApplicationInsightsResource(com.microsoft.applicationinsights.preference.ApplicationInsightsResource) ObjectOutput(java.io.ObjectOutput) BackingStoreException(org.osgi.service.prefs.BackingStoreException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) Preferences(org.osgi.service.prefs.Preferences) ObjectOutputStream(java.io.ObjectOutputStream)

Aggregations

ObjectOutput (java.io.ObjectOutput)105 ObjectOutputStream (java.io.ObjectOutputStream)78 ByteArrayOutputStream (java.io.ByteArrayOutputStream)64 IOException (java.io.IOException)53 ObjectInput (java.io.ObjectInput)26 Test (org.junit.Test)24 ObjectInputStream (java.io.ObjectInputStream)20 ByteArrayInputStream (java.io.ByteArrayInputStream)19 WorkingMemory (org.drools.core.WorkingMemory)13 FileOutputStream (java.io.FileOutputStream)12 RuleImpl (org.drools.core.definitions.rule.impl.RuleImpl)12 Pattern (org.drools.core.rule.Pattern)12 Consequence (org.drools.core.spi.Consequence)12 KnowledgeHelper (org.drools.core.spi.KnowledgeHelper)12 OutputStream (java.io.OutputStream)11 InternalWorkingMemory (org.drools.core.common.InternalWorkingMemory)8 Declaration (org.drools.core.rule.Declaration)8 IntrospectionException (java.beans.IntrospectionException)7 File (java.io.File)7 InvalidRuleException (org.drools.core.rule.InvalidRuleException)7