List of usage examples for java.io ObjectInputStream readByte
public byte readByte() throws IOException
From source file:Main.java
public static void main(String[] args) throws Exception { byte b = 12;//from w ww.j a va 2s . c o m FileOutputStream out = new FileOutputStream("test.txt"); ObjectOutputStream oout = new ObjectOutputStream(out); // write something in the file oout.writeByte(b); oout.writeByte(21); oout.flush(); oout.close(); // create an ObjectInputStream for the file we created before ObjectInputStream ois = new ObjectInputStream(new FileInputStream("test.txt")); // read and print a byte System.out.println((char) ois.readByte()); // read and print a byte System.out.println((char) ois.readByte()); ois.close(); }
From source file:Main.java
public static void main(String[] args) throws Exception { String s = "Hello World!"; FileOutputStream out = new FileOutputStream("test.txt"); ObjectOutputStream oout = new ObjectOutputStream(out); oout.writeUTF(s);// w w w .j av a2 s . c om oout.writeUTF("This is an example from java2s.com"); oout.flush(); oout.close(); ObjectInputStream ois = new ObjectInputStream(new FileInputStream("test.txt")); ois.skipBytes(4); for (int i = 0; i < ois.available() - 4; i++) { System.out.print((char) ois.readByte()); } ois.close(); }
From source file:jfs.sync.encryption.JFSEncryptedStream.java
public static byte readMarker(ObjectInputStream ois) throws IOException { byte marker = ois.readByte(); if (log.isInfoEnabled()) { log.info("JFSEncryptedStream.readMarker() marker " + marker + " for "); } // if//from www. j a v a2 s . c o m return marker; }
From source file:ByteArrayList.java
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException { in.defaultReadObject();/*from ww w .j a v a 2s.com*/ array = new byte[in.readInt()]; for (int i = 0; i < size; i++) { array[i] = in.readByte(); } }
From source file:idontwant2see.IDontWant2See.java
public void readData(final ObjectInputStream in) throws IOException, ClassNotFoundException { final int version = in.readInt(); // read Version int n = in.readInt(); if (version <= 2) { for (int i = 0; i < n; i++) { final StringBuilder value = new StringBuilder("*"); value.append(in.readUTF()).append("*"); mSettings.getSearchList().add(new IDontWant2SeeListEntry(value.toString(), false)); }/*ww w . j a v a 2s . c o m*/ if (version == 2) { n = in.readInt(); for (int i = 0; i < n; i++) { mSettings.getSearchList().add(new IDontWant2SeeListEntry(in.readUTF(), true)); } mSettings.setSimpleMenu(false); } } else { for (int i = 0; i < n; i++) { mSettings.getSearchList().add(new IDontWant2SeeListEntry(in, version)); } mSettings.setSimpleMenu(in.readBoolean()); if (version >= 4) { mSettings.setSwitchToMyFilter(in.readBoolean()); } if (version >= 5) { mSettings.setLastEnteredExclusionString(in.readUTF()); } if (version >= 6) { mSettings.setLastUsedDate(Date.readData(in)); } if (version >= 7) { mSettings.setProgramImportance(in.readByte()); } else { mSettings.setProgramImportance(Program.DEFAULT_PROGRAM_IMPORTANCE); } } }
From source file:org.pentaho.reporting.engine.classic.core.Element.java
/** * A helper method that deserializes a object from the given stream. * * @param stream//from w w w. j a v a 2 s. com * the stream from which to read the object data. * @throws IOException * if an IO error occured. * @throws ClassNotFoundException * if an referenced class cannot be found. */ private void readObject(final ObjectInputStream stream) throws IOException, ClassNotFoundException { stream.defaultReadObject(); this.attributes = new ReportAttributeMap<Object>(stream.readLong()); final String[] nameSpaces = (String[]) stream.readObject(); for (int i = 0; i < nameSpaces.length; i++) { final String nameSpace = nameSpaces[i]; final String[] names = (String[]) stream.readObject(); for (int j = 0; j < names.length; j++) { final String name = names[j]; final int nullHandler = stream.readByte(); if (nullHandler == 0) { final Object attribute = SerializerHelper.getInstance().readObject(stream); this.attributes.setAttribute(nameSpace, name, attribute); } } } }
From source file:org.pentaho.reporting.libraries.serializer.SerializerHelper.java
/** * Reads the object from the object input stream. This object selects the best serializer to read the object. * <p/>//from www.ja v a 2 s .com * Make sure, that you use the same configuration (library and class versions, registered methods in the * SerializerHelper) for reading as you used for writing. * * @param in the object input stream from where to read the serialized data. * @return the generated object. * @throws IOException if reading the stream failed. * @throws ClassNotFoundException if serialized object class cannot be found. */ public synchronized Object readObject(final ObjectInputStream in) throws IOException, ClassNotFoundException { final int type = in.readByte(); if (type == 0) { return null; } if (type == 1) { return in.readObject(); } final Class c = (Class) in.readObject(); final SerializeMethod m = getSerializer(c); if (m == null) { throw new NotSerializableException(c.getName()); } return m.readObject(in); }