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:fr.inria.atlanmod.neoemf.data.hbase.util.HBaseEncoderUtil.java

public static String[] toStrings(byte[] bytes) {
    if (isNull(bytes)) {
        return null;
    }//from  w  ww. j  a v  a2  s  .  c om

    String[] result = null;
    ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(bytes);
    ObjectInputStream objectInputStream = null;
    try {
        objectInputStream = new ObjectInputStream(byteArrayInputStream);
        result = (String[]) objectInputStream.readObject();
    } catch (IOException e) {
        NeoLogger.error("Unable to convert ''{0}'' to String[]", Arrays.toString(bytes));
    } catch (ClassNotFoundException e) {
        NeoLogger.error(e);
    } finally {
        IOUtils.closeQuietly(objectInputStream);
    }
    return result;
}

From source file:de.codecentric.boot.admin.event.ClientApplicationEventTest.java

@SuppressWarnings("unchecked")
/**//from   w  w  w .j a v  a 2s.  c o  m
 * yeah nasty but we need exact the same timestamp
 */
private <T extends Serializable> T cloneBySerialization(T obj) throws IOException, ClassNotFoundException {
    try (ByteArrayOutputStream buf = new ByteArrayOutputStream()) {
        try (ObjectOutputStream oos = new ObjectOutputStream(buf)) {
            oos.writeObject(obj);
        }

        try (ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(buf.toByteArray()))) {
            return (T) ois.readObject();
        }
    }
}

From source file:id.co.nlp.MachineTranslation.Utils.Util.java

public static Object deserializing(String pathfile)
        throws FileNotFoundException, IOException, ClassNotFoundException {
    FileInputStream fileIn = new FileInputStream(pathfile);
    ObjectInputStream in = new ObjectInputStream(fileIn);
    Object object = in.readObject();
    in.close();// ww w  . j a  va  2  s.c  o m
    fileIn.close();
    return object;
}

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

public UkbDictionaryInventory(String inputPath, String serializiblePath, String neededMentionsPath)
        throws FileNotFoundException, IOException {
    // Open the serialized version or create it from scratch
    try {/*  ww  w  . j  a  va2s .  c  o  m*/
        // System.out.println("Trying to load dictionary from serializable.");
        ObjectInputStream dictionaryReader = new ObjectInputStream(
                new BZip2CompressorInputStream(new FileInputStream(serializiblePath)));
        dictionary = (UkbDictionary) dictionaryReader.readObject();
        dictionaryReader.close();
        // System.out.println("Loaded dictionary from serializable.");
    } catch (Exception e) {
        // System.out.println("Trying to load dictionary from input.");
        dictionary = new UkbDictionary(inputPath, neededMentionsPath);
        System.out.println("Loaded dictionary from input.");

        ObjectOutputStream dictionaryWriter = new ObjectOutputStream(
                new BZip2CompressorOutputStream(new FileOutputStream(serializiblePath)));
        dictionaryWriter.writeObject(dictionary);
        dictionaryWriter.close();
        // System.out.println("Stored dictionary in serializable.");
    }

}

From source file:MSUmpire.SpectrumParser.DIA_Setting.java

public static DIA_Setting ReadDIASettingSerialization(String filepath) {
    if (!new File(FilenameUtils.getFullPath(filepath) + FilenameUtils.getBaseName(filepath) + "_diasetting.ser")
            .exists()) {// w  w  w .  j a  va  2s  . c o  m
        return null;
    }
    try {
        Logger.getRootLogger().debug("Reading DIA setting from file:" + FilenameUtils.getFullPath(filepath)
                + FilenameUtils.getBaseName(filepath) + "_diasetting.ser...");

        FileInputStream fileIn = new FileInputStream(
                FilenameUtils.getFullPath(filepath) + FilenameUtils.getBaseName(filepath) + "_diasetting.ser");
        ObjectInputStream in = new ObjectInputStream(fileIn);
        DIA_Setting setting = (DIA_Setting) in.readObject();
        in.close();
        fileIn.close();
        return setting;

    } catch (Exception ex) {
        Logger.getRootLogger().error(ExceptionUtils.getStackTrace(ex));
        return null;
    }
}

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

@Test
public void testGoogleDictionary() throws Exception {

    FileUtils.deleteQuietly(new File(output));

    GoogleDictionary dictionary = new GoogleDictionary(path, needed_mentions);
    Assert.assertNotNull(dictionary);/*from ww  w  .  j  a va  2  s  .com*/

    ObjectOutputStream dictionaryWriter = new ObjectOutputStream(
            new BZip2CompressorOutputStream(new FileOutputStream(output)));
    dictionaryWriter.writeObject(dictionary);
    dictionaryWriter.close();

    Assert.assertTrue(new File(output).exists());

    ObjectInputStream dictionaryReader = new ObjectInputStream(
            new BZip2CompressorInputStream(new FileInputStream(output)));

    dictionary = null;
    dictionary = (GoogleDictionary) dictionaryReader.readObject();

    Assert.assertNotNull(dictionary);
    System.out.println(dictionary.getNumberOfMentionEntityPairs());
    System.out.println(dictionary.getTargetSize());
    Assert.assertEquals(3, dictionary.getTargetValuePairs("claude_monet").size());

    dictionaryReader.close();

}

From source file:org.activiti.designer.eclipse.navigator.cloudrepo.ActivitiCloudEditorUtil.java

public static CloseableHttpClient getAuthenticatedClient() {

    // Get settings from preferences
    String url = PreferencesUtil.getStringPreference(Preferences.ACTIVITI_CLOUD_EDITOR_URL);
    String userName = PreferencesUtil.getStringPreference(Preferences.ACTIVITI_CLOUD_EDITOR_USERNAME);
    String password = PreferencesUtil.getStringPreference(Preferences.ACTIVITI_CLOUD_EDITOR_PASSWORD);
    String cookieString = PreferencesUtil.getStringPreference(Preferences.ACTIVITI_CLOUD_EDITOR_COOKIE);

    Cookie cookie = null;//from   w w  w  .j  a  va 2  s.  c  om
    if (StringUtils.isNotEmpty(cookieString)) {
        ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(
                hexStringToByteArray(cookieString));
        try {
            ObjectInputStream objectInputStream = new ObjectInputStream(byteArrayInputStream);
            cookie = (BasicClientCookie) objectInputStream.readObject();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    // Build session
    BasicCookieStore cookieStore = new BasicCookieStore();
    CloseableHttpClient httpClient = HttpClients.custom().setDefaultCookieStore(cookieStore).build();

    if (cookie == null) {
        try {
            HttpUriRequest login = RequestBuilder.post().setUri(new URI(url + "/rest/app/authentication"))
                    .addParameter("j_username", userName).addParameter("j_password", password)
                    .addParameter("_spring_security_remember_me", "true").build();

            CloseableHttpResponse response = httpClient.execute(login);

            try {
                EntityUtils.consume(response.getEntity());
                List<Cookie> cookies = cookieStore.getCookies();
                if (cookies.isEmpty()) {
                    // nothing to do
                } else {
                    Cookie reponseCookie = cookies.get(0);
                    ByteArrayOutputStream os = new ByteArrayOutputStream();
                    ObjectOutputStream outputStream = new ObjectOutputStream(os);
                    outputStream.writeObject(reponseCookie);
                    PreferencesUtil.getActivitiDesignerPreferenceStore().setValue(
                            Preferences.ACTIVITI_CLOUD_EDITOR_COOKIE.getPreferenceId(),
                            byteArrayToHexString(os.toByteArray()));
                    InstanceScope.INSTANCE.getNode(ActivitiPlugin.PLUGIN_ID).flush();
                }

            } finally {
                response.close();
            }

        } catch (Exception e) {
            Logger.logError("Error authenticating " + userName, e);
        }

    } else {
        // setting cookie from cache
        cookieStore.addCookie(cookie);
    }

    return httpClient;
}

From source file:gui.CompressDecompress.java

private static List<List<BigInteger>> deserialize(byte[] bytes) throws IOException, ClassNotFoundException {
    ByteArrayInputStream b = new ByteArrayInputStream(bytes);
    ObjectInputStream o = new ObjectInputStream(b);
    return (List<List<BigInteger>>) o.readObject();
}

From source file:com.hp.autonomy.hod.client.api.resource.ResourceTest.java

@Test
public void testSerializeAndDeserialize() throws IOException, ClassNotFoundException {
    final ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();

    final Resource input = new Resource(UUID.randomUUID(), "name", "domain");

    try (final ObjectOutput objectOutputStream = new ObjectOutputStream(byteArrayOutputStream)) {
        objectOutputStream.writeObject(input);
    }//  w  w  w  .j a va2 s  .c om

    try (final ObjectInputStream objectInputStream = new ObjectInputStream(
            new ByteArrayInputStream(byteArrayOutputStream.toByteArray()))) {
        @SuppressWarnings("CastToConcreteClass")
        final Resource output = (Resource) objectInputStream.readObject();
        assertThat(output, is(input));
    }
}

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

public GumgaFile find(String tempFileName) {
    if (tempFileName == null || tempFileName.isEmpty()) {
        return null;
    }//  ww  w  .j a  v a  2 s  .co  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;
}