List of usage examples for java.io ObjectInputStream available
public int available() throws IOException
From source file:Main.java
public static void main(String[] args) throws Exception { FileOutputStream out = new FileOutputStream("test.txt"); ObjectOutputStream oout = new ObjectOutputStream(out); oout.writeUTF("Hello World from java2s.com"); oout.flush();/* w w w . ja va2s. c om*/ oout.close(); ObjectInputStream ois = new ObjectInputStream(new FileInputStream("test.txt")); for (int i = 0; i < ois.available();) { System.out.print((char) ois.read()); } 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 .ja va 2 s .c o m 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:Main.java
public static void main(String[] args) throws Exception { FileOutputStream out = new FileOutputStream("test.txt"); ObjectOutputStream oout = new ObjectOutputStream(out); // write something in the file oout.writeUTF("Hello World from java2s.com"); oout.flush();// w ww .j a v a2s . c o m // create an ObjectInputStream for the file we created before ObjectInputStream ois = new ObjectInputStream(new FileInputStream("test.txt")); // read from the stream for (int i = 0; i < ois.available();) { System.out.print((char) ois.read()); } ois.close(); }
From source file:Main.java
public static void main(String[] args) throws Exception { FileOutputStream out = new FileOutputStream("test.txt"); ObjectOutputStream oout = new ObjectOutputStream(out); // write something in the file oout.writeUTF("Hello World from java2s.com"); oout.flush();//from www . j a va 2s .c o m oout.close(); // create an ObjectInputStream for the file we created before ObjectInputStream ois = new ObjectInputStream(new FileInputStream("test.txt")); // check how many bytes are available System.out.println(ois.available()); ois.close(); }
From source file:com.adobe.acs.commons.audit_log_search.impl.AuditLogSearchServlet.java
@SuppressWarnings("unchecked") private JsonArray getModifiedProperties(ValueMap properties) throws IOException { JsonArray modifiedProperties = new JsonArray(); InputStream is = properties.get("cq:properties", InputStream.class); if (is != null) { ObjectInputStream ois = new ObjectInputStream(is); ois.readInt();//from w ww .j av a2 s . c om while (ois.available() != -1) { try { Object obj = ois.readObject(); if (obj instanceof HashSet) { Set<String> propertiesSet = (Set<String>) obj; for (String property : propertiesSet) { modifiedProperties.add(new JsonPrimitive(property)); } break; } } catch (Exception e) { break; } } } return modifiedProperties; }
From source file:com.bigdata.dastor.db.ColumnFamilyStore.java
protected Set<String> readSavedCache(File path, boolean sort) throws IOException { Set<String> keys; if (sort) {/*w w w . j a v a 2 s . com*/ // sort the results on read because cache may be written many times during server lifetime, // so better to pay that price once on startup than sort at write time. keys = new TreeSet<String>(StorageProxy.keyComparator); } else { keys = new HashSet<String>(); } long start = System.currentTimeMillis(); if (path.exists()) { if (logger_.isDebugEnabled()) logger_.debug("reading saved cache from " + path); ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(new FileInputStream(path))); Charset UTF8 = Charset.forName("UTF-8"); while (in.available() > 0) { int size = in.readInt(); byte[] bytes = new byte[size]; in.readFully(bytes); keys.add(new String(bytes, UTF8)); } in.close(); if (logger_.isDebugEnabled()) logger_.debug(String.format("completed reading (%d ms; %d keys) from saved cache at %s", (System.currentTimeMillis() - start), keys.size(), path)); } return keys; }
From source file:org.apache.hadoop.hive.ql.exec.spark.SparkDynamicPartitionPruner.java
private void processFiles(MapWork work, JobConf jobConf) throws HiveException { ObjectInputStream in = null; try {//from ww w. j a v a 2s. c om Path baseDir = work.getTmpPathForPartitionPruning(); FileSystem fs = FileSystem.get(baseDir.toUri(), jobConf); // Find the SourceInfo to put values in. for (String name : sourceInfoMap.keySet()) { Path sourceDir = new Path(baseDir, name); for (FileStatus fstatus : fs.listStatus(sourceDir)) { LOG.info("Start processing pruning file: " + fstatus.getPath()); in = new ObjectInputStream(fs.open(fstatus.getPath())); String columnName = in.readUTF(); SourceInfo info = null; for (SourceInfo si : sourceInfoMap.get(name)) { if (columnName.equals(si.columnName)) { info = si; break; } } Preconditions.checkArgument(info != null, "AssertionError: no source info for the column: " + columnName); // Read fields while (in.available() > 0) { writable.readFields(in); Object row = info.deserializer.deserialize(writable); Object value = info.soi.getStructFieldData(row, info.field); value = ObjectInspectorUtils.copyToStandardObject(value, info.fieldInspector); info.values.add(value); } } } } catch (Exception e) { throw new HiveException(e); } finally { try { if (in != null) { in.close(); } } catch (IOException e) { throw new HiveException("error while trying to close input stream", e); } } }
From source file:org.scantegrity.crypto.FlatFileTable.java
public FlatFileTable(String p_path) throws FileNotFoundException, IOException, ClassNotFoundException { ObjectInputStream l_in = new ObjectInputStream(new FileInputStream(p_path)); int l_size = l_in.read(); c_list = new ArrayList<ArrayList<Object>>(); while (l_in.available() > 0) { ArrayList<Object> l_row = new ArrayList<Object>(); for (int x = 0; x < l_size; x++) l_row.add(l_in.readObject()); c_list.add(l_row);/* w ww.j ava2 s. c om*/ } }
From source file:tvbrowser.core.Settings.java
private static void loadWindowSettings() { File windowSettingsFile = new File(Settings.getUserSettingsDirName(), WINDOW_SETTINGS_FILE); if (windowSettingsFile.isFile() && windowSettingsFile.canRead()) { try {// w ww. j a v a 2 s. c om StreamUtilities.objectInputStream(windowSettingsFile, new ObjectInputStreamProcessor() { public void process(ObjectInputStream in) throws IOException { if (in.available() > 0) { in.readInt(); // read version int n = in.readInt(); // read number of window settings mWindowSettings = new HashMap<String, WindowSetting>(n); for (int i = 0; i < n; i++) { mWindowSettings.put(in.readUTF(), new WindowSetting(in)); } } in.close(); } }); } catch (Exception e) { // propably defect settings, create new settings mWindowSettings = null; } } if (mWindowSettings == null) { mWindowSettings = new HashMap<String, WindowSetting>(1); } }