List of usage examples for java.io ObjectOutputStream close
public void close() throws IOException
From source file:com.adaptris.core.services.metadata.CheckUniqueMetadataValueService.java
private void storePreviouslyReceivedValues() { if (store != null) { try {/*from w w w . j a v a2s . c o m*/ ObjectOutputStream o = new ObjectOutputStream(new FileOutputStream(store)); o.writeObject(previousValuesStore); o.flush(); o.close(); } catch (Exception e) { log.error("exception storing previously received values", e); log.error(previousValuesStore.toString()); } } }
From source file:com.sec.ose.osi.thread.job.identify.data.IdentifyErrorQueue.java
private boolean updateDatFileByIdentifyErrorQueue() { log.debug("updateIdentifyErrorQueueFile-start - num of item:" + size()); FileOutputStream fos = null;//from w w w .j ava 2s . c om try { // Check Folder File dir = new File(DAT_FILE_DIRECTORY); if (!dir.exists()) { if (dir.mkdirs() == false) { System.err.println("Can not create folder."); } } // Check File File file = new File(identifyQueueErrorFileName); if (file.exists() == false) { file.createNewFile(); } fos = new FileOutputStream(file); // Overwrite if (identifyDataQueueError.size() > 0) { ObjectOutputStream oosWriter = new ObjectOutputStream(fos); for (IdentifyData tmpIdentifiedData : identifyDataQueueError) { oosWriter.writeObject(tmpIdentifiedData); } oosWriter.flush(); oosWriter.close(); } fos.close(); log.debug("updateIdentifyErrorQueueFile-end"); // write text file writeTextFile(toHTMLForm()); return true; } catch (IOException e) { log.warn(e); } finally { if (fos != null) { try { fos.close(); } catch (Exception e) { log.debug(e); } } } return false; }
From source file:com.gdc.nms.web.mibquery.wizard.ciscavate.cjwizard.FlatWizardSettings.java
/** * Serialize the current instance of {@link FlatWizardSettings} to the given * filename./* w w w . jav a 2s.c o m*/ * * @param filename * The filename. */ public void serialize(String filename) { ObjectOutputStream out = null; FileOutputStream fout = null; try { fout = new FileOutputStream(filename); out = new ObjectOutputStream(fout); out.writeObject(this); } catch (IOException ioe) { log.error("Error writing settings", ioe); } finally { if (null != out) { try { out.close(); } catch (IOException ioe) { log.error("Error closing output stream", ioe); } } if (null != fout) { try { fout.close(); } catch (IOException ioe) { log.error("Error closing file", ioe); } } } }
From source file:com.centurylink.mdw.common.translator.impl.JavaObjectTranslator.java
public String realToString(Object object) throws TranslationException { if (!(object instanceof Serializable)) throw new TranslationException("Object must implement java.io.Serializable: " + object.getClass()); ObjectOutputStream oos = null; try {/*w ww .j av a 2s .c o m*/ ByteArrayOutputStream baos = new ByteArrayOutputStream(); oos = new ObjectOutputStream(baos); oos.writeObject(object); return encodeBase64(baos.toByteArray()); } catch (IOException ex) { throw new TranslationException(ex.getMessage(), ex); } finally { if (oos != null) { try { oos.close(); } catch (IOException ex) { } } } }
From source file:com.lillicoder.newsblurry.net.PreferenceCookieStore.java
/** * Encodes the given {@link SerializableCookie} as a base-64 encoded string. * This string is what will be persisted to preferences. * @param cookie {@link SerializableCookie} to encode. * @return Encoded base-64 string for the given cookie, * <code>null</code> if we failed to serialize the given cookie. */// w w w. j a v a 2s .c o m private String encodeCookie(Cookie cookie) { Assert.assertTrue(cookie != null); ByteArrayOutputStream out = new ByteArrayOutputStream(); try { ObjectOutputStream outStream = new ObjectOutputStream(out); SerializableCookie wrappedCookie = new SerializableCookie(cookie); outStream.writeObject(wrappedCookie); outStream.close(); } catch (IOException e) { Log.w(TAG, WARNING_FAILED_TO_WRITE_COOKIE_TO_STREAM); return null; } try { out.close(); } catch (IOException e) { Log.w(TAG, WARNING_FAILED_TO_CLOSE_ARRAY_OUTPUT_STREAM, e); } return Base64.encodeToString(out.toByteArray(), Base64.DEFAULT); }
From source file:com.microsoft.azure.management.datalake.store.uploader.UploadMetadata.java
/** * Saves the given metadata to its canonical location. This method is thread-safe. * * @throws IOException Thrown if the file cannot be saved due to accessibility or there is an error saving the stream to disk. * @throws InvalidMetadataException Thrown if the metadata is invalid. *//*ww w . j a va2 s . c o m*/ public void save() throws IOException, InvalidMetadataException { if (this.metadataFilePath == null || StringUtils.isEmpty(this.metadataFilePath)) { throw new InvalidObjectException( "Null or empty metadataFilePath. Cannot save metadata until this property is set."); } //quick check to ensure that the metadata we constructed is sane this.validateConsistency(); synchronized (saveSync) { File curMetadata = new File(this.metadataFilePath); if (curMetadata.exists()) { curMetadata.delete(); } // always create the full path to the file, since this will not throw if it already exists. curMetadata.getParentFile().mkdirs(); curMetadata.createNewFile(); try { FileOutputStream fileOut = new FileOutputStream(this.metadataFilePath); ObjectOutputStream out = new ObjectOutputStream(fileOut); out.writeObject(this); out.close(); fileOut.close(); } catch (Exception ex) { throw new InvalidMetadataException("Unable to parse metadata object and write it to a file", ex); } } }
From source file:org.activiti.rest.service.api.runtime.ProcessInstanceVariablesCollectionResourceTest.java
/** * Test creating a single process variable using a binary stream containing a serializable. POST runtime/process-instances/{processInstanceId}/variables *///from w w w. j a v a 2s . c om @Deployment(resources = { "org/activiti/rest/service/api/runtime/ProcessInstanceVariablesCollectionResourceTest.testProcess.bpmn20.xml" }) public void testCreateSingleSerializableProcessVariable() throws Exception { ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess"); TestSerializableVariable serializable = new TestSerializableVariable(); serializable.setSomeField("some value"); // Serialize object to readable stream for representation ByteArrayOutputStream buffer = new ByteArrayOutputStream(); ObjectOutputStream output = new ObjectOutputStream(buffer); output.writeObject(serializable); output.close(); InputStream binaryContent = new ByteArrayInputStream(buffer.toByteArray()); // Add name, type and scope Map<String, String> additionalFields = new HashMap<String, String>(); additionalFields.put("name", "serializableVariable"); additionalFields.put("type", "serializable"); // Upload a valid BPMN-file using multipart-data HttpPost httpPost = new HttpPost(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl( RestUrls.URL_PROCESS_INSTANCE_VARIABLE_COLLECTION, processInstance.getId())); httpPost.setEntity(HttpMultipartHelper.getMultiPartEntity("value", "application/x-java-serialized-object", binaryContent, additionalFields)); CloseableHttpResponse response = executeBinaryRequest(httpPost, HttpStatus.SC_CREATED); JsonNode responseNode = objectMapper.readTree(response.getEntity().getContent()); closeResponse(response); assertNotNull(responseNode); assertEquals("serializableVariable", responseNode.get("name").asText()); assertTrue(responseNode.get("value").isNull()); assertEquals("local", responseNode.get("scope").asText()); assertEquals("serializable", responseNode.get("type").asText()); assertFalse(responseNode.get("valueUrl").isNull()); assertTrue(responseNode.get("valueUrl").asText().endsWith(RestUrls.createRelativeResourceUrl( RestUrls.URL_PROCESS_INSTANCE_VARIABLE_DATA, processInstance.getId(), "serializableVariable"))); // Check actual value of variable in engine Object variableValue = runtimeService.getVariableLocal(processInstance.getId(), "serializableVariable"); assertNotNull(variableValue); assertTrue(variableValue instanceof TestSerializableVariable); assertEquals("some value", ((TestSerializableVariable) variableValue).getSomeField()); }
From source file:org.flowable.rest.service.api.runtime.ProcessInstanceVariablesCollectionResourceTest.java
/** * Test creating a single process variable using a binary stream containing a serializable. POST runtime/process-instances/{processInstanceId}/variables */// w w w .j av a 2 s. c o m @Deployment(resources = { "org/flowable/rest/service/api/runtime/ProcessInstanceVariablesCollectionResourceTest.testProcess.bpmn20.xml" }) public void testCreateSingleSerializableProcessVariable() throws Exception { ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess"); TestSerializableVariable serializable = new TestSerializableVariable(); serializable.setSomeField("some value"); // Serialize object to readable stream for representation ByteArrayOutputStream buffer = new ByteArrayOutputStream(); ObjectOutputStream output = new ObjectOutputStream(buffer); output.writeObject(serializable); output.close(); InputStream binaryContent = new ByteArrayInputStream(buffer.toByteArray()); // Add name, type and scope Map<String, String> additionalFields = new HashMap<String, String>(); additionalFields.put("name", "serializableVariable"); additionalFields.put("type", "serializable"); // Upload a valid BPMN-file using multipart-data HttpPost httpPost = new HttpPost(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl( RestUrls.URL_PROCESS_INSTANCE_VARIABLE_COLLECTION, processInstance.getId())); httpPost.setEntity(HttpMultipartHelper.getMultiPartEntity("value", "application/x-java-serialized-object", binaryContent, additionalFields)); CloseableHttpResponse response = executeBinaryRequest(httpPost, HttpStatus.SC_CREATED); JsonNode responseNode = objectMapper.readTree(response.getEntity().getContent()); closeResponse(response); assertNotNull(responseNode); assertEquals("serializableVariable", responseNode.get("name").asText()); assertTrue(responseNode.get("value").isNull()); assertEquals("local", responseNode.get("scope").asText()); assertEquals("serializable", responseNode.get("type").asText()); assertFalse(responseNode.get("valueUrl").isNull()); assertTrue(responseNode.get("valueUrl").asText().endsWith(RestUrls.createRelativeResourceUrl( RestUrls.URL_PROCESS_INSTANCE_VARIABLE_DATA, processInstance.getId(), "serializableVariable"))); // Check actual value of variable in engine Object variableValue = runtimeService.getVariableLocal(processInstance.getId(), "serializableVariable"); assertNotNull(variableValue); assertTrue(variableValue instanceof TestSerializableVariable); assertEquals("some value", ((TestSerializableVariable) variableValue).getSomeField()); }
From source file:de.hero.vertretungsplan.HtmlWork.java
public void extractTable(StringBuffer strHtml) throws IOException { SharedPreferences.Editor editor = mySharedPreferences.edit(); ArrayList<HashMap<String, String>> lstEintraege = new ArrayList<HashMap<String, String>>(); HashMap<String, String> hmEintrag = new HashMap<String, String>(); int intIndex = strHtml.indexOf("<table"); strHtml.delete(0, intIndex - 1);//from w w w. jav a 2s .com intIndex = strHtml.indexOf("</table"); strHtml.delete(intIndex, strHtml.length() - 1); DateFormat dfm = new SimpleDateFormat("dd.MM.yyyy"); DateFormat dfm2 = new SimpleDateFormat("dd.MM.yy"); Date dat = new Date(); try { dat = dfm.parse(strHtml.substring(strHtml.indexOf(":") + 2)); } catch (ParseException e) { // TODO Auto-generated catch block e.printStackTrace(); } // int date = dat.getDate(); // int month = dat.getMonth() + 1; //String strAktualisierungsText = ((date < 10) ? "0" + date : date) + "." + ((month < 10) ? "0" + month : month) + "." + (dat.getYear() + 1900) + " - " + strHtml.substring(strHtml.indexOf("<td>") + 4,strHtml.indexOf("</td")); String datumVertretungsplan = dfm2.format(dat); String aOderBWoche = strHtml.substring(strHtml.indexOf("<td>") + 4, strHtml.indexOf("</td")); Log.d("HtmlWork", "strAktualisierungsText " + datumVertretungsplan); editor.putString(context.getString(R.string.datumVertretungsplan), datumVertretungsplan); editor.putString("aOderBWoche", aOderBWoche); editor.commit(); intIndex = strHtml.indexOf("<tr>"); int intIndex2 = strHtml.indexOf("</tr>"); strHtml.delete(0, intIndex2 + 4); intIndex = strHtml.indexOf("<tr>"); intIndex2 = strHtml.indexOf("</tr>"); strHtml.delete(0, intIndex2 + 4); intIndex2 = strHtml.indexOf("</tr>"); strHtml.delete(0, intIndex2 + 4); intIndex = strHtml.indexOf("<tr>"); intIndex2 = strHtml.indexOf("</tr>"); while (intIndex != -1) { StringBuffer strZeile = new StringBuffer(strHtml.substring(intIndex + 4, intIndex2)); int intIndex4 = strZeile.indexOf("</t"); strZeile.delete(0, intIndex4 + 5); int intIndex3 = strZeile.indexOf("<t"); intIndex4 = strZeile.indexOf("</t"); String stunde = strZeile.substring(intIndex3 + 4, intIndex4); hmEintrag.put("stunde", stunde + ((stunde.endsWith(".")) ? " Stunde" : ". Stunde")); strZeile.delete(intIndex3, intIndex4 + 4); intIndex3 = strZeile.indexOf("<t"); intIndex4 = strZeile.indexOf("</t"); hmEintrag.put("fach1", strZeile.substring(intIndex3 + 4, intIndex4)); strZeile.delete(intIndex3, intIndex4 + 4); intIndex3 = strZeile.indexOf("<t"); intIndex4 = strZeile.indexOf("</t"); hmEintrag.put("vertreter", strZeile.substring(intIndex3 + 4, intIndex4)); /*strZeile.delete(intIndex3, intIndex4 + 4); intIndex3 = strZeile.indexOf("<t"); intIndex4 = strZeile.indexOf("</t"); hmEintrag.put("fach2", strZeile.substring(intIndex3 + 4, intIndex4));*/ strZeile.delete(intIndex3, intIndex4 + 4); intIndex3 = strZeile.indexOf("<t"); intIndex4 = strZeile.indexOf("</t"); hmEintrag.put("klassen", strZeile.substring(intIndex3 + 4, intIndex4)); strZeile.delete(intIndex3, intIndex4 + 4); intIndex3 = strZeile.indexOf("<t"); intIndex4 = strZeile.indexOf("</t"); hmEintrag.put("raum", strZeile.substring(intIndex3 + 4, intIndex4)); strZeile.delete(intIndex3, intIndex4 + 4); intIndex3 = strZeile.indexOf("<t"); intIndex4 = strZeile.indexOf("</t"); String strTemp = strZeile.substring(intIndex3 + 4, intIndex4); strZeile.delete(intIndex3, intIndex4 + 4); intIndex3 = strZeile.indexOf("<t"); intIndex4 = strZeile.indexOf("</t"); hmEintrag.put("text", strTemp + " " + strZeile.substring(intIndex3 + 4, intIndex4)); lstEintraege.add(hmEintrag); hmEintrag = new HashMap<String, String>(); strHtml.delete(0, intIndex2 + 2); intIndex = strHtml.indexOf("<tr>"); intIndex2 = strHtml.indexOf("</tr>"); } FileOutputStream fos = context.openFileOutput(context.getString(R.string.filename), Context.MODE_PRIVATE); ObjectOutputStream oos = new ObjectOutputStream(fos); int oldHash = mySharedPreferences.getInt(context.getString(R.string.v_plan_hash_value), 0); oos.writeObject(lstEintraege); oos.close(); fos.close(); int newHash = lstEintraege.hashCode(); editor.putInt(context.getString(R.string.v_plan_hash_value), newHash); editor.commit(); Log.d("HtmlWork", "oldHash: " + oldHash + "; newHash: " + newHash); if (oldHash != newHash) { onDataChange(); } }
From source file:org.webpki.mobile.android.proxy.BaseProxyActivity.java
public void closeProxy() { if (protocol_log != null) { try {/*from www.j a v a 2 s. c o m*/ ObjectOutputStream oos = new ObjectOutputStream( openFileOutput(getProtocolName(), Context.MODE_PRIVATE)); oos.writeObject(protocol_log); oos.close(); Log.i(getProtocolName(), "Wrote protocol log"); } catch (Exception e) { Log.e(getProtocolName(), "Couldn't write protocol log"); } } SKSStore.serializeSKS(getProtocolName(), this); finish(); }