Example usage for java.io ObjectInputStream readObject

List of usage examples for java.io ObjectInputStream readObject

Introduction

In this page you can find the example usage for java.io ObjectInputStream readObject.

Prototype

public final Object readObject() throws IOException, ClassNotFoundException 

Source Link

Document

Read an object from the ObjectInputStream.

Usage

From source file:com.impetus.kundera.property.accessor.ObjectAccessor.java

@Override
public final Object fromBytes(Class targetClass, byte[] bytes) {
    try {// w  ww  .  j a  v a2  s .  c o m
        if (targetClass != null && targetClass.equals(byte[].class)) {
            return bytes;
        }
        ObjectInputStream ois;
        ois = new ObjectInputStream(new ByteArrayInputStream(bytes));
        Object o = ois.readObject();
        ois.close();
        return o;
    } catch (IOException e) {
        throw new PropertyAccessException(e);
    } catch (ClassNotFoundException e) {
        throw new PropertyAccessException(e);
    }

}

From source file:edu.uga.cs.fluxbuster.clustering.hierarchicalclustering.Dendrogram.java

/**
 * Creates a deep copy of any object./*w  ww. j ava2s. co m*/
 *
 * @param o the object to copy
 * @return the copy
 */
public Object deepCopy(Object o) {
    try {
        ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
        ObjectOutputStream out = new ObjectOutputStream(byteOut);
        out.writeObject(o);
        out.close();

        byte[] data = byteOut.toByteArray();
        ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(data));
        Object copy = in.readObject();
        in.close();

        return copy;
    } catch (Exception e) {
        if (log.isErrorEnabled()) {
            log.error("Error performing deep copy.", e);
        }
    }

    return null;
}

From source file:com.ps.cc.action.LoginAction.java

@Override
public void run(HttpServletRequest request, HttpServletResponse response) throws ActionException {
    try {/*  www.  j  av  a  2 s . c  o  m*/
        HttpSession session = request.getSession();

        long companyId = PortalUtil.getCompanyId(request);
        long userId = PortalUtil.getUserId(request);

        User user = UserLocalServiceUtil.getUserById(companyId, userId);
        TwilioConfiguration twilioConfiguration = new TwilioConfiguration();

        try {
            File file = new File("twilioConfiguration.txt");
            ObjectInputStream in = new ObjectInputStream(new FileInputStream(file));
            twilioConfiguration = (TwilioConfiguration) in.readObject();
            in.close();
        } catch (Exception ex) {
            //didn't exist...
        }

        String acctSid = twilioConfiguration.getAcctSid();
        String authToken = twilioConfiguration.getAuthToken();
        String appSid = twilioConfiguration.getAppSid();

        TwilioCapability capability = new TwilioCapability(acctSid, authToken);

        capability.allowEventStream(null);
        capability.allowClientIncoming(user.getScreenName());

        Map<String, String> params = new HashMap<String, String>();
        params.put("portraitId", String.valueOf(user.getPortraitId()));

        capability.allowClientOutgoing(appSid, params);

        String token = capability.generateToken();

        //Now we will share the json object with everyone
        session.setAttribute("USER_twilio_token", token);

        if (_log.isInfoEnabled()) {
            _log.info("Twilio Token Generated: " + token + " (" + user.getScreenName() + ")");
        }

    } catch (Exception ex) {
        _log.error("Error during post login", ex);
    }
}

From source file:org.blanco.techmun.android.cproviders.MesasFetcher.java

private Mesas tryToLoadFromCache(Context context) {
    try {//from   w w  w  . jav  a2  s .co m
        FileInputStream mesasFIS = context.openFileInput("mesas.df");
        ObjectInputStream mesasOIS = new ObjectInputStream(mesasFIS);
        Mesas result = (Mesas) mesasOIS.readObject();
        mesasOIS.close();
        return result;
    } catch (IOException e) {
        Log.e("tachmun",
                "Error opening cache file for mesas in content provider. " + "No cache will be restored", e);
        return null;
    } catch (ClassNotFoundException e) {
        Log.e("tachmun", "Error in cache file for mesas in content provider. "
                + "Something is there but is not a Mesas object. Cache no restored", e);
        return null;
    }
}

From source file:com.artofsolving.jodconverter.XmlDocumentFormatRegistry.java

private void load(InputStream inputStream) {
    if (inputStream == null) {
        throw new IllegalArgumentException("inputStream is null");
    }/* w w w . j  av a2 s  . c  om*/
    XStream xstream = createXStream();
    try {
        ObjectInputStream in = xstream.createObjectInputStream(new InputStreamReader(inputStream));
        while (true) {
            try {
                addDocumentFormat((DocumentFormat) in.readObject());
            } catch (EOFException endOfFile) {
                break;
            }
        }
    } catch (Exception exception) {
        throw new RuntimeException("invalid registry configuration", exception);
    } finally {
        IOUtils.closeQuietly(inputStream);
    }
}

From source file:com.google.u2f.gaedemo.impl.DataStoreImpl.java

@Override
public EnrollSessionData getEnrollSessionData(String sessionId) {
    SecretKey key = new SecretKeySpec(SecretKeys.get().sessionEncryptionKey(), "AES");

    byte[] serialized = Base64.decodeBase64(sessionId);
    ByteArrayInputStream inner = new ByteArrayInputStream(serialized);
    try {/*w w  w.j  a v a2s  .  c  om*/
        ObjectInputStream in = new ObjectInputStream(inner);

        SealedObject sealed = (SealedObject) in.readObject();
        return (EnrollSessionData) sealed.getObject(key);
    } catch (InvalidKeyException | ClassNotFoundException | NoSuchAlgorithmException | IOException e) {
        throw new RuntimeException(e);
    }
}

From source file:edu.uci.ics.jung.visualization.layout.PersistentLayoutImpl.java

/**
 * Restore the graph Vertex locations from a file
 * @param fileName the file to use//from ww w.j  ava 2  s  . co  m
 * @throws IOException for file problems
 * @throws ClassNotFoundException for classpath problems
 */
@SuppressWarnings("unchecked")
public void restore(String fileName) throws IOException, ClassNotFoundException {
    ObjectInputStream ois = new ObjectInputStream(new FileInputStream(fileName));
    map = (Map) ois.readObject();
    ois.close();
    initializeLocations();
    locked = true;
    fireStateChanged();
}

From source file:com.joliciel.talismane.lexicon.LexiconDeserializer.java

public PosTaggerLexicon deserializeLexiconFile(ObjectInputStream ois) {
    PosTaggerLexicon memoryBase = null;/* ww w  . j  a v  a2s .c o m*/
    try {
        memoryBase = (PosTaggerLexicon) ois.readObject();
        ois.close();
    } catch (IOException ioe) {
        throw new RuntimeException(ioe);
    } catch (ClassNotFoundException cnfe) {
        throw new RuntimeException(cnfe);
    }

    return memoryBase;
}

From source file:org.blanco.techmun.android.cproviders.EventosFetcher.java

private Eventos tryToLoadFromCache(Context context, long mesaId) {
    try {//from  w w w  .  j  ava  2s .  com
        FileInputStream mesasFIS = context.openFileInput("eventos_" + mesaId + ".df");
        ObjectInputStream mesasOIS = new ObjectInputStream(mesasFIS);
        Eventos result = (Eventos) mesasOIS.readObject();
        mesasOIS.close();

        return result;
    } catch (IOException e) {
        Log.e("tachmun",
                "Error opening cache file for mesas in content provider. " + "No cache will be restored", e);
        return null;
    } catch (ClassNotFoundException e) {
        Log.e("tachmun", "Error in cache file for mesas in content provider. "
                + "Something is there but is not a Mesas object. Cache no restored", e);
        return null;
    }
}

From source file:com.sun.j2ee.blueprints.waf.controller.web.flow.handlers.ClientStateFlowHandler.java

public String processFlow(HttpServletRequest request) throws FlowHandlerException {

    String forwardScreen = request.getParameter("referring_screen");
    // de-serialize the request attributes.
    Map params = (Map) request.getParameterMap();
    HashMap newParams = new HashMap();
    String cacheId = request.getParameter("cacheId");
    if (!params.isEmpty()) {
        Iterator it = params.keySet().iterator();
        // put the request attributes stored in the session in the request
        while (it.hasNext()) {
            String key = (String) it.next();
            if (key.startsWith(cacheId + "_attribute_")) {
                String[] values = (String[]) params.get(key);
                String valueString = values[0];
                byte[] bytes = Base64.decode(valueString.getBytes());
                try {
                    ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(bytes));
                    Object requestObject = requestObject = ois.readObject();
                    ois.close();//from  ww w  .  j  av a2 s.co m
                    // put the de-serialized object back into the request
                    String requestObjectKey = key.substring((cacheId + "_attribute_").length(), key.length());
                    request.setAttribute(requestObjectKey, requestObject);
                } catch (java.io.OptionalDataException ode) {
                    System.err.println("ClientCacheLinkFlowHandler caught: " + ode);
                } catch (java.lang.ClassNotFoundException cnfe) {
                    System.err.println("ClientCacheLinkFlowHandler caught: " + cnfe);
                } catch (java.io.IOException iox) {
                    System.err.println("ClientCacheLinkFlowHandler caught: " + iox);
                }
            }
        }
    }
    return forwardScreen;
}