Example usage for java.io ObjectInput readObject

List of usage examples for java.io ObjectInput readObject

Introduction

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

Prototype

public Object readObject() throws ClassNotFoundException, IOException;

Source Link

Document

Read and return an object.

Usage

From source file:com.lhy.commons.encrypt.service.EncryptService.java

@Override
public License getLicense(File licenseFile, String ipAddress) {
    License licFile = null;/*w  ww . j  a v  a  2s  . co  m*/
    try {
        ObjectInput in = new ObjectInputStream(new FileInputStream(licenseFile));
        licFile = (License) in.readObject();
        if (licFile.getIpAddress().equals(DigestUtils.sha512Hex(ipAddress))
                && licFile.getLicenseType().equals(LicenseType.user)) {
            licFile.setLicenseType(LicenseType.user);
        } else {
            licFile.setLicenseType(LicenseType.developer);
        }
        in.close();
    } catch (FileNotFoundException e) {
        log.error(e.getMessage());
    } catch (IOException e) {
        log.error(e.getMessage());
    } catch (ClassNotFoundException e) {
        log.error(e.getMessage());
    }
    return licFile;
}

From source file:com.rr.familyPlanning.ui.security.decryptObject.java

/**
 * Decrypts the String and serializes the object
 *
 * @param base64Data//w  w  w .  j  a  v  a  2 s . co  m
 * @param base64IV
 * @return
 * @throws Exception
 */
public Object decryptObject(String base64Data, String base64IV) throws Exception {
    // Decode the data
    byte[] encryptedData = Base64.decodeBase64(base64Data.getBytes());

    // Decode the Init Vector
    byte[] rawIV = Base64.decodeBase64(base64IV.getBytes());

    // Configure the Cipher
    Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
    IvParameterSpec ivSpec = new IvParameterSpec(rawIV);
    MessageDigest digest = MessageDigest.getInstance("SHA-256");
    digest.update(keyString.getBytes());
    byte[] key = new byte[16];
    System.arraycopy(digest.digest(), 0, key, 0, key.length);
    SecretKeySpec keySpec = new SecretKeySpec(key, "AES");
    cipher.init(Cipher.DECRYPT_MODE, keySpec, ivSpec);

    // Decrypt the data..
    byte[] decrypted = cipher.doFinal(encryptedData);

    // Deserialize the object
    ByteArrayInputStream stream = new ByteArrayInputStream(decrypted);

    ObjectInput in = new ObjectInputStream(stream);
    Object obj = null;
    try {
        obj = in.readObject();
    } finally {
        stream.close();
        in.close();
    }
    return obj;
}

From source file:MemComboBoxDemo.java

public void load(String fName) {
    try {//from  w w w .j av  a  2  s  . c o  m
        if (getItemCount() > 0)
            removeAllItems();
        File f = new File(fName);
        if (!f.exists())
            return;
        FileInputStream fStream = new FileInputStream(f);
        ObjectInput stream = new ObjectInputStream(fStream);

        Object obj = stream.readObject();
        if (obj instanceof ComboBoxModel)
            setModel((ComboBoxModel) obj);

        stream.close();
        fStream.close();
    } catch (Exception e) {
        System.err.println("Serialization error: " + e.toString());
    }
}

From source file:xbird.xquery.dm.value.sequence.EncodedSequence.java

public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
    this.type = (Type) in.readObject();
    final byte[] b = IOUtils.readBytes(in);
    //this.encodedSequence = b;
    this.actualSequence = decode(b);
}

From source file:gov.nih.nci.caarray.external.v1_0.data.AbstractDataColumn.java

/**
 * Optimizes the serialized form of this class by compressing the values array.
 * /*from   w  w  w.j a va  2 s . c  o  m*/
 * {@inheritDoc}
 */
public void readExternal(ObjectInput oi) throws IOException, ClassNotFoundException {
    this.quantitationType = (QuantitationType) oi.readObject();
    int valuesLength = oi.readInt();
    byte[] serializedValues = new byte[valuesLength];
    oi.readFully(serializedValues);
    setSerializableValues(CaArrayUtils.deserialize(serializedValues));
}

From source file:com.parallax.server.blocklyprop.db.dao.impl.SessionDaoImpl.java

private void printSessionInfo(String action, SessionRecord session) {
    if (configuration.getBoolean("debug.session", false)) {
        try {/*from  ww  w .j  a v  a 2s  .c  o  m*/
            if (session == null || session.getAttributes() == null) {
                System.out.println(action + ": NO SESSION AVAILABLE");
            } else {
                ByteArrayInputStream bis = new ByteArrayInputStream(session.getAttributes());
                ObjectInput in = new ObjectInputStream(bis);
                HashMap attributes = (HashMap) in.readObject();
                System.out.println(action + ": " + attributes);
            }
        } catch (IOException ex) {
            Logger.getLogger(SessionDaoImpl.class.getName()).log(Level.SEVERE, null, ex);
        } catch (ClassNotFoundException cnfe) {
            Logger.getLogger(SessionDaoImpl.class.getName()).log(Level.SEVERE, null, cnfe);
        }
    }

}

From source file:Clock.java

public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
    setDigital(in.readBoolean());/*from  w  w  w  . j  a  v a2s .c om*/
    setBackground((Color) in.readObject());
    setForeground((Color) in.readObject());
    setPreferredSize((Dimension) in.readObject());
}

From source file:com.gsma.mobileconnect.discovery.DiscoveryResponseTest.java

private DiscoveryResponse roundTripSerialize(DiscoveryResponse in) throws IOException, ClassNotFoundException {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    ObjectOutput output = new ObjectOutputStream(baos);

    output.writeObject(in);//from   w w w  .  j a v  a2s  .  c o  m

    output.close();

    ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
    ObjectInput input = new ObjectInputStream(bais);

    DiscoveryResponse out = (DiscoveryResponse) input.readObject();

    input.close();

    return out;
}

From source file:ca.uhn.fhir.model.api.BasePrimitive.java

@Override
public void readExternal(ObjectInput theIn) throws IOException, ClassNotFoundException {
    String object = (String) theIn.readObject();
    setValueAsString(object);/*from  w  w  w  .j  a v a  2s.  c o m*/
}

From source file:ca.uhn.fhir.model.primitive.BoundCodeDt.java

@SuppressWarnings("unchecked")
@Override/*from www .  j a  v  a2  s .  c  o m*/
public void readExternal(ObjectInput theIn) throws IOException, ClassNotFoundException {
    super.readExternal(theIn);
    myBinder = (IValueSetEnumBinder<T>) theIn.readObject();
}