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:com.easytrack.component.system.LicenseCheck.java

private LicenseCheck() throws Exception {
    try {//from w w  w .  java2  s. co  m
        try {
            //            String file = Config.getHomeDir();
            //            if (file == null) {
            //               if ("Windows".startsWith(System.getProperty("os.name")))
            //                  file = "D:/EasyTrack";
            //               else {
            //                  file = "/home/easytrack";
            //               }
            //            }
            String file = "D:/EasyTrack";
            //            File f = new File(file + "/config/license.lic");
            File f = new File(file + "/config2/license.lic");
            if (f.exists()) {
                FileInputStream o = new FileInputStream(f);
                ObjectInputStream in = new ObjectInputStream(o);
                this.license = ((License) in.readObject());
                System.out.println(this.license.toString());
                System.out.println("-------------------");
                in.close();
                o.close();
            }
        } catch (Exception e) {
            e.printStackTrace();
            this.license = new License();
        }
        checkLicense(this.license);

        String s = Config.getConfig("LICENSE", "ALERT-THRESHOLD");
        this.alertThreshold = (Integer.parseInt(s) / 100.0D);
        if (this.alertThreshold > 1.0D) {
            this.alertThreshold = 1.0D;
        }
        this.adminEmail = Config.getConfig("LICENSE", "ADMIN-EMAIL");
    } catch (CommonException e) {
        throw e;
    } catch (Exception e) {
        e.printStackTrace();
        throw new CommonException("InvalidLicenseKey");
    }
}

From source file:com.mongodb.hadoop.mapred.input.MongoInputSplit.java

public void readFields(DataInput in) throws IOException {
    final ObjectInputStream objIn = new ObjectInputStream((InputStream) in);

    _mongoURI = new MongoURI(in.readUTF());
    _querySpec = (DBObject) JSON.parse(in.readUTF());
    _fieldSpec = (DBObject) JSON.parse(in.readUTF());
    _sortSpec = (DBObject) JSON.parse(in.readUTF());
    _limit = in.readInt();//w ww  .  j ava  2  s  .  co  m
    _skip = in.readInt();

    log.info("Deserialized MongoInputSplit ... { length = " + getLength() + ", locations = "
            + java.util.Arrays.toString(getLocations()) + ", query = " + _querySpec + ", fields = " + _fieldSpec
            + ", sort = " + _sortSpec + ", limit = " + _limit + ", skip = " + _skip + "}");

    objIn.close();
}

From source file:io.cloudslang.engine.queue.entities.ExecutionMessageConverter.java

private <T> T objFromBytes(byte[] bytes) {
    ObjectInputStream ois = null;
    try {// w w w  .jav a 2  s . c  o m
        //2 Buffers are added to increase performance
        ByteArrayInputStream is = new ByteArrayInputStream(bytes);

        skipPayloadMetaData(is);

        BufferedInputStream bis = new BufferedInputStream(is);
        ois = new ObjectInputStream(bis);

        //noinspection unchecked
        return (T) ois.readObject();
    } catch (IOException | ClassNotFoundException ex) {
        throw new RuntimeException("Failed to read execution plan from byte[]. Error: ", ex);
    } finally {
        IOUtils.closeQuietly(ois);
    }

}

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

/**
 * Creates a deep copy of any object.//from  w ww  . jav  a 2  s  .  c  om
 *
 * @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:de.zib.gndms.gritserv.tests.EncTest.java

public static void dryRun(EndpointReferenceType epr) throws Exception {

    ByteArrayOutputStream bse = new ByteArrayOutputStream();
    ObjectOutputStream oos = new ObjectOutputStream(bse);
    String sepr = ObjectSerializer.toString(epr, QNAME);
    System.out.println(sepr);// ww  w  . j  a  v  a2 s  .  c  o m
    oos.writeObject(sepr);

    Base64 b64 = new Base64(0, new byte[] {}, true);
    String uuepr = b64.encodeToString(bse.toByteArray());
    System.out.println("uuepr: \"" + uuepr + "\"");

    byte[] bt = b64.decode(uuepr.getBytes());

    ByteArrayInputStream bis = new ByteArrayInputStream(bt);
    ObjectInputStream ois = new ObjectInputStream(bis);
    String eprs = (String) ois.readObject();
    System.out.println(eprs);
}

From source file:com.limegroup.gnutella.auth.ContentCache.java

/**
  * Loads values from cache file, if available.
  *///from  w  w w  . j a  v  a2 s .  c  om
private void deserialize() {
    long cutoff = System.currentTimeMillis() - EXPIRY_TIME;

    ObjectInputStream ois = null;
    try {
        ois = new ObjectInputStream(new BufferedInputStream(new FileInputStream(CACHE_FILE)));
        Map map = (Map) ois.readObject();
        Map<URN, ContentResponseData> checked = GenericsUtils.scanForMap(map, URN.class,
                ContentResponseData.class, GenericsUtils.ScanMode.REMOVE);
        if (checked.size() != map.size())
            dirty = true;

        for (Iterator<ContentResponseData> i = checked.values().iterator(); i.hasNext();) {
            ContentResponseData data = i.next();
            if (data.getCreationTime() < cutoff) {
                if (LOG.isWarnEnabled())
                    LOG.warn("Removing old response [" + data + "]");
                i.remove();
                dirty = true;
            }
        }

        responses = checked;
    } catch (Throwable t) {
        dirty = true;
        LOG.error("Can't read responses", t);
    } finally {
        IOUtils.close(ois);
        if (responses == null)
            responses = new HashMap<URN, ContentResponseData>();
    }
}

From source file:com.servoy.extensions.plugins.http.AllowedCertTrustStrategy.java

/**
 * @return the holder// w  ww. j  a va2 s . co  m
 */
public CertificatesHolder getCertificatesHolder() {
    if (holder == null) {
        File file = new File(System.getProperty("user.home"), J2DBGlobals.CLIENT_LOCAL_DIR + "servoy.ks"); //$NON-NLS-1$//$NON-NLS-2$
        if (file.exists()) {
            ObjectInputStream ois = null;
            try {
                ois = new ObjectInputStream(new BufferedInputStream(new FileInputStream(file)));
                holder = (CertificatesHolder) ois.readObject();
            } catch (Exception e) {
                Debug.error(e);
            } finally {
                try {
                    if (ois != null)
                        ois.close();
                } catch (Exception e) {
                }
            }
        }
        if (holder == null)
            holder = new CertificatesHolder();
    }
    return holder;
}

From source file:com.joliciel.lefff.LefffMemoryLoader.java

public LefffMemoryBase deserializeMemoryBase(ZipInputStream zis) {
    LefffMemoryBase memoryBase = null;//from  ww  w .j  a v a 2  s . co  m
    MONITOR.startTask("deserializeMemoryBase");
    try {
        ZipEntry zipEntry;
        if ((zipEntry = zis.getNextEntry()) != null) {
            LOG.debug("Scanning zip entry " + zipEntry.getName());

            ObjectInputStream in = new ObjectInputStream(zis);
            memoryBase = (LefffMemoryBase) in.readObject();
            zis.closeEntry();
            in.close();
        } else {
            throw new RuntimeException("No zip entry in input stream");
        }
    } catch (IOException ioe) {
        throw new RuntimeException(ioe);
    } catch (ClassNotFoundException cnfe) {
        throw new RuntimeException(cnfe);
    } finally {
        MONITOR.endTask("deserializeMemoryBase");
    }

    Map<PosTagSet, LefffPosTagMapper> posTagMappers = memoryBase.getPosTagMappers();
    PosTagSet posTagSet = posTagMappers.keySet().iterator().next();
    memoryBase.setPosTagSet(posTagSet);

    return memoryBase;
}

From source file:de.tudarmstadt.ukp.dkpro.wsd.si.dictionary.GoogleDictionaryInventory.java

public GoogleDictionaryInventory(String inputPath, String serializiblePath, String neededMentionsPath)
        throws FileNotFoundException, IOException {
    // Open the serialized version or create it from scratch
    try {//from www.  ja  v a2s  . c o  m
        logger.debug("Trying to load dictionary " + this.getClass().getSimpleName() + " from serializable.");
        ObjectInputStream dictionaryReader = new ObjectInputStream(
                new BZip2CompressorInputStream(new FileInputStream(serializiblePath)));
        dictionary = (GoogleDictionary) dictionaryReader.readObject();
        dictionaryReader.close();
        logger.debug("Loaded dictionary " + this.getClass().getSimpleName() + " from serializable.");
    } catch (Exception e) {
        logger.debug("Trying to load dictionary " + this.getClass().getSimpleName() + " from input.");
        dictionary = new GoogleDictionary(inputPath, neededMentionsPath);
        System.out.println("Loaded dictionary " + this.getClass().getSimpleName() + " from input.");

        ObjectOutputStream dictionaryWriter = new ObjectOutputStream(
                new BZip2CompressorOutputStream(new FileOutputStream(serializiblePath)));
        dictionaryWriter.writeObject(dictionary);
        dictionaryWriter.close();
        logger.debug("Stored dictionary " + this.getClass().getSimpleName() + " in serializable.");

    }
}

From source file:com.googlecode.jeeunit.example.test.spring.AuthorTest.java

/**
 * Test case for Glassfish <a/*from  w  ww.j a va 2  s  .c  om*/
 * href="https://glassfish.dev.java.net/issues/show_bug.cgi?id=12599">bug #12599</a>.
 * 
 * @throws IOException
 * @throws ClassNotFoundException
 */
@Test
@Ignore
public void serialization() throws IOException, ClassNotFoundException {
    long expectedNumBooks = libraryService.getNumBooks();
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    ObjectOutputStream oos = new ObjectOutputStream(baos);
    oos.writeObject(libraryService);
    oos.close();

    byte[] bytes = baos.toByteArray();
    ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
    ObjectInputStream ois = new ObjectInputStream(bais);
    Object obj = ois.readObject();
    assertTrue(obj instanceof LibraryService);

    // the deserialized proxy throws a NullPointerException on method invocation
    long numBooks = ((LibraryService) obj).getNumBooks();
    assertEquals(expectedNumBooks, numBooks);
}