Example usage for java.io ObjectInputStream ObjectInputStream

List of usage examples for java.io ObjectInputStream ObjectInputStream

Introduction

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

Prototype

public ObjectInputStream(InputStream in) throws IOException 

Source Link

Document

Creates an ObjectInputStream that reads from the specified InputStream.

Usage

From source file:core.service.bus.socket.SocketWrapper.java

public ObjectInputStream getObjectInputStream() throws IOException {
    synchronized (this) {
        if (input == null) {
            input = new ObjectInputStream(new BufferedInputStream(socket.getInputStream()));
        }/*from   w  w  w .  j av a2 s  .c  o m*/
    }
    return input;
}

From source file:misc.TestUtils.java

@SuppressWarnings("unchecked")
public static <T extends Serializable> T cloneSerializable(T obj) {
    ObjectOutputStream out = null;
    ObjectInputStream in = null;//from w w w . j ava  2 s  . c om

    try {
        ByteArrayOutputStream bout = new ByteArrayOutputStream();
        out = new ObjectOutputStream(bout);

        out.writeObject(obj);
        out.close();

        ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray());
        in = new ObjectInputStream(bin);
        Object copy = in.readObject();

        in.close();

        return (T) copy;
    } catch (Exception ex) {
        ex.printStackTrace();
    } finally {
        try {
            if (out != null) {
                out.close();
            }

            if (in != null) {
                in.close();
            }
        } catch (IOException ignore) {
        }
    }

    return null;
}

From source file:net.mindengine.oculus.frontend.web.Auth.java

public static User decodeUser(String encodedString) {
    try {//from   w  ww  .j  ava  2s.  c  om
        ObjectInputStream ois = new ObjectInputStream(
                new ByteArrayInputStream(Base64.decodeBase64(encodedString.getBytes())));
        SealedObject sealedObject = (SealedObject) ois.readObject();
        ois.close();

        Cipher dcipher = Cipher.getInstance("DES");
        dcipher.init(Cipher.DECRYPT_MODE, secrectAuthKey);

        User user = (User) sealedObject.getObject(dcipher);
        return user;
    } catch (Exception e) {
        return null;
    }
}

From source file:net.fizzl.redditengine.impl.PersistentCookieStore.java

/**
 * Load Cookies from a file/*from w  w  w .j a v a 2  s . c  o m*/
 */
private void load() {
    RedditApi api = DefaultRedditApi.getInstance();
    Context ctx = api.getContext();
    try {
        FileInputStream fis = ctx.openFileInput(cookiestore);
        ObjectInputStream ois = new ObjectInputStream(fis);
        SerializableCookieStore tempStore = (SerializableCookieStore) ois.readObject();

        super.clear();
        for (Cookie c : tempStore.getCookies()) {
            super.addCookie(c);
        }

        ois.close();
        fis.close();
    } catch (FileNotFoundException e) {
        Log.w(getClass().getName(), e.getMessage());
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:org.hoteia.qalingo.app.business.job.email.AbstractEmailItemProcessor.java

public Email process(CommonProcessIndicatorItemWrapper<Long, Email> wrapper) throws Exception {
    Email email = wrapper.getItem();//  w ww .  j  a v  a2s .c om
    Blob emailcontent = email.getEmailContent();

    InputStream is = emailcontent.getBinaryStream();
    ObjectInputStream oip = new ObjectInputStream(is);
    Object object = oip.readObject();

    MimeMessagePreparatorImpl mimeMessagePreparator = (MimeMessagePreparatorImpl) object;

    oip.close();
    is.close();

    try {
        // SANITY CHECK
        if (email.getStatus().equals(Email.EMAIl_STATUS_PENDING)) {

            if (mimeMessagePreparator.isMirroringActivated()) {
                String filePathToSave = mimeMessagePreparator.getMirroringFilePath();
                File file = new File(filePathToSave);

                // SANITY CHECK : create folders
                String absoluteFolderPath = file.getParent();
                File absolutePathFile = new File(absoluteFolderPath);
                if (!absolutePathFile.exists()) {
                    absolutePathFile.mkdirs();
                }

                if (!file.exists()) {
                    FileOutputStream fileOutputStream = new FileOutputStream(file);
                    OutputStreamWriter outputStreamWriter = new OutputStreamWriter(fileOutputStream,
                            Constants.UTF8);
                    Writer out = new BufferedWriter(outputStreamWriter);
                    if (StringUtils.isNotEmpty(mimeMessagePreparator.getHtmlContent())) {
                        out.write(mimeMessagePreparator.getHtmlContent());
                    } else {
                        out.write(mimeMessagePreparator.getPlainTextContent());
                    }

                    try {
                        if (out != null) {
                            out.close();
                        }
                    } catch (IOException e) {
                        logger.debug("Cannot close the file", e);
                    }
                } else {
                    logger.debug("File already exists : " + filePathToSave);
                }
            }

            mailSender.send(mimeMessagePreparator);
            email.setStatus(Email.EMAIl_STATUS_SENDED);
        } else {
            logger.warn("Batch try to send email was already sended!");
        }

    } catch (Exception e) {
        logger.error("Fail to send email! Exception is save in database, id:" + email.getId());
        email.setStatus(Email.EMAIl_STATUS_ERROR);
        emailService.handleEmailException(email, e);
    }

    return email;
}

From source file:FileGameAccess.java

@SuppressWarnings("resource")
private Object loadSerializable(String fName) {
    File file = new File(System.getProperty("user.dir") + File.separator + fName);
    if (!file.exists())
        return null;
    FileInputStream fis;//from   ww w.  j a v a  2 s . c o  m
    try {
        fis = new FileInputStream(file);
    } catch (FileNotFoundException ex) {
        Logger.getLogger(FileGameAccess.class.getName()).log(Level.SEVERE, null, ex);
        return null;
    }
    ObjectInputStream objectinputstream = null;
    try {
        objectinputstream = new ObjectInputStream(fis);
    } catch (IOException ex) {
        Logger.getLogger(FileGameAccess.class.getName()).log(Level.SEVERE, null, ex);
        return null;
    }
    try {
        Object newObject = objectinputstream.readObject();
        fis.close();
        return newObject;
    } catch (IOException | ClassNotFoundException ex) {
        Logger.getLogger(FileGameAccess.class.getName()).log(Level.SEVERE, null, ex);
    }
    return null;
}

From source file:cs.register.abrirefeichar.java

@Override
public void lerd() {
    ObjectInputStream objectIn = null;
    try {/*from   w  ww . j ava 2s  .com*/
        objectIn = new ObjectInputStream(new BufferedInputStream(new FileInputStream("save")));

        setList1((List<partida>) objectIn.readObject());

        objectIn.close();
    } catch (IOException ex) {
        salvaresair(1);
        lerd();
        return;

    } catch (ClassNotFoundException ex) {
        salvaresair(1);
        lerd();
        return;
    } finally {
        try {
            objectIn.close();
        } catch (IOException ex) {
            salvaresair(1);
            lerd();
            return;

        }
    }

}

From source file:net.brtly.monkeyboard.api.plugin.Bundle.java

/**
 * Factory method that creates a Bundle by deserializing a byte array
 * produced by {@link #toByteArray(Bundle)}
 * //w ww .  jav  a 2s . c o  m
 * @param b
 * @return
 * @throws IOException
 * @throws ClassNotFoundException
 */
public static Bundle fromByteArray(byte[] b) throws IOException, ClassNotFoundException {
    ByteArrayInputStream bis = new ByteArrayInputStream(b);
    ObjectInput in = null;
    try {
        in = new ObjectInputStream(bis);
        return (Bundle) in.readObject();
    } finally {
        bis.close();
        in.close();
    }
}

From source file:com.earldouglas.xjdl.io.LicenseLoader.java

protected License decryptLicense(String encodedLicense)
        throws BadPaddingException, UnsupportedEncodingException, Exception {
    byte[] encryptedLicense = Base64.decodeBase64(encodedLicense);

    SecretKeySpec secretKeySpec = new SecretKeySpec(key.getBytes(), "AES");
    Cipher cipher = Cipher.getInstance("AES");
    cipher.init(Cipher.DECRYPT_MODE, secretKeySpec);
    byte[] serializedLicense = cipher.doFinal(encryptedLicense);

    ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(serializedLicense);
    ObjectInputStream objectInputStream = new ObjectInputStream(byteArrayInputStream);
    License license = (License) objectInputStream.readObject();
    objectInputStream.close();//w  w w.  ja va2  s.  com
    return license;
}

From source file:com.jaspersoft.jasperserver.api.metadata.data.cache.JavaDataSnapshotSerializer.java

public DataSnapshot readSnapshot(InputStream in) throws IOException {
    if (log.isDebugEnabled()) {
        log.debug("deserializing data snapshot");
    }//from w w w  .ja  va  2s  .  com

    ObjectInputStream objectInput = new ObjectInputStream(in);
    DataSnapshot snapshot;
    try {
        snapshot = (DataSnapshot) objectInput.readObject();
    } catch (ClassNotFoundException e) {
        throw new JSExceptionWrapper("Failed to deserialize data snapshot", e);
    }

    if (log.isDebugEnabled()) {
        log.debug("deserialized data snapshot of type " + snapshot.getClass().getName());
    }

    return snapshot;
}