List of usage examples for java.io ObjectOutputStream writeInt
public void writeInt(int val) throws IOException
From source file:Main.java
public static void writePath(GeneralPath path, ObjectOutputStream out) throws IOException { PathIterator i = path.getPathIterator(null); float[] data = new float[6]; while (!i.isDone()) { switch (i.currentSegment(data)) { case PathIterator.SEG_MOVETO: out.writeInt(PathIterator.SEG_MOVETO); out.writeFloat(data[0]);/* w w w . j a va 2 s.c om*/ out.writeFloat(data[1]); break; case PathIterator.SEG_LINETO: out.writeInt(PathIterator.SEG_LINETO); out.writeFloat(data[0]); out.writeFloat(data[1]); break; case PathIterator.SEG_QUADTO: out.writeInt(PathIterator.SEG_QUADTO); out.writeFloat(data[0]); out.writeFloat(data[1]); out.writeFloat(data[2]); out.writeFloat(data[3]); break; case PathIterator.SEG_CUBICTO: out.writeInt(PathIterator.SEG_CUBICTO); out.writeFloat(data[0]); out.writeFloat(data[1]); out.writeFloat(data[2]); out.writeFloat(data[3]); out.writeFloat(data[4]); out.writeFloat(data[5]); break; case PathIterator.SEG_CLOSE: out.writeInt(PathIterator.SEG_CLOSE); break; default: throw new IOException(); } i.next(); } out.writeInt(PATH_IS_DONE); }
From source file:org.eclipse.wb.internal.core.utils.IOUtils2.java
/** * Writes byte array as length and bytes. *//*w ww . j a va 2 s . co m*/ public static void writeByteArray(ObjectOutputStream oos, byte[] bytes) throws IOException { oos.writeInt(bytes.length); oos.write(bytes); }
From source file:org.apache.falcon.state.store.jdbc.BeanMapperUtil.java
public static byte[] getAwaitedPredicates(InstanceState instanceState) throws IOException { ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); ObjectOutputStream out = null; try {/*w ww. j a v a2 s . c o m*/ out = new ObjectOutputStream(byteArrayOutputStream); out.writeInt(instanceState.getInstance().getAwaitingPredicates().size()); for (Predicate predicate : instanceState.getInstance().getAwaitingPredicates()) { out.writeObject(predicate); } return byteArrayOutputStream.toByteArray(); } finally { IOUtils.closeQuietly(out); } }
From source file:org.apache.falcon.state.store.jdbc.BeanMapperUtil.java
/** * Convert instance of Entity's instance to InstanceBean of DB. * @param instanceState/* w ww .jav a 2 s . c om*/ * @return * @throws StateStoreException * @throws IOException */ public static InstanceBean convertToInstanceBean(InstanceState instanceState) throws StateStoreException, IOException { InstanceBean instanceBean = new InstanceBean(); ExecutionInstance instance = instanceState.getInstance(); if (instance.getActualEnd() != null) { instanceBean.setActualEndTime(new Timestamp(instance.getActualEnd().getMillis())); } if (instance.getActualStart() != null) { instanceBean.setActualStartTime(new Timestamp(instance.getActualStart().getMillis())); } if (instanceState.getCurrentState() != null) { instanceBean.setCurrentState(instanceState.getCurrentState().toString()); } if (instance.getExternalID() != null) { instanceBean.setExternalID(instanceState.getInstance().getExternalID()); } instanceBean.setCluster(instance.getCluster()); instanceBean.setCreationTime(new Timestamp(instance.getCreationTime().getMillis())); instanceBean.setId(instance.getId().toString()); instanceBean.setInstanceTime(new Timestamp(instance.getInstanceTime().getMillis())); instanceBean.setEntityId(new InstanceID(instance).getEntityID().toString()); instanceBean.setInstanceSequence(instance.getInstanceSequence()); if (instance.getAwaitingPredicates() != null && !instance.getAwaitingPredicates().isEmpty()) { ObjectOutputStream out = null; ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); try { out = new ObjectOutputStream(byteArrayOutputStream); out.writeInt(instance.getAwaitingPredicates().size()); for (Predicate predicate : instance.getAwaitingPredicates()) { out.writeObject(predicate); } instanceBean.setAwaitedPredicates(byteArrayOutputStream.toByteArray()); } finally { IOUtils.closeQuietly(out); } } return instanceBean; }
From source file:org.n52.geoar.newdata.PluginLoader.java
/** * Saves the state of plugins to {@link SharedPreferences}. *//* ww w . j a v a 2 s. co m*/ public static void saveState() { try { ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); ObjectOutputStream objectOutputStream = new ObjectOutputStream(outputStream); // store plugin state version objectOutputStream.writeInt(PLUGIN_STATE_VERSION); List<InstalledPluginHolder> checkedPlugins = mInstalledPlugins.getCheckedItems(); objectOutputStream.writeInt(checkedPlugins.size()); for (InstalledPluginHolder plugin : checkedPlugins) { objectOutputStream.writeUTF(plugin.getIdentifier()); plugin.saveState(objectOutputStream); } SharedPreferences preferences = GeoARApplication.applicationContext .getSharedPreferences(GeoARApplication.PREFERENCES_FILE, Context.MODE_PRIVATE); Editor editor = preferences.edit(); objectOutputStream.flush(); editor.putString(PLUGIN_STATE_PREF, Base64.encodeToString(outputStream.toByteArray(), Base64.DEFAULT)); editor.commit(); objectOutputStream.close(); } catch (IOException e) { e.printStackTrace(); // TODO } }
From source file:Main.java
/** * Serialises a <code>Stroke</code> object. This code handles the * <code>BasicStroke</code> class which is the only <code>Stroke</code> * implementation provided by the JDK (and isn't directly * <code>Serializable</code>). * * @param stroke the stroke object (<code>null</code> permitted). * @param stream the output stream (<code>null</code> not permitted). * * @throws IOException if there is an I/O error. *//*from w w w . j a v a 2s .c o m*/ public static void writeStroke(final Stroke stroke, final ObjectOutputStream stream) throws IOException { if (stream == null) { throw new IllegalArgumentException("Null 'stream' argument."); } if (stroke != null) { stream.writeBoolean(false); if (stroke instanceof BasicStroke) { final BasicStroke s = (BasicStroke) stroke; stream.writeObject(BasicStroke.class); stream.writeFloat(s.getLineWidth()); stream.writeInt(s.getEndCap()); stream.writeInt(s.getLineJoin()); stream.writeFloat(s.getMiterLimit()); stream.writeObject(s.getDashArray()); stream.writeFloat(s.getDashPhase()); } else { stream.writeObject(stroke.getClass()); stream.writeObject(stroke); } } else { stream.writeBoolean(true); } }
From source file:Main.java
public static void writeStroke(Stroke aStroke, ObjectOutputStream out) throws IOException { if (aStroke instanceof Serializable) { out.writeBoolean(true);//from ww w .j av a 2 s . c om out.writeBoolean(true); out.writeObject(aStroke); } else if (aStroke instanceof BasicStroke) { out.writeBoolean(true); out.writeBoolean(false); BasicStroke s = (BasicStroke) aStroke; float[] dash = s.getDashArray(); if (dash == null) { out.write(0); } else { out.write(dash.length); for (int i = 0; i < dash.length; i++) { out.writeFloat(dash[i]); } } out.writeFloat(s.getLineWidth()); out.writeInt(s.getEndCap()); out.writeInt(s.getLineJoin()); out.writeFloat(s.getMiterLimit()); out.writeFloat(s.getDashPhase()); } else { out.writeBoolean(false); } }
From source file:org.apache.openjpa.lib.util.LRUMap.java
protected void doWriteObject(ObjectOutputStream out) throws IOException { out.writeInt(_max); super.doWriteObject(out); }
From source file:DoubleList.java
private void writeObject(ObjectOutputStream out) throws IOException { out.writeInt(CURRENT_SERIAL_VERSION); int size = data.length; out.writeInt(size);//from w w w . j a v a2 s. c o m for (int i = 1; i < size; i++) { out.writeDouble(data[i]); } out.writeInt(this.size); }
From source file:org.apache.flink.api.common.accumulators.ListAccumulator.java
@Override public void write(ObjectOutputStream out) throws IOException { int numItems = localValue.size(); out.writeInt(numItems); for (byte[] item : localValue) { out.writeInt(item.length);// w w w. java 2 s . c om out.write(item); } }