List of usage examples for java.io ObjectInputStream ObjectInputStream
public ObjectInputStream(InputStream in) throws IOException
From source file:maltcms.ui.fileHandles.serialized.JFCLoader.java
@Override public JFreeChart call() throws Exception { ph.start(100);/*from w w w. j a va 2 s .co m*/ JFreeChart chart = null; try { ph.progress("Opening file", 33); try (ObjectInputStream ois = new ObjectInputStream( new BufferedInputStream(new FileInputStream(filename)))) { ph.progress("Reading object", 66); chart = (JFreeChart) ois.readObject(); } } catch (final ClassNotFoundException e) { ph.progress("ClassNotFoundException", 80); e.printStackTrace(); } catch (final IOException e) { ph.progress("IOException", 80); e.printStackTrace(); } ph.progress("Finished!", 100); ph.finish(); return chart; }
From source file:com.thoughtworks.go.util.ObjectUtil.java
public static Object deserialize(byte[] bytes) { try {/*ww w. ja v a 2 s .c o m*/ return new ObjectInputStream(new ByteArrayInputStream(bytes)).readObject(); } catch (Exception e) { throw ExceptionUtils.bomb(e); } }
From source file:jp.queuelinker.system.util.SerializeUtil.java
/** * Deserializes an object from a byte array by using the Java standard serialization mechanism. * @param data//from w ww . j ava 2s. co m * @param offset * @param length * @return */ public static Object deserialize(final byte[] data, final int offset, final int length) { Object ret = null; ByteArrayInputStream byteStream = new ByteArrayInputStream(data, offset, length); try { ObjectInputStream objStream = new ObjectInputStream(byteStream); ret = objStream.readObject(); objStream.close(); } catch (IOException e) { logger.error("Exception: " + e); } catch (ClassNotFoundException e) { logger.error("Exception: " + e); } return ret; }
From source file:com.rr.familyPlanning.ui.security.decryptObject.java
/** * Decrypts the String and serializes the object * * @param base64Data/*from w ww. j ava 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:info.donsun.cache.filecache.FileCache.java
@Override public Object get(Object key) throws CacheException { synchronized (LOCK) { // /*from w w w .j av a 2 s . c o m*/ if (exists(key)) { // ?? for (String fileName : listFileNames()) { if (isCacheFile(key, fileName)) { try { FileInputStream fileStream = new FileInputStream( FileUtils.getFile(config.getDir(), fileName)); ObjectInputStream in = new ObjectInputStream(fileStream); boolean isExpire = false; try { CachedObject cachedObject = (CachedObject) in.readObject(); // if (cachedObject.getExpire() > 0 && cachedObject.getExpire() < System.currentTimeMillis()) { isExpire = true; return null; } return cachedObject.getData(); } finally { in.close(); fileStream.close(); if (isExpire) { remove(key); } } } catch (Exception e) { throw new CacheException("Get cache file fail.", e); } } } } return null; } }
From source file:eu.supersede.fe.security.redis.template.ObjectRedisSerializer.java
@Override public Object deserialize(byte[] bytes) throws SerializationException { if (bytes == null) { return null; }/* w ww . ja v a2 s .c o m*/ try (ByteArrayInputStream b = new ByteArrayInputStream(bytes)) { try (ObjectInputStream o = new ObjectInputStream(b)) { return o.readObject(); } } catch (Exception ex) { log.error(ex.getMessage()); } return null; }
From source file:BckgrndServiceThreads.fileListingTH.java
Object getSerializedObject(String objectName) throws Exception { FileInputStream inputFile = new FileInputStream(objectName); ObjectInputStream inputObject = new ObjectInputStream(inputFile); Object getObjectToReturn = inputObject.readObject(); inputObject.close();//from w ww .j a v a2s .c o m return getObjectToReturn; }
From source file:com.griddynamics.jagger.util.SerializationUtils.java
public static <T extends Serializable> T fromString(String s) { if (s.isEmpty()) { log.info("fromString({}, '{}')", fromStringCount.getAndIncrement(), s); }/*from www .jav a2 s . c o m*/ ObjectInputStream ois = null; try { byte[] data = Base64Coder.decode(s); try { //TODO fixes for support old reports ois = new JBossObjectInputStream(new ByteArrayInputStream(data)); } catch (IOException e) { // /data stored not with JBoss ois = new ObjectInputStream(new ByteArrayInputStream(data)); } T obj = (T) ois.readObject(); return obj; } catch (IOException e) { log.error("Deserialization exception ", e); log.error("fromString('{}')", s); throw new TechnicalException(e); } catch (ClassNotFoundException e) { log.error("Deserialization exception ", e); throw new TechnicalException(e); } finally { try { Closeables.close(ois, true); } catch (IOException e) { log.warn("IOException should not have been thrown.", e); } } }
From source file:com.impetus.kundera.property.accessor.ObjectAccessor.java
@Override public final Object fromBytes(Class targetClass, byte[] bytes) { try {/* w w w . j av a 2 s. c o m*/ if (targetClass != null && targetClass.equals(byte[].class)) { return bytes; } ObjectInputStream ois; ois = new ObjectInputStream(new ByteArrayInputStream(bytes)); Object o = ois.readObject(); ois.close(); return o; } catch (IOException e) { throw new PropertyAccessException(e); } catch (ClassNotFoundException e) { throw new PropertyAccessException(e); } }
From source file:com.marintek.isis.wicket.popupbox.applib.PopupWicketBoxSemanticsProvider.java
static Object fromString(String s) { final byte[] data = Base64.decodeBase64(s); ObjectInputStream ois = null; try {// w w w. jav a 2 s .com ois = new ObjectInputStream(new ByteArrayInputStream(data)); return ois.readObject(); } catch (IOException e) { throw new Base64Serializer.Exception(e); } catch (ClassNotFoundException e) { throw new Base64Serializer.Exception(e); } finally { try { if (ois != null) { ois.close(); } } catch (IOException e) { throw new Base64Serializer.Exception(e); } } }