Search in sources :

Example 1 with ObjectInput

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
        }
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ObjectInput(java.io.ObjectInput) IOException(java.io.IOException) ObjectInputStream(java.io.ObjectInputStream)

Example 2 with ObjectInput

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);
    }
}
Also used : VersionedObjectInput(org.apache.geode.internal.VersionedObjectInput) Version(org.apache.geode.internal.Version) InternalGemFireException(org.apache.geode.InternalGemFireException) VersionedObjectInput(org.apache.geode.internal.VersionedObjectInput) ObjectInput(java.io.ObjectInput) FileInputStream(java.io.FileInputStream) InternalGemFireException(org.apache.geode.InternalGemFireException) IOException(java.io.IOException) ObjectInputStream(java.io.ObjectInputStream)

Example 3 with ObjectInput

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

Example 4 with ObjectInput

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);
    }
}
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 5 with ObjectInput

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;
}
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) File(java.io.File) FileInputStream(java.io.FileInputStream) ObjectInputStream(java.io.ObjectInputStream)

Aggregations

ObjectInput (java.io.ObjectInput)26 ObjectInputStream (java.io.ObjectInputStream)18 IOException (java.io.IOException)15 ByteArrayInputStream (java.io.ByteArrayInputStream)13 ObjectOutput (java.io.ObjectOutput)10 InputStream (java.io.InputStream)7 ObjectOutputStream (java.io.ObjectOutputStream)7 ByteArrayOutputStream (java.io.ByteArrayOutputStream)6 FileInputStream (java.io.FileInputStream)6 BufferedInputStream (java.io.BufferedInputStream)5 RemoteException (java.rmi.RemoteException)4 MotanFrameworkException (com.weibo.api.motan.exception.MotanFrameworkException)3 File (java.io.File)3 MarshalException (java.rmi.MarshalException)3 UnmarshalException (java.rmi.UnmarshalException)3 Test (org.junit.Test)3 DefaultRequest (com.weibo.api.motan.rpc.DefaultRequest)2 DefaultResponse (com.weibo.api.motan.rpc.DefaultResponse)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 ServerError (java.rmi.ServerError)2