public void xx() { try { PublicKey pubKey = key; // FileInputStream sigfis = new FileInputStream(args[1]); byte[] sigToVerify = (byte[]) objIn.readObject(); // sigfis.read(sigToVerify); // sigfis.close(); Signature sig = Signature.getInstance("SHA1withDSA", "SUN"); sig.initVerify(pubKey); FileInputStream datafis = (FileInputStream) objIn.readObject(); BufferedInputStream bufin = new BufferedInputStream(datafis); byte[] buffer = new byte[1024]; int len; while (bufin.available() != 0) { len = bufin.read(buffer); sig.update(buffer, 0, len); } ; bufin.close(); boolean verifies = sig.verify(sigToVerify); System.out.println("signature verifies: " + verifies); } catch (Exception e) { System.err.println("Caught exception " + e.toString()); } }
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 ArrayList<FIncomePO> findbyHall(String hall) throws RemoteException, IOException { ArrayList<FIncomePO> income = new ArrayList<FIncomePO>(); ObjectInputStream os = null; System.out.println("start find!"); try { FileInputStream fs = new FileInputStream(file); os = new ObjectInputStream(fs); FIncomePO po = (FIncomePO) os.readObject(); while (fs.available() > 0) { byte[] buf = new byte[4]; fs.read(buf); FIncomePO incomepo = (FIncomePO) os.readObject(); if (incomepo.getShop().equals(hall)) { income.add(incomepo); } } return income; } catch (Exception e) { return null; } finally { os.close(); } }
// Load a neural network from memory public NeuralNetwork loadGenome() { // Read from disk using FileInputStream FileInputStream f_in = null; try { f_in = new FileInputStream("./memory/mydriver.mem"); } catch (FileNotFoundException e) { e.printStackTrace(); } // Read object using ObjectInputStream ObjectInputStream obj_in = null; try { obj_in = new ObjectInputStream(f_in); } catch (IOException e) { e.printStackTrace(); } // Read an object try { return (NeuralNetwork) obj_in.readObject(); } catch (IOException e) { e.printStackTrace(); } catch (ClassNotFoundException e) { e.printStackTrace(); } return null; }
/** * A getter for the high scores list. Reads it directly from file and throws an error if the file * is not found (!working on this!). * * @return Object[][] where [i][0] is the rank (String), [i][1] is the name (String) and [i][2] is * the score (Integer). */ public static Object[][] getHighScore() { 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(); } } try { // Read and return the read object matrix ObjectInputStream o = new ObjectInputStream(new FileInputStream("HighScores.dat")); Object[][] highScores = (Object[][]) o.readObject(); o.close(); return highScores; } catch (IOException | ClassNotFoundException e) { e.printStackTrace(); } return null; }
/** * Read an object from a deserialization stream. * * @param s An object deserialization stream. * @throws ClassNotFoundException If the object's class read from the stream cannot be found. * @throws IOException If an error occurs reading from the stream. */ @SuppressWarnings("unchecked") private void readObject(ObjectInputStream s) throws ClassNotFoundException, IOException { s.defaultReadObject(); final T value = (T) s.readObject(); final List<Node<T>> children = (List<Node<T>>) s.readObject(); node = new Node<>(value, children); }
public static void main(String args[]) { ObjectInputStream in = null; try { in = new ObjectInputStream(new FileInputStream("output7.dat")); while (true) { Rectangle obj = (Rectangle) in.readObject(); System.out.println("넓이 : " + obj.width); System.out.println("높이 : " + obj.height); } } catch (FileNotFoundException fnfe) { System.out.println("파일이 존재하지 않습니다."); } catch (EOFException eofe) { // 파일로부터 더이상 읽을 객체가 없을때 발생하는 예외처리를 합니다. System.out.println("시마이."); } catch (IOException ioe) { System.out.println(ioe.getMessage()); } catch (ClassNotFoundException cnfe) { System.out.println("해당 클래스가 존재하지 않습니다."); } finally { try { in.close(); // 파일 종료 } catch (Exception e) { // close메소드가 발생하는 예외처리 } } }
/** * Clone a <code>Serializable</code> object; for use when a <code>clone()</code> method is not * available. * * @param obj object to clone * @return clone object * @throws RuntimeException */ public static Object cloneSerializable(Object obj) { Object ret = null; try { ByteArrayOutputStream baos = new ByteArrayOutputStream(StreamUtils.DEFAULT_BUFFER_SIZE); ObjectOutputStream oos = new ObjectOutputStream(baos); oos.writeObject(obj); oos.close(); ByteArrayInputStream bis = new ByteArrayInputStream(baos.toByteArray()); ObjectInputStream ois = new ObjectInputStream(bis); try { ret = ois.readObject(); } catch (ClassNotFoundException cnfe) { assert false; } ois.close(); } catch (IOException ioex) { throw new RuntimeException("Unable to clone object: " + obj); } return ret; }
/** * fill this VoxelSelection using the serialised VoxelSelection byte array * * @param byteArrayInputStream the bytearray containing the serialised VoxelSelection * @return true for success, false for failure (leaves selection untouched) */ public boolean readFromBytes(ByteArrayInputStream byteArrayInputStream) { try { DataInputStream inputStream = new DataInputStream(byteArrayInputStream); int newXsize = inputStream.readInt(); int newYsize = inputStream.readInt(); int newZsize = inputStream.readInt(); if (newXsize < 1 || newXsize > MAX_X_SIZE || newYsize < 1 || newYsize > MAX_Y_SIZE || newZsize < 1 || newZsize > MAX_Z_SIZE) { return false; } ObjectInputStream objectInputStream = new ObjectInputStream(inputStream); Object newVoxels = objectInputStream.readObject(); if (!(newVoxels instanceof BitSet)) return false; xSize = newXsize; ySize = newYsize; zSize = newZsize; voxels = (BitSet) newVoxels; } catch (ClassNotFoundException cnfe) { ErrorLog.defaultLog().debug("Exception while VoxelSelection.readFromDataArray: " + cnfe); return false; } catch (IOException ioe) { ErrorLog.defaultLog().debug("Exception while VoxelSelection.readFromDataArray: " + ioe); return false; } return true; }
public void testSerial() { assertTrue(_nbhm.isEmpty()); final String k1 = "k1"; final String k2 = "k2"; assertThat(_nbhm.put(k1, "v1"), nullValue()); assertThat(_nbhm.put(k2, "v2"), nullValue()); // Serialize it out try { FileOutputStream fos = new FileOutputStream("NBHM_test.txt"); ObjectOutputStream out = new ObjectOutputStream(fos); out.writeObject(_nbhm); out.close(); } catch (IOException ex) { ex.printStackTrace(); } // Read it back try { File f = new File("NBHM_test.txt"); FileInputStream fis = new FileInputStream(f); ObjectInputStream in = new ObjectInputStream(fis); NonBlockingIdentityHashMap nbhm = (NonBlockingIdentityHashMap) in.readObject(); in.close(); assertThat( "serialization works", nbhm.toString(), anyOf(is("{k1=v1, k2=v2}"), is("{k2=v2, k1=v1}"))); if (!f.delete()) throw new IOException("delete failed"); } catch (IOException ex) { ex.printStackTrace(); } catch (ClassNotFoundException ex) { ex.printStackTrace(); } }
/** @see util.ObjStream#toArray() */ public final Object[] toArray() throws IOException { if (in == null) return null; ObjectInputStream instr = new ObjectInputStream(new FileInputStream(file)); Vector res = new Vector(); Object[] resArray = null; Object tw = null; try { try { while (true) { tw = instr.readObject(); res.add(tw); } } catch (EOFException e) { } resArray = new Object[res.size()]; res.toArray(resArray); } catch (ClassNotFoundException e) { } in.close(); instr.close(); instr = null; in = null; file.delete(); return resArray; }
/** * Loads training set from the specified file * * @param filePath training set file * @return loded training set */ public static DataSet load(String filePath) { ObjectInputStream oistream = null; try { File file = new File(filePath); if (!file.exists()) { throw new FileNotFoundException("Cannot find file: " + filePath); } oistream = new ObjectInputStream(new FileInputStream(filePath)); DataSet tSet = (DataSet) oistream.readObject(); return tSet; } catch (IOException ioe) { ioe.printStackTrace(); } catch (ClassNotFoundException cnfe) { cnfe.printStackTrace(); } finally { if (oistream != null) { try { oistream.close(); } catch (IOException ioe) { } } } return null; }
public ArrayList<FIncomePO> findAll() throws RemoteException { ArrayList<FIncomePO> incomeList = new ArrayList<FIncomePO>(); FileInputStream fis = null; ObjectInputStream ois = null; try { fis = new FileInputStream(file); ois = new ObjectInputStream(fis); FIncomePO in = (FIncomePO) ois.readObject(); while (fis.available() > 0) { byte[] buf = new byte[4]; fis.read(buf); FIncomePO incomepo = (FIncomePO) ois.readObject(); incomeList.add(incomepo); } } catch (Exception e) { e.printStackTrace(); } finally { try { ois.close(); } catch (IOException e) { // TODO 自动生成的 catch 块 e.printStackTrace(); } } return incomeList; }
public ArrayList<FIncomePO> findByTime(String time1, String time2) throws RemoteException, IOException { ArrayList<FIncomePO> income = new ArrayList<FIncomePO>(); ObjectInputStream os = null; SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd"); try { Date date1 = formatter.parse(time1); Date date2 = formatter.parse(time2); FileInputStream fs = new FileInputStream(file); os = new ObjectInputStream(fs); FIncomePO po = (FIncomePO) os.readObject(); while (fs.available() > 0) { byte[] buf = new byte[4]; fs.read(buf); FIncomePO incomepo = (FIncomePO) os.readObject(); if (formatter.parse(incomepo.getTime()).after(date1) && formatter.parse(incomepo.getTime()).before(date2)) { income.add(incomepo); } } return income; } catch (Exception e) { return null; } finally { os.close(); } }
/* * receive process sent from slaves via socket */ public void receiveProcess() throws IOException, ClassNotFoundException { ServerSocket listener = null; Socket socket; ObjectInputStream in = null; try { // 1. creating a server socket listener = new ServerSocket(getPort()); while (true) { // 2. wait for connection System.out.println("Master Waiting for Slave"); socket = listener.accept(); System.out.println("Connection received from " + listener.getInetAddress().getHostName()); // 3.read object from inputstream in = new ObjectInputStream(socket.getInputStream()); // String s = (String) in.readObject(); // System.out.println("Message Received from slave" + s); MigratableProcess process = (MigratableProcess) in.readObject(); processList.add(process); } } catch (IOException e) { e.printStackTrace(); } finally { // 4.close connection in.close(); listener.close(); } }
public void run() { try { System.out.println("socked"); sock = new Socket(ii, pp); oout = new ObjectOutputStream(sock.getOutputStream()); oout.flush(); oin = new ObjectInputStream(sock.getInputStream()); System.out.println("read "); rf.setLength(0); do { System.out.println("read "); file f = (file) oin.readObject(); if (f.length <= 0) break; write(f); } while (true); oout.close(); oin.close(); rf.close(); sock.close(); xx.ConfirmPopup("Haua file namano shesh!!!"); } catch (Exception e) { e.printStackTrace(); } }
/** Loads the extraction model from the file. */ public void loadModel() throws Exception { BufferedInputStream inStream = new BufferedInputStream(new FileInputStream(m_modelName)); ObjectInputStream in = new ObjectInputStream(inStream); m_KEAFilter = (KEAFilter) in.readObject(); in.close(); }
/** * Deserialize an {@link com.microsoft.windowsazure.services.table.client.EntityProperty}. * * @param property a datastore {@link * com.microsoft.windowsazure.services.table.client.EntityProperty}. * @return the deserialized object. * @throws java.io.IOException * @throws ClassNotFoundException * @see com.microsoft.windowsazure.services.table.client.EntityProperty */ public static Object deserialize(EntityProperty property) throws IOException, ClassNotFoundException { byte[] bytes = property.getValueAsByteArray(); ByteArrayInputStream b = new ByteArrayInputStream(bytes); ObjectInputStream o = new ObjectInputStream(b); return o.readObject(); }
static boolean loadDat(String path) { // ByteArray byteArray = ByteArray.createByteArray(path); // if (byteArray == null) return false; // // int size = byteArray.nextInt(); // 这两个数组从byte转为int竟然要花4秒钟 // start = new int[size]; // for (int i = 0; i < size; ++i) // { // start[i] = byteArray.nextInt(); // } // // size = byteArray.nextInt(); // pair = new int[size]; // for (int i = 0; i < size; ++i) // { // pair[i] = byteArray.nextInt(); // } try { ObjectInputStream in = new ObjectInputStream(new FileInputStream(path)); start = (int[]) in.readObject(); pair = (int[]) in.readObject(); in.close(); } catch (Exception e) { logger.warning("尝试载入缓存文件" + path + "发生异常[" + e + "],下面将载入源文件并自动缓存……"); return false; } return true; }
public static void Ex() { System.out.println("-- do zapisu --"); BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); DowodOsobisty z = new DowodOsobisty(br); z.info(); try { ObjectOutputStream outp = new ObjectOutputStream(new FileOutputStream("plik.dat")); outp.writeObject(z); outp.close(); } catch (Exception e) { System.out.println(e); } System.out.println("\n-- z pliku --"); ObjectInputStream inp; try { inp = new ObjectInputStream(new FileInputStream("plik.dat")); Object o = inp.readObject(); DowodOsobisty x = (DowodOsobisty) o; inp.close(); x.info(); } catch (Exception e) { System.out.println(e); } }
public FileCollectionSnapshot snapshot(FileCollection files) { try { File snapshotFile = cache.get(files); if (snapshotFile == null) { assert cache.size() == 0; FileCollectionSnapshot snapshot = snapshotter.snapshot(files); snapshotFile = new File(tmpDir, String.valueOf(cache.size())); ObjectOutputStream outstr = new ObjectOutputStream(new BufferedOutputStream(new FileOutputStream(snapshotFile))); try { outstr.writeObject(snapshot); } finally { outstr.close(); } cache.put(files, snapshotFile); return snapshot; } else { ObjectInputStream instr = new ObjectInputStream(new BufferedInputStream(new FileInputStream(snapshotFile))); try { return (FileCollectionSnapshot) instr.readObject(); } finally { instr.close(); } } } catch (Exception e) { throw new UncheckedIOException(e); } }
public CompiledScriptCache loadCompiledScriptCache() { if (Config.SCRIPT_CACHE) { File file = new File(SCRIPT_FOLDER, "CompiledScripts.cache"); if (file.isFile()) { ObjectInputStream ois = null; try { ois = new ObjectInputStream(new FileInputStream(file)); CompiledScriptCache cache = (CompiledScriptCache) ois.readObject(); return cache; } catch (InvalidClassException e) { _log.fatal( "Failed loading Compiled Scripts Cache, invalid class (Possibly outdated).", e); } catch (IOException e) { _log.fatal("Failed loading Compiled Scripts Cache from file.", e); } catch (ClassNotFoundException e) { _log.fatal("Failed loading Compiled Scripts Cache, class not found.", e); } finally { try { ois.close(); } catch (Exception e) { } } return new CompiledScriptCache(); } else return new CompiledScriptCache(); } return null; }
/** * Charge le projet depuis le chemin <code>cheminSauvegarde</code>, et rétabli les attributs et * les observeur tel qu'avant la sauvergarde. * * @param cheminSauvegarde * @return le projet chargé et initialisé. * @throws FileNotFoundException * @throws IOException * @throws ClassNotFoundException */ public static Projet chargerProjetDepuisFichier(File cheminSauvegarde) throws FileNotFoundException, IOException, ClassNotFoundException { ObjectInputStream in = new ObjectInputStream(new FileInputStream(cheminSauvegarde)); Projet projetCharge = (Projet) in.readObject(); projetCharge.initialisationApresChargement(); return projetCharge; }
public static void main1(String[] args) throws IOException, ClassNotFoundException { Employee harry = new Employee("Harry Hacker", 50000, 1989, 10, 1); Manager carl = new Manager("Carl Cracker", 80000, 1987, 12, 15); carl.setSecretary(harry); Manager tony = new Manager("Tony Tester", 40000, 1990, 3, 15); tony.setSecretary(harry); Employee[] staff = new Employee[3]; staff[0] = carl; staff[1] = harry; staff[2] = tony; // save all employee records to the file employee.dat try (ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream("employee.dat"))) { out.writeObject(staff); } try (ObjectInputStream in = new ObjectInputStream(new FileInputStream("employee.dat"))) { // retrieve all records into a new array Employee[] newStaff = (Employee[]) in.readObject(); // raise secretary's salary newStaff[1].raiseSalary(10); // print the newly read employee records for (Employee e : newStaff) System.out.println(e); } }
/** * Because the readArchive() method requires unchecked casting, the compiler throws a warning at * compile time. Since we already know the data type we are extracting from the file we can safely * suppress this warning. */ @SuppressWarnings("unchecked") public AbstractRoom[] readArchive() throws IOException, ClassNotFoundException { ObjectInputStream in = new ObjectInputStream(new FileInputStream("RoomArchive.txt")); roomArr = (AbstractRoom[]) in.readObject(); in.close(); return roomArr; }
public static GA GAWithCheckpoint(String checkpoint) throws Exception { File checkpointFile = new File(checkpoint); FileInputStream zin = new FileInputStream(checkpointFile); GZIPInputStream in = new GZIPInputStream(zin); ObjectInputStream oin = new ObjectInputStream(in); Checkpoint ckpt = (Checkpoint) oin.readObject(); GA ga = ckpt.ga; ga._checkpoint = ckpt; ckpt.checkpointNumber++; // because it gets increased only after ckpt is // written oin.close(); System.out.println(ckpt.report.toString()); // Do we want to append to the file if it exists? Or just overwrite it? // Heu! Quae enim quaestio animas virorum vero pertemptit. // Wowzers! This is, indeed, a question that truly tests mens' souls. if (ga._outputfile != null) ga._outputStream = new FileOutputStream(new File(ga._outputfile)); else ga._outputStream = System.out; return ga; }
private void setHPubAccessHandleString(String encodedHandleWithSpaces) { String encodedHandle = removeSpaceCharacters(encodedHandleWithSpaces); if ((encodedHandle == null) || (encodedHandle.length() < 5)) { return; } try { byte[] handleByteArray = null; sun.misc.BASE64Decoder dec = new sun.misc.BASE64Decoder(); try { handleByteArray = dec.decodeBuffer(encodedHandle); } catch (Exception e) { System.out.println("AccessEJBTemplate::setHPubAccessHandleString() decoding buffer"); } ; ByteArrayInputStream bais = new ByteArrayInputStream(handleByteArray); javax.ejb.Handle h1 = null; try { ObjectInputStream ois = new ObjectInputStream(bais); hPubAccessHandle = (javax.ejb.Handle) ois.readObject(); } catch (Exception ioe) { System.out.println("Exception reading handle object"); } } catch (Exception e) { e.printStackTrace(System.err); System.out.println("Exception AccessEJBTemplate::setHPubAccessHandleString()"); } return; }
public void checkSlave() throws IOException, ClassNotFoundException { ServerSocket listener = null; Socket socket; ObjectInputStream in = null; try { // 1. creating a server socket listener = new ServerSocket(15440); while (true) { // 2. wait for connection // System.out.println("Waiting for checkSlave"); socket = listener.accept(); // 3.read object from inputstream in = new ObjectInputStream(socket.getInputStream()); SlaveBean slave = (SlaveBean) in.readObject(); slaveList.put(slave, slave.getCurCount()); } } catch (IOException e) { e.printStackTrace(); } finally { // 4.close connection in.close(); listener.close(); } }
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException { int version = in.readInt(); this.encoding = (String) in.readObject(); if (encoding.equals("null")) { encoding = null; } }
public static Object loadObjectFromFile(String fileName) throws Exception { FileInputStream fis = new FileInputStream(fileName); ObjectInputStream ois = new ObjectInputStream(fis); Object obj = ois.readObject(); ois.close(); return obj; }