public static void writeObject(Context context, String key, Object object) throws IOException { FileOutputStream fos = context.openFileOutput(key, Context.MODE_PRIVATE); ObjectOutputStream oos = new ObjectOutputStream(fos); oos.writeObject(object); oos.close(); fos.close(); }
static void serTest(Map s, int size) throws Exception { if (!(s instanceof Serializable)) return; System.out.print("Serialize : "); for (int i = 0; i < size; i++) { s.put(new Integer(i), Boolean.TRUE); } long startTime = System.currentTimeMillis(); FileOutputStream fs = new FileOutputStream("MapCheck.dat"); ObjectOutputStream out = new ObjectOutputStream(new BufferedOutputStream(fs)); out.writeObject(s); out.close(); FileInputStream is = new FileInputStream("MapCheck.dat"); ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(is)); Map m = (Map) in.readObject(); long endTime = System.currentTimeMillis(); long time = endTime - startTime; System.out.print(time + "ms"); if (s instanceof IdentityHashMap) return; reallyAssert(s.equals(m)); }
public void serialize(String fileName, Object object) throws IOException { File file = new File(Config.getResponesCacheDir(), EncryptUtil.MD5(fileName)); if (!file.exists()) { if (!file.getParentFile().exists()) file.mkdirs(); } else { file.delete(); } file.createNewFile(); ObjectOutputStream out = null; try { out = new ObjectOutputStream(new FileOutputStream(file)); out.writeObject(object); out.close(); } catch (FileNotFoundException e) { throw new RuntimeException("FileNotFoundException occurred. ", e); } catch (IOException e) { throw new RuntimeException("IOException occurred. ", e); } finally { if (out != null) { try { out.close(); } catch (IOException e) { throw new RuntimeException("IOException occurred. ", e); } } } }
@Override public void write(String path) throws IOException { File dir = FileUtils.getFile(path, "ensemble", getName()); if (!dir.isDirectory()) { dir.mkdirs(); } ObjectOutputStream oop = new ObjectOutputStream(new FileOutputStream(new File(dir, "similarityCoefficients"))); oop.writeObject(simlarityCoefficients); oop.flush(); oop.close(); oop = new ObjectOutputStream(new FileOutputStream(new File(dir, "mostSimilarCoefficients"))); oop.writeObject(mostSimilarCoefficients); oop.flush(); oop.close(); oop = new ObjectOutputStream(new FileOutputStream(new File(dir, "similarityInterpolator"))); oop.writeObject(similarityInterpolator); oop.flush(); oop.close(); oop = new ObjectOutputStream(new FileOutputStream(new File(dir, "mostSimilarInterpolator"))); oop.writeObject(mostSimilarInterpolator); oop.flush(); oop.close(); }
public boolean out(OutStoringpo opo) throws Exception { // TODO Auto-generated method stub FileInputStream fis = new FileInputStream("src/main/java/data/save/outstock.txt"); ObjectInputStream ois = new ObjectInputStream(fis); @SuppressWarnings("unchecked") List<OutStoringpo> list = (List<OutStoringpo>) ois.readObject(); ois.close(); list.add(opo); FileOutputStream fos = new FileOutputStream("src/main/java/data/save/outstock.txt"); ObjectOutputStream oos = new ObjectOutputStream(fos); oos.writeObject(list); oos.close(); FileInputStream fis1 = new FileInputStream("src/main/java/data/save/instock.txt"); ObjectInputStream ois1 = new ObjectInputStream(fis1); @SuppressWarnings("unchecked") List<InStoringpo> list1 = (List<InStoringpo>) ois1.readObject(); for (int i = 0; i < list1.size(); i++) { if (((list1.get(i)).getID()).equals(opo.getID())) { list1.remove(i); i--; // System.out.println("Delete "); } } ois1.close(); FileOutputStream fos1 = new FileOutputStream("src/main/java/data/save/instock.txt"); ObjectOutputStream oos1 = new ObjectOutputStream(fos1); oos1.writeObject(list1); oos1.close(); return true; }
// returns a deep copy of an object public static Object deepCopy(Object oldObj) { ObjectOutputStream oos = null; ObjectInputStream ois = null; try { ByteArrayOutputStream bos = new ByteArrayOutputStream(); // A oos = new ObjectOutputStream(bos); // B // serialize and pass the object oos.writeObject(oldObj); // C oos.flush(); // D ByteArrayInputStream bin = new ByteArrayInputStream(bos.toByteArray()); // E ois = new ObjectInputStream(bin); // F // return the new object Object object = ois.readObject(); oos.close(); ois.close(); return object; // G } catch (Exception e) { return null; } finally { try { if (oos != null) oos.close(); if (ois != null) ois.close(); } catch (IOException e) { e.printStackTrace(); } } }
public void saveToFile() { Log.i(LOG_TAG, "Saving to file..."); try { FileOutputStream fos = openFileOutput("cs_pinger_icmp", Context.MODE_PRIVATE); ObjectOutputStream os = new ObjectOutputStream(fos); os.writeObject(icmpPingSettings); os.close(); fos.close(); fos = openFileOutput("cs_pinger_http", Context.MODE_PRIVATE); os = new ObjectOutputStream(fos); os.writeObject(httpPingSettings); os.close(); fos.close(); fos = openFileOutput("cs_pinger_https", Context.MODE_PRIVATE); os = new ObjectOutputStream(fos); os.writeObject(httpsPingSettings); os.close(); fos.close(); } catch (Exception e) { StringWriter errors = new StringWriter(); e.printStackTrace(new PrintWriter(errors)); Log.e(LOG_TAG, "File write error!\n" + errors.toString()); } }
/* * check if there is anything on the queue, if so send it over the socket to the consumer(non-Javadoc) * @see java.lang.Runnable#run() */ @Override public void run() { try { while (true) { IDataObject instance = queue.take(); out.writeObject( instance); // since it is a blocking queue the method will block until there is an item // in the queue } } catch (Exception e) { // cannot write output anyhow, orderly shutdown the stream // close the stream and exit try { if (out != null) out.close(); this.queue.clear(); this.socket.close(); } catch (IOException e1) { // nothing to do here } } finally { try { if (out != null) out.close(); this.queue.clear(); this.socket.close(); } catch (Exception e) { } } }
/** * java.io.ObjectOutputStream#writeInt(int) * java.io.ObjectOutputStream#writeObject(java.lang.Object) * java.io.ObjectOutputStream#writeUTF(java.lang.String) */ public void testMixPrimitivesAndObjects() throws Exception { int i = 7; String s1 = "string 1"; String s2 = "string 2"; byte[] bytes = {1, 2, 3}; try { oos = new ObjectOutputStream(bao = new ByteArrayOutputStream()); oos.writeInt(i); oos.writeObject(s1); oos.writeUTF(s2); oos.writeObject(bytes); oos.close(); ois = new ObjectInputStream(new ByteArrayInputStream(bao.toByteArray())); int j = ois.readInt(); assertTrue("Wrong int :" + j, i == j); String l1 = (String) ois.readObject(); assertTrue("Wrong obj String :" + l1, s1.equals(l1)); String l2 = ois.readUTF(); assertTrue("Wrong UTF String :" + l2, s2.equals(l2)); byte[] bytes2 = (byte[]) ois.readObject(); assertTrue("Wrong byte[]", Arrays.equals(bytes, bytes2)); } finally { try { if (oos != null) oos.close(); if (ois != null) ois.close(); } catch (IOException e) { } } }
/** * Checks if the score is high enough to get to the high scores list, adds the name and score and * organizes the list. If HighScores.dat is not found, the method generates a blank one. * * @param name The nickname of the person getting to the list. * @param score The score gained. */ public static void addHighScore(String name, int score) { // If we don't yet have a high scores table, we create a blank (and let the user know about it) if (!new File("HighScores.dat").exists()) { // This object matrix actually stores the information of the high scores list Object[][] highScores = new Object[10][3]; // We fill the high scores list with blank entries: #. " " 0 for (int i = 0; i < highScores.length; i++) { highScores[i][0] = (i + 1) + "."; highScores[i][1] = " "; highScores[i][2] = 0; } // This actually writes and makes the high scores file try { ObjectOutputStream o = new ObjectOutputStream(new FileOutputStream("HighScores.dat")); o.writeObject(highScores); o.close(); } catch (IOException e) { e.printStackTrace(); } } // We read the file to check if we have a new high score, and then rewrite the highscore // This is done even if we didn't previously have a high scores list try { ObjectInputStream o = new ObjectInputStream(new FileInputStream("HighScores.dat")); // The object matrix does the same as the previous one. // Here we just take what we read from the HighScores.dat to the Object[][] HighScores. Object[][] highScores = (Object[][]) o.readObject(); // Then we start searching for an entry for which the score is smaller than the achieved score for (int i = 0; i < highScores.length; i++) { if ((Integer) highScores[i][2] < score) { // Once found we start to move entries, which are below the score we had, downwards. // I.e. 10. becomes whatever 9. was. 9. becomes what 8. was etc... for (int j = 9; j > i; j--) { highScores[j][0] = (j + 1) + "."; highScores[j][1] = highScores[j - 1][1]; highScores[j][2] = highScores[j - 1][2]; } // Then we write the score and the name we just got to the correct place highScores[i][0] = (i + 1) + "."; highScores[i][1] = name; highScores[i][2] = score; // And break the loop. /*Maybe this could be avoided somehow? I haven't been able to come up with an easy way yet.*/ break; } } try { // And finally we overwrite the HighScores.dat with our highScores object matrix ObjectOutputStream n = new ObjectOutputStream(new FileOutputStream("HighScores.dat")); n.writeObject(highScores); n.close(); } catch (IOException e) { e.printStackTrace(); } } catch (ClassNotFoundException | IOException e) { e.printStackTrace(); } }
/** * Serializes and Base64 encodes the provided <code>state</code> to the provided <code>writer * </code>/ * * @param state view state * @param writer the <code>Writer</code> to write the content to * @throws IOException if an error occurs writing the state to the client */ protected void doWriteState(Object state, Writer writer) throws IOException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); OutputStream base = null; if (compressViewState) { base = new GZIPOutputStream(baos, csBuffSize); } else { base = baos; } ObjectOutputStream oos = null; try { oos = serialProvider.createObjectOutputStream(new BufferedOutputStream(base)); if (stateTimeoutEnabled) { oos.writeLong(System.currentTimeMillis()); } Object[] stateToWrite = (Object[]) state; //noinspection NonSerializableObjectPassedToObjectStream oos.writeObject(stateToWrite[0]); //noinspection NonSerializableObjectPassedToObjectStream oos.writeObject(stateToWrite[1]); oos.flush(); oos.close(); oos = null; // get bytes for encrypting byte[] bytes = baos.toByteArray(); if (guard != null) { // this will MAC bytes = guard.encrypt(bytes); } // Base 64 encode Base64OutputStreamWriter bos = new Base64OutputStreamWriter(bytes.length, writer); bos.write(bytes, 0, bytes.length); bos.finish(); if (LOGGER.isLoggable(Level.FINE)) { LOGGER.log( Level.FINE, "Client State: total number of characters written: {0}", bos.getTotalCharsWritten()); } } finally { if (oos != null) { try { oos.close(); } catch (IOException ioe) { // ignore } } } }
/** {@inheritDoc} */ public synchronized boolean commit(GRootGroup currentState, int referenceVersion) throws RemoteException, VersionException, RepositoryException { // check that referenceVersion is a valid version if ((referenceVersion < 0) || (referenceVersion > currentVersion)) { throw new VersionException( "The reference version supplied at commit (" + referenceVersion + ") was either negative or greater than the current version on the repository."); } // tell the client that an update is needed before he can commit if (referenceVersion != currentVersion) { return false; } try { // the delta between version(n) and version(n+1) is stored in the file called v<n+1> File vFile = new File(repositoryPath + "v" + (new Integer(currentVersion + 1)).toString()); ObjectOutputStream vfWriter = new ObjectOutputStream(new BufferedOutputStream(new FileOutputStream(vFile))); Datetime timestamp = new Datetime(); vfWriter.writeObject(timestamp); vfWriter.writeObject(currentState); vfWriter.close(); timestamps.add(timestamp); } catch (IOException e) { e.printStackTrace(); System.out.println("Failed to write operations to file during commit."); throw new RepositoryException( "The repository failed to commit your version. Please notify " + "the administrator."); } // if we got this far, it means all went ok => we can increment currentVersion File versionFile = new File(repositoryPath + "version"); System.out.println("Trying to update version file after a successful commit."); try { ObjectOutputStream vfWriter = new ObjectOutputStream(new FileOutputStream(versionFile)); vfWriter.writeInt(currentVersion + 1); vfWriter.close(); } catch (IOException e) { e.printStackTrace(); System.out.println("Failed to update version file."); throw new RepositoryException( "The repository failed to commit your version. Please notify " + "the administrator."); } System.out.println("Version file successfully updated."); currentVersion++; return true; }
@SuppressWarnings("unchecked") public void recover(String mode) { if (backUp.exists()) { try { FIS = new FileInputStream(backUp); OIS = new ObjectInputStream(FIS); records = (ArrayList<Record>) OIS.readObject(); OIS.close(); FIS.close(); boolean flag = false; for (int i = 0; i < records.size() - 1; i++) { for (int j = i + 1; j < records.size(); j++) { if (records.get(i).getRecordInfo().equals(records.get(j).getRecordInfo())) { records.remove(j); flag = true; } } } if (flag) { FOS = new FileOutputStream(backUp); OOS = new ObjectOutputStream(FOS); OOS.writeObject(records); OOS.close(); FOS.close(); } for (Record R : records) { System.out.println(R.getRecordInfo()); } System.err.println("Content of this copy: " + records.size() + " records."); if (mode.equals("recover")) { FOS = new FileOutputStream(F); OOS = new ObjectOutputStream(FOS); OOS.writeObject(records); OOS.close(); FOS.close(); System.err.println("Records has been recovered.\nTotal: " + records.size()); } } catch (Exception e) { e.printStackTrace(); } } else { System.err.println("No backups are available."); } }
/* * (non-Javadoc) <p>Title: writeObject</p> <p>Description: 将缓存写入本地</p> * * * * @see * com.ucap.cloud.business.formserver.data.outin.IDataInputOutput#writeObject * (java.lang.Object) */ public void writeObject() { // 1.得到当前的用户名 // 2.根据用户名得到IdfUserModel对象 // 3.将IdfUserModel对象写入缓存 // 4.序列化发布的匿名表单 ObjectOutputStream out; // add by sunjq try { AllNiMingIdfModel allnm = (AllNiMingIdfModel) this.ccache.getVluae("allNiMingIdf"); // 依据idfname获取匿名表单 File file = new File(this.getUrl() + this.path + "niming.txt"); if (!file.getParentFile().exists()) { file.getParentFile().mkdirs(); } out = new ObjectOutputStream(new FileOutputStream(file)); // 写入的是IdfUserModel对象 out.writeObject(allnm); // 清空流 out.flush(); // 关闭流 out.close(); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } // end add Set<String> userMap = alreadyuser.keySet(); for (String userid : userMap) { IdfUserModel user = (IdfUserModel) this.ccache.getVluae(userid); if (null == user) { return; } try { File file = new File(this.getUrl() + this.path + userid + "/" + "useridf/" + (userid + ".txt")); if (!file.getParentFile().exists()) { file.getParentFile().mkdirs(); } out = new ObjectOutputStream(new FileOutputStream(file)); // 写入的是IdfUserModel对象 out.writeObject(user); // 清空流 out.flush(); // 关闭流 out.close(); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }
public static void main(String[] args) throws IOException, ClassNotFoundException { FileOutputStream fout = null; ObjectOutputStream out = null; FileInputStream fin = null; ObjectInputStream in = null; SerializeClass obj = null; SerializeClass s = null; // Serialization for is-a relationship Starts obj = new SerializeClass(1, "Dushyant"); // Serialization fout = new FileOutputStream("file.txt"); out = new ObjectOutputStream(fout); out.writeObject(obj); out.flush(); fout.close(); out.close(); // De-Serialization fin = new FileInputStream("file.txt"); in = new ObjectInputStream(fin); s = (SerializeClass) in.readObject(); System.out.println(s.getId() + " " + s.getName()); fin.close(); in.close(); // Serialization for is-a relationship Ends // Serialization for has-a relationship Starts obj = new SerializeClass(1, "Dushyant"); obj.setCityAndState(new CityState("Gurgaon", "Haryana")); fout = new FileOutputStream("file.txt"); out = new ObjectOutputStream(fout); out.writeUTF(obj.getName()); // 1 out.writeUTF(obj.getCityAndState().getCityName()); // 1 out.writeUTF(obj.getCityAndState().getStateName()); // 1 out.flush(); out.close(); fin = new FileInputStream("file.txt"); in = new ObjectInputStream(fin); s = new SerializeClass(); s.setCityAndState(new CityState()); s.setName(in.readUTF()); // 2 s.getCityAndState().setCityName(in.readUTF()); // 2 s.getCityAndState().setStateName(in.readUTF()); // 2 System.out.println(s); // Serialization for has-a relationship Ends }
// saves the current configuration (breakpoints, window sizes and positions...) private void saveConfig() { try { ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream(idxName + ".config")); Breakpoints.save(out); Properties.save(out); out.close(); } catch (IOException exc) { consoleFrame.echoInfo("Could not save settings: " + exc); } }
@SuppressWarnings({"unchecked", "ResultOfMethodCallIgnored"}) public void newRecord(String code, String name, String age, String city, String oldest) { try { if (!backUp.exists()) { new File(backUp.getParent()).mkdirs(); } if (F.exists()) { FIS = new FileInputStream(F); OIS = new ObjectInputStream(FIS); records = (ArrayList<Record>) OIS.readObject(); OIS.close(); FIS.close(); } FOS = new FileOutputStream(F); OOS = new ObjectOutputStream(FOS); records.add(new Record(code, name, age, city, oldest)); OOS.writeObject(records); OOS.close(); FOS.close(); // SAVING BACKUP... if (backUp.exists()) { FIS = new FileInputStream(backUp); OIS = new ObjectInputStream(FIS); records = (ArrayList<Record>) OIS.readObject(); OIS.close(); FIS.close(); } FOS = new FileOutputStream(backUp); OOS = new ObjectOutputStream(FOS); records.add(new Record(code, name, age, city, oldest)); OOS.writeObject(records); OOS.close(); FOS.close(); // BACKUP SAVED! System.err.println("Successfully saved on: " + F.getParent()); } catch (Exception e) { e.printStackTrace(); } }
public void closeFile() { try { if (output1 != null) { output1.close(); } if (output2 != null) { output2.close(); } } catch (IOException exc) { JOptionPane.showMessageDialog(null, "Error closing file"); } }
public void insert(FIncomePO po) throws RemoteException, IOException { ObjectOutputStream oos = null; try { FileOutputStream fs = new FileOutputStream(file, true); oos = new ObjectOutputStream(fs); oos.writeObject(po); oos.close(); } catch (Exception e) { e.printStackTrace(); } finally { oos.close(); } }
public static void main(String[] argv) { MyPojoObj obj1 = new MyPojoObj("cat", 1); MyPojoObj obj2 = new MyPojoObj("dog", 2); MyPojoObj des_obj1; MyPojoObj des_obj2; System.out.println("Before serialization"); System.out.println(obj1.toString()); System.out.println(obj2.toString()); try { FileOutputStream fileOut = new FileOutputStream("./SerializedObjects/obj1.ser"); ObjectOutputStream out = new ObjectOutputStream(fileOut); out.writeObject(obj1); out.close(); fileOut.close(); fileOut = new FileOutputStream("./SerializedObjects/obj2.ser"); out = new ObjectOutputStream(fileOut); out.writeObject(obj2); out.close(); fileOut.close(); System.out.printf("Serialized data is saved in ./SerializedObjectsr"); } catch (IOException i) { i.printStackTrace(); } // Desrialize try { FileInputStream fileIn = new FileInputStream("./SerializedObjects/obj1.ser"); ObjectInputStream in = new ObjectInputStream(fileIn); des_obj1 = (MyPojoObj) in.readObject(); in.close(); fileIn.close(); fileIn = new FileInputStream("./SerializedObjects/obj2.ser"); in = new ObjectInputStream(fileIn); des_obj2 = (MyPojoObj) in.readObject(); System.out.println("Desrialized data operation ends with success"); in.close(); fileIn.close(); } catch (IOException i) { i.printStackTrace(); return; } catch (ClassNotFoundException c) { System.out.println("Employee class not found"); c.printStackTrace(); return; } System.out.println("After serialization"); System.out.println(des_obj1.toString()); System.out.println(des_obj2.toString()); }
private byte[] serialise(Object value, VersionMapper versionMapper) throws IOException { ByteArrayOutputStream bout = new ByteArrayOutputStream(); ObjectOutputStream oout = new LenientObjectOutputStream(bout, versionMapper); oout.writeObject(value); oout.close(); return bout.toByteArray(); }
void serialize(File f) throws IOException { FileOutputStream fos = new FileOutputStream(f); ObjectOutputStream oos = new ObjectOutputStream(fos); oos.writeObject(this); oos.close(); fos.close(); }
public void run() { try { done = false; final String PATH = "/home/lvuser/AutoRoutineData.ser"; File file = new File(PATH); if (!file.exists()) { file.createNewFile(); } else { file.delete(); file.createNewFile(); } FileOutputStream fileOut = new FileOutputStream(file); ObjectOutputStream out = new ObjectOutputStream(fileOut); out.writeObject(data); out.close(); fileOut.close(); Repository.Log.info("Serialized auto routine data: " + data.toString()); done = true; } catch (Exception ex) { Repository.Logs.error("Failed to serialize auto routine data", ex); done = true; } }
/** 克隆Serializable */ @SuppressWarnings("unchecked") public static <T> T cloneSerializable(T src) throws RuntimeException { ByteArrayOutputStream memoryBuffer = new ByteArrayOutputStream(); ObjectOutputStream out = null; ObjectInputStream in = null; T dest = null; try { out = new ObjectOutputStream(memoryBuffer); out.writeObject(src); out.flush(); in = new ObjectInputStream(new ByteArrayInputStream(memoryBuffer.toByteArray())); dest = (T) in.readObject(); } catch (Exception e) { throw new RuntimeException(e); } finally { if (out != null) { try { out.close(); out = null; } catch (Exception e) { } } if (in != null) { try { in.close(); in = null; } catch (Exception e) { } } } return dest; }
public void run() { try { ObjectInputStream oin = new ObjectInputStream(client.getInputStream()); test = new testMessage((testMessage) oin.readObject()); serverMain.textPane2.setText( serverMain.textPane2.getText() + (new Date()) + ":" + test.qq + "开始验证有无密保问题......\n"); ObjectOutputStream oout = new ObjectOutputStream(client.getOutputStream()); String returnQuestion = "select * from safeQuestion_" + test.qq + ";"; ResultSet res_return = state2.executeQuery(returnQuestion); if (res_return.next()) { changed = 2; String text1 = res_return.getString("question"); res_return.next(); String text2 = res_return.getString("question"); res_return.next(); String text3 = res_return.getString("question"); oout.writeObject(new safeQuestionOrAnswer(null, text1, text2, text3)); oout.close(); serverMain.textPane2.setText(serverMain.textPane2.getText() + test.qq + "有无密保问题!\n"); } else { oout.writeObject(null); changed = 1; serverMain.textPane2.setText(serverMain.textPane2.getText() + test.qq + "无密保问题!\n"); } client.close(); state2.close(); } catch (Exception e) { e.printStackTrace(); } }
/** * Serialize an object to a byte array. (code by CB) * * @param object object to serialize * @return byte array that represents the object * @throws Exception */ public static byte[] toByte(Object object) throws Exception { ByteArrayOutputStream os = new ByteArrayOutputStream(); ObjectOutputStream oos = new ObjectOutputStream((OutputStream) os); oos.writeObject(object); oos.close(); return os.toByteArray(); }
/** @since 3.0 */ @Override public void setTimestampTransform(final ITmfTimestampTransform tt) { fTsTransform = tt; /* Save the timestamp transform to a file */ File sync_file = getSyncFormulaFile(); if (sync_file != null) { if (sync_file.exists()) { sync_file.delete(); } FileOutputStream fos; ObjectOutputStream oos; /* Save the header of the file */ try { fos = new FileOutputStream(sync_file, false); oos = new ObjectOutputStream(fos); oos.writeObject(fTsTransform); oos.close(); fos.close(); } catch (IOException e1) { Activator.logError("Error writing timestamp transform for trace", e1); // $NON-NLS-1$ } } }
private void saveSettings() { if (settings == null) return; File fSettings = new File(getDataFolder(), "settings.npr"); try { getDataFolder().mkdirs(); } catch (Exception e) { return; } FileOutputStream fOut = null; ObjectOutputStream out = null; try { fOut = new FileOutputStream(fSettings); out = new ObjectOutputStream(fOut); out.writeObject(settings); } catch (Exception e) { } finally { try { if (fOut != null) fOut.close(); if (out != null) out.close(); } catch (Exception e) { } } }
public static void main(String[] args) { ZStudent[] zstudents = { new ZStudent(50, "Ngu", "M", "Monday", 50.0F), new ZStudent(100, "Gray", "G", "Tuesday", 60.0F), new ZStudent(150, "Green", "G", "Wednesday", 70.0F), new ZStudent(200, "Purple", "P", "Thursday", 80.0F), new ZStudent(300, "Red", "R", "Friday", 90.0F) }; try { FileOutputStream fos = new FileOutputStream("zStudentFile.ser"); ObjectOutputStream oos = new ObjectOutputStream(fos); // to write out student records to a file // for (int i = 0; i < 5; i++) { // oos.writeObject(zstudents[i]);// to write 1 obj at a time oos.writeObject(zstudents); // } oos.close(); } catch (IOException e) { System.out.println("Error:" + e); } }
public void run() { try { in = new ObjectInputStream(new BufferedInputStream(socket.getInputStream())); while (!Thread.interrupted()) { String value = in.readUTF(); if (ConfigSettings.instance().isActivateStats()) { StatsCommunication.instance().sent(value.getBytes().length); } if (ConfigSettings.instance().isDumpMessages()) { System.out.println("Received: " + value); } Message message = (Message) MessageSerializer.readMessage(value); consumer.receive(message); } } catch (Throwable t) { t.printStackTrace(); } finally { consumer = null; try { out.close(); } catch (IOException ex) { ex.printStackTrace(); } } }