Search in sources :

Example 31 with ObjectInput

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

Example 32 with ObjectInput

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());
}
Also used : ObjectInputStream(java.io.ObjectInputStream) ByteBufferInputStream(org.apache.avro.util.ByteBufferInputStream) InputStream(java.io.InputStream) ObjectInput(java.io.ObjectInput) IOException(java.io.IOException) ObjectInputStream(java.io.ObjectInputStream)

Example 33 with ObjectInput

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);
    }
}
Also used : BufferedInputStream(java.io.BufferedInputStream) BufferedInputStream(java.io.BufferedInputStream) ObjectInputStream(java.io.ObjectInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) ObjectInput(java.io.ObjectInput) FileInputStream(java.io.FileInputStream) ObjectInputStream(java.io.ObjectInputStream)

Example 34 with ObjectInput

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;
}
Also used : BufferedInputStream(java.io.BufferedInputStream) BufferedInputStream(java.io.BufferedInputStream) ObjectInputStream(java.io.ObjectInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) ObjectInput(java.io.ObjectInput) IOException(java.io.IOException) File(java.io.File) FileInputStream(java.io.FileInputStream) ObjectInputStream(java.io.ObjectInputStream)

Example 35 with ObjectInput

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);
}
Also used : Path(org.apache.hadoop.fs.Path) ObjectOutput(java.io.ObjectOutput) ByteArrayOutputStream(java.io.ByteArrayOutputStream) FileSplit(org.apache.hadoop.mapreduce.lib.input.FileSplit) ObjectOutputStream(java.io.ObjectOutputStream) HadoopSplitWrapper(org.apache.ignite.internal.processors.hadoop.HadoopSplitWrapper) ByteArrayInputStream(java.io.ByteArrayInputStream) ObjectInput(java.io.ObjectInput) ObjectInputStream(java.io.ObjectInputStream)

Aggregations

ObjectInput (java.io.ObjectInput)45 IOException (java.io.IOException)31 ObjectOutput (java.io.ObjectOutput)25 ObjectInputStream (java.io.ObjectInputStream)20 ByteArrayInputStream (java.io.ByteArrayInputStream)16 WorkingMemory (org.drools.core.WorkingMemory)13 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 Test (org.junit.Test)9 ObjectOutputStream (java.io.ObjectOutputStream)8 InternalWorkingMemory (org.drools.core.common.InternalWorkingMemory)8 Declaration (org.drools.core.rule.Declaration)8 IntrospectionException (java.beans.IntrospectionException)7 ByteArrayOutputStream (java.io.ByteArrayOutputStream)7 InputStream (java.io.InputStream)7 InvalidRuleException (org.drools.core.rule.InvalidRuleException)7 ConsequenceException (org.drools.core.spi.ConsequenceException)7 FileInputStream (java.io.FileInputStream)6