List of usage examples for java.io ObjectOutputStream ObjectOutputStream
public ObjectOutputStream(OutputStream out) throws IOException
From source file:com.github.stephanarts.cas.ticket.registry.provider.GetTicketsMethod.java
/** * Execute the JSONRPCFunction./*from w w w . j ava 2s . c om*/ * * @param params JSONRPC Method Parameters. * * @return JSONRPC result object * * @throws JSONRPCException implementors can throw JSONRPCExceptions containing the error. */ public JSONObject execute(final JSONObject params) throws JSONRPCException { JSONObject result = new JSONObject(); JSONArray tickets = new JSONArray(); String ticketId = null; if (params.length() != 0) { throw new JSONRPCException(-32602, "Invalid Params"); } for (Ticket ticket : this.map.values()) { byte[] serializedTicketArray = { 0 }; try { ByteArrayOutputStream bo = new ByteArrayOutputStream(); ObjectOutputStream so = new ObjectOutputStream(bo); so.writeObject(ticket); so.flush(); serializedTicketArray = bo.toByteArray(); } catch (final Exception e) { logger.debug(e.getMessage()); throw new JSONRPCException(-32500, "Error extracting Ticket"); } tickets.put(DatatypeConverter.printBase64Binary(serializedTicketArray)); } logger.debug("GetTickets: " + tickets.length()); result.put("tickets", tickets); return result; }
From source file:com.backbase.expert.extensions.sushi.util.Base64Serializer.java
@Override public String writeObject(Serializable serializable) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); ObjectOutputStream oos = null; String str = null;//from w ww.j a v a 2 s . co m try { oos = new ObjectOutputStream(baos); oos.writeObject(serializable); byte[] data = baos.toByteArray(); str = new String(Base64.encodeBase64(data), "UTF-8"); } catch (IOException e) { LOG.error("Could not encode the object to a base64 string.", e); } finally { IOUtils.closeQuietly(oos); } return str; }
From source file:com.ibm.watson.developer_cloud.professor_languo.ingestion.indexing.StackExchangeThreadSerializer.java
/** * Serialize a StackExchangeThread into a byte array * //from ww w. j a va 2 s.com * @param threadToSerialize - StackExchangeThread to be serialized * @return a byte array serialized from the StackExchangeThread * @throws IngestionException */ public static byte[] serializeThreadToBinArr(StackExchangeThread threadToSerialize) throws IngestionException { ByteArrayOutputStream binOut = new ByteArrayOutputStream(); try { ObjectOutputStream out = new ObjectOutputStream(binOut); out.writeObject(threadToSerialize); out.close(); binOut.close(); } catch (IOException e) { throw new IngestionException(e); } return binOut.toByteArray(); }
From source file:com.sec.ose.osi.ui.cache.UICache.java
private void save() { log.debug("save cache"); ObjectOutputStream dos = null; try {//from w w w . j av a 2s . c om File file = new File(CACHE_FILE_NAME); if (file.exists() == false) file.createNewFile(); // IOException dos = new ObjectOutputStream(new FileOutputStream(file)); // FileNotFoundException dos.writeObject(mMap); } catch (FileNotFoundException e) { log.warn(e); } catch (IOException e) { log.warn(e); } finally { if (dos != null) { try { dos.flush(); } catch (IOException e) { log.warn(e); } try { dos.close(); } catch (IOException e) { log.warn(e); } dos = null; } } log.debug("save done"); }
From source file:org.sakaiproject.orm.ibatis.support.BlobSerializableTypeHandler.java
protected void setParameterInternal(PreparedStatement ps, int index, Object value, String jdbcType, LobCreator lobCreator) throws SQLException, IOException { if (value != null) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); ObjectOutputStream oos = new ObjectOutputStream(baos); try {//from w w w .j a v a2 s .c om oos.writeObject(value); oos.flush(); lobCreator.setBlobAsBytes(ps, index, baos.toByteArray()); } finally { oos.close(); } } else { lobCreator.setBlobAsBytes(ps, index, null); } }
From source file:it.unimi.di.big.mg4j.io.IOFactories.java
public static void storeObject(final IOFactory ioFactory, final Object object, final String filename) throws IOException { final ObjectOutputStream oos = new ObjectOutputStream( new FastBufferedOutputStream(ioFactory.getOutputStream(filename))); oos.writeObject(object);/*from w w w .ja v a2 s. com*/ oos.close(); }
From source file:org.alfresco.rad.test.AlfrescoTestRunner.java
public static String serializableToString(Serializable serializable) throws IOException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); ObjectOutputStream oos = new ObjectOutputStream(baos); oos.writeObject(serializable);//w w w. j av a2 s . c om oos.close(); String string = Base64.encodeBase64URLSafeString(baos.toByteArray()); return string; }
From source file:net.sf.ehcache.constructs.asynchronous.ListAppenderCommand.java
private void checkSerializability(Serializable payload) throws IOException { ObjectOutputStream oout = new ObjectOutputStream(new ByteArrayOutputStream()); oout.writeObject(payload);/*from w w w . ja va 2 s . com*/ }
From source file:com.cloudera.recordservice.hcatalog.common.HCatRSUtil.java
public static String serialize(Serializable obj) throws IOException { if (obj == null) { return ""; }/* w ww .j a v a 2s . co m*/ try { ByteArrayOutputStream serialObj = new ByteArrayOutputStream(); ObjectOutputStream objStream = new ObjectOutputStream(serialObj); objStream.writeObject(obj); objStream.close(); return encodeBytes(serialObj.toByteArray()); } catch (Exception e) { throw new IOException("Serialization error: " + e.getMessage(), e); } }
From source file:com.lhy.commons.encrypt.service.EncryptService.java
@Override public File createLicenseFile(License license, String licenseFilePath) { License licObj = new License(); licObj.setIpAddress(DigestUtils.sha512Hex(license.getIpAddress())); licObj.setLicenseID(license.getLicenseID()); licObj.setLicenseType(license.getLicenseType()); licObj.setStopTime(// w ww . ja v a 2 s. co m license.getStopTime() == null ? DateUtils.addDays(new Date(), 30) : license.getStopTime()); File licenseFile = null; try { licenseFile = new File(licenseFilePath + File.separator + LicenseFileName); ObjectOutput out = new ObjectOutputStream(new FileOutputStream(licenseFile)); out.writeObject(licObj); out.close(); } catch (FileNotFoundException e) { log.error(e.getMessage()); } catch (IOException e) { log.error(e.getMessage()); } return licenseFile; }