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:DateServer.java

public void run() {
    while (true) {
        try {/*from ww  w . j  a  v a  2  s.c o  m*/
            Socket s = ss.accept();

            ObjectInputStream ois;
            ois = new ObjectInputStream(s.getInputStream());
            Locale l = (Locale) ois.readObject();

            PrintWriter pw;
            pw = new PrintWriter(s.getOutputStream());

            MessageFormat mf;
            mf = new MessageFormat("The date is {0, date, long}", l);

            Object[] args = { new Date() };

            pw.println(mf.format(args));

            pw.close();
        } catch (Exception e) {
            System.err.println(e);
        }
    }
}

From source file:cz.seznam.euphoria.hadoop.SerializableWritableTest.java

@SuppressWarnings("unchecked")
@Test// w  w  w.  j  a v  a  2s.  com
public void testSerialization() throws Exception {
    Configuration conf = new Configuration();
    conf.set("key", "value");

    SerializableWritable<Configuration> sw = new SerializableWritable<>(conf);

    // clone by serialization
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    ObjectOutputStream oos = new ObjectOutputStream(baos);
    oos.writeObject(sw);

    ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
    ObjectInputStream ois = new ObjectInputStream(bais);

    sw = (SerializableWritable<Configuration>) ois.readObject();
    Configuration newConf = sw.getWritable();

    assertEquals(conf.get("key"), newConf.get("key"));
}

From source file:de.iew.framework.utils.IewApplicationEvent.java

private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
    in.defaultReadObject();//www  .  ja  v  a  2s  .co m
    source = in.readObject();
}

From source file:gumga.framework.application.GumgaTempFileService.java

public GumgaFile find(String tempFileName) {
    if (tempFileName == null || tempFileName.isEmpty()) {
        return null;
    }/* w w w  . j a  v a 2s .c o m*/
    try { //TODO Melhorar o tratamento da Exception para FileNotFound
        FileInputStream fis = new FileInputStream(gumgaValues.getUploadTempDir() + "/" + tempFileName);
        ObjectInputStream ois = new ObjectInputStream(fis);
        GumgaFile gf = (GumgaFile) ois.readObject();
        ois.close();
        fis.close();
        return gf;
    } catch (Exception ex) {
        log.error("erro ao recuperar arquivo temporario " + tempFileName, ex);
    }
    return null;
}

From source file:cn.com.loopj.android.http.SerializableCookie.java

private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
    String key = (String) in.readObject();
    String value = (String) in.readObject();
    clientCookie = new BasicClientCookie(key, value);
    clientCookie.setComment((String) in.readObject());
    clientCookie.setDomain((String) in.readObject());
    clientCookie.setExpiryDate((Date) in.readObject());
    clientCookie.setPath((String) in.readObject());
    clientCookie.setVersion(in.readInt());
    clientCookie.setSecure(in.readBoolean());
}

From source file:com.blazeroni.reddit.http.SerializableCookie.java

private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
    String name = (String) in.readObject();
    String value = (String) in.readObject();
    BasicClientCookie c = new BasicClientCookie(name, value);
    c.setComment((String) in.readObject());
    c.setDomain((String) in.readObject());
    c.setExpiryDate((Date) in.readObject());
    c.setPath((String) in.readObject());
    c.setVersion(in.readInt());//from   ww w  . j  a v a  2s  .  com
    c.setSecure(in.readBoolean());

    this.cookie = c;
}

From source file:com.evozi.droidsniff.objects.CookieWrapper.java

private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
    String domain = (String) in.readObject();
    String name = (String) in.readObject();
    String path = (String) in.readObject();
    String value = (String) in.readObject();

    BasicClientCookie cookie = new BasicClientCookie(name, value);
    cookie.setDomain(domain);/* w w w  .j  ava2s.  c om*/
    cookie.setPath(path);
    cookie.setVersion(0);

    this.cookie = cookie;
}

From source file:cn.caimatou.canting.utils.http.asynchttp.SerializableCookie.java

private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
    String name = (String) in.readObject();
    String value = (String) in.readObject();
    clientCookie = new BasicClientCookie(name, value);
    clientCookie.setComment((String) in.readObject());
    clientCookie.setDomain((String) in.readObject());
    clientCookie.setExpiryDate((Date) in.readObject());
    clientCookie.setPath((String) in.readObject());
    clientCookie.setVersion(in.readInt());
    clientCookie.setSecure(in.readBoolean());
}

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

/**
 * Test case for Glassfish <a//www . j  a  v a2  s  . com
 * 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);
}

From source file:com.winvector.logistic.demo.MapReduceScore.java

public double run(final String modelFileName, final String testFileName, final String resultFileName)
        throws Exception {
    final Log log = LogFactory.getLog(MapReduceScore.class);
    final Random rand = new Random();
    final String tmpPrefix = "TMPAC_" + rand.nextLong();
    final Configuration mrConfig = getConf();
    log.info("start");
    log.info("reading model: " + modelFileName);
    final Model model;
    {/*w  ww. j  av  a2 s  .  c  o m*/
        final Path modelPath = new Path(modelFileName);
        final FSDataInputStream fdi = modelPath.getFileSystem(mrConfig).open(modelPath);
        final ObjectInputStream ois = new ObjectInputStream(fdi);
        model = (Model) ois.readObject();
        ois.close();
    }
    log.info("model:\n" + model.config.formatSoln(model.coefs));
    final Path testFile = new Path(testFileName);
    final Path resultFile = new Path(resultFileName);
    log.info("scoring data: " + testFile);
    log.info("writing: " + resultFile);
    final SigmoidLossMultinomial underlying = new SigmoidLossMultinomial(model.config.dim(),
            model.config.noutcomes());
    final WritableVariableList lConfig = WritableVariableList.copy(model.config.def());
    final String headerLine = WritableUtils.readFirstLine(mrConfig, testFile);
    final Pattern sepPattern = Pattern.compile("\t");
    final LineBurster burster = new HBurster(sepPattern, headerLine, false);
    mrConfig.set(MapRedScan.BURSTERSERFIELD, SerialUtils.serializableToString(burster));
    final StringBuilder b = new StringBuilder();
    b.append("predict" + "." + model.config.def().resultColumn + "\t");
    b.append("predict" + "." + model.config.def().resultColumn + "." + "score" + "\t");
    for (int i = 0; i < model.config.noutcomes(); ++i) {
        final String cat = model.config.outcome(i);
        b.append("predict" + "." + model.config.def().resultColumn + "." + cat + "." + "score" + "\t");
    }
    b.append(headerLine);
    mrConfig.set(MapRedScore.IDEALHEADERFIELD, b.toString());
    final MapRedScore sc = new MapRedScore(underlying, lConfig, model.config.useIntercept(), mrConfig,
            testFile);
    sc.score(model.coefs, resultFile);
    final MapRedAccuracy ac = new MapRedAccuracy(underlying, lConfig, model.config.useIntercept(), tmpPrefix,
            mrConfig, testFile);
    final long[] testAccuracy = ac.score(model.coefs);
    final double accuracy = testAccuracy[0] / (double) testAccuracy[1];
    log.info("test accuracy: " + testAccuracy[0] + "/" + testAccuracy[1] + "\t" + accuracy);
    log.info("done");
    return accuracy;
}