Example usage for java.io ObjectInputStream readLong

List of usage examples for java.io ObjectInputStream readLong

Introduction

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

Prototype

public long readLong() throws IOException 

Source Link

Document

Reads a 64 bit long.

Usage

From source file:Main.java

public static void main(String[] args) throws Exception {

    long l = 12345678909876L;

    FileOutputStream out = new FileOutputStream("test.txt");
    ObjectOutputStream oout = new ObjectOutputStream(out);

    // write something in the file
    oout.writeLong(l);//  w ww  .j av a2  s .c om
    oout.writeLong(987654321L);
    oout.flush();
    oout.close();
    // create an ObjectInputStream for the file we created before
    ObjectInputStream ois = new ObjectInputStream(new FileInputStream("test.txt"));

    // read and print a long
    System.out.println(ois.readLong());

    // read and print a long
    System.out.println(ois.readLong());
    ois.close();
}

From source file:jfs.sync.encryption.JFSEncryptedStream.java

public static long readLength(ObjectInputStream ois) throws IOException {
    return ois.readLong();
}

From source file:com.projity.pm.criticalpath.TaskSchedule.java

public static TaskSchedule deserialize(ObjectInputStream s) throws IOException, ClassNotFoundException {
    TaskSchedule t = new TaskSchedule();
    t.setPercentComplete(s.readDouble());
    t.setRawDuration(s.readLong());
    t.setStart(s.readLong());/* w ww . j  a va2s.  co m*/
    t.setFinish(s.readLong());
    return t;
}

From source file:mitm.application.djigzo.mail.MailContainer.java

private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
    long version = in.readLong();

    if (version != serialVersionUID) {
        throw new SerializationException("Version expected '" + serialVersionUID + "' but got '" + version);
    }/*from   ww  w . j a v  a 2  s.c om*/

    mail = (Mail) in.readObject();
}

From source file:mitm.application.djigzo.james.EncryptedContainer.java

@SuppressWarnings("unchecked")
private void readObject(ObjectInputStream in) throws IOException, EncryptorException {
    long version = in.readLong();

    if (version != serialVersionUID) {
        throw new SerializationException("Version expected '" + serialVersionUID + "' but got '" + version);
    }/*from w  w w  .  ja va 2  s.  com*/

    byte[] encrypted = new byte[in.readInt()];

    in.read(encrypted);

    value = (T) SerializationUtils.deserialize(getEncryptor().decrypt(encrypted));
}

From source file:com.qwazr.utils.server.InFileSessionPersistenceManager.java

private PersistentSession readSession(File sessionFile) {
    try {//from   w w w .j  a  va2 s  .c o  m
        final FileInputStream fileInputStream = new FileInputStream(sessionFile);
        try {
            final ObjectInputStream in = new ObjectInputStream(fileInputStream);
            try {
                final Date expDate = new Date(in.readLong());
                final HashMap<String, Object> sessionData = new HashMap<>();
                try {
                    for (;;)
                        readSessionAttribute(in, sessionData);
                } catch (EOFException e) {
                    ;// Ok we reached the end of the file
                }
                return sessionData.isEmpty() ? null : new PersistentSession(expDate, sessionData);
            } finally {
                IOUtils.close(in);
            }
        } finally {
            IOUtils.close(fileInputStream);
        }
    } catch (IOException e) {
        if (logger.isWarnEnabled())
            logger.warn("Cannot load sessions from " + sessionFile + " " + e.getMessage(), e);
        return null;
    }
}

From source file:gr.wavesoft.webng.io.cache.DiskCacheStorage.java

private HttpCacheEntry unserialize(byte[] bytes, String key) {
    try {//w  w w  . java2s .c o  m
        InputStream is = new ByteArrayInputStream(bytes);
        ObjectInputStream ois = new ObjectInputStream(is);

        // Read data
        Date dReq = new Date(ois.readLong());
        Date dRes = new Date(ois.readLong());
        StatusLine statusLine = (StatusLine) ois.readObject();
        Header[] responseHeaders = (Header[]) ois.readObject();

        // Close streams
        ois.close();
        is.close();

        // Build response
        HttpCacheEntry hce = new HttpCacheEntry(dReq, dRes, statusLine, responseHeaders,
                new FileResource(new File(baseDir + "/" + itemPrefix + key + ".cache")));

        return hce;

    } catch (ClassNotFoundException ex) {
        systemLogger.except(ex);
        return null;
    } catch (UnsupportedEncodingException ex) {
        systemLogger.except(ex);
        return null;
    } catch (IOException ex) {
        systemLogger.except(ex);
        return null;
    }
}

From source file:LongArrayList.java

private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
    in.defaultReadObject();//from  w  ww  .  ja va2 s .c  o  m
    array = new long[in.readInt()];
    for (int i = 0; i < size; i++) {
        array[i] = in.readLong();
    }
}

From source file:mitm.application.djigzo.james.Certificates.java

private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
    try {/*from ww  w  . j a  v a  2  s .c o m*/
        CertificateFactory certificateFactory = SecurityFactoryFactory.getSecurityFactory()
                .createCertificateFactory("X.509");

        certificates = new HashSet<X509Certificate>();

        long version = in.readLong();

        if (version != serialVersionUID) {
            throw new SerializationException("Version expected '" + serialVersionUID + "' but got '" + version);
        }

        /*
         * Read how many certificates we have to read.
         */
        int nrOfCertificates = in.readInt();

        for (int i = 0; i < nrOfCertificates; i++) {
            int encodedSize = in.readInt();

            byte[] encoded = new byte[encodedSize];

            in.readFully(encoded);

            X509Certificate certificate = (X509Certificate) certificateFactory
                    .generateCertificate(new ByteArrayInputStream(encoded));

            certificates.add(certificate);
        }
    } catch (NoSuchProviderException e) {
        throw new NoSuchProviderRuntimeException(e);
    } catch (CertificateException e) {
        throw new IOException(e);
    } catch (SecurityFactoryFactoryException e) {
        throw new IOException(e);
    }
}

From source file:hudson.console.AnnotatedLargeText.java

private ConsoleAnnotator createAnnotator(StaplerRequest req) throws IOException {
    try {/*from   w ww  .  j  a  va  2 s.c o m*/
        String base64 = req != null ? req.getHeader("X-ConsoleAnnotator") : null;
        if (base64 != null) {
            Cipher sym = PASSING_ANNOTATOR.decrypt();

            ObjectInputStream ois = new ObjectInputStreamEx(
                    new GZIPInputStream(new CipherInputStream(
                            new ByteArrayInputStream(Base64.decode(base64.toCharArray())), sym)),
                    Jenkins.getInstance().pluginManager.uberClassLoader);
            try {
                long timestamp = ois.readLong();
                if (TimeUnit2.HOURS.toMillis(1) > abs(System.currentTimeMillis() - timestamp))
                    // don't deserialize something too old to prevent a replay attack
                    return (ConsoleAnnotator) ois.readObject();
            } finally {
                ois.close();
            }
        }
    } catch (ClassNotFoundException e) {
        throw new IOException(e);
    }
    // start from scratch
    return ConsoleAnnotator.initial(context == null ? null : context.getClass());
}