Example usage for java.io ObjectOutputStream writeInt

List of usage examples for java.io ObjectOutputStream writeInt

Introduction

In this page you can find the example usage for java.io ObjectOutputStream writeInt.

Prototype

public void writeInt(int val) throws IOException 

Source Link

Document

Writes a 32 bit int.

Usage

From source file:FastMap.java

/**
 * Requires special handling during serialization process.
 *
 * @param  stream the object output stream.
 * @throws IOException if an I/O error occurs.
 *///from w ww.j  av a 2 s  . c  o m
private void writeObject(ObjectOutputStream stream) throws IOException {
    stream.writeInt(_capacity);
    stream.writeInt(_size);
    int count = 0;
    EntryImpl entry = _mapFirst;
    while (entry != null) {
        stream.writeObject(entry._key);
        stream.writeObject(entry._value);
        count++;
        entry = entry._after;
    }
    if (count != _size) {
        throw new IOException("FastMap Corrupted");
    }
}

From source file:com.github.jsonj.JsonObject.java

void writeObject(java.io.ObjectOutputStream out) throws IOException {
    // when using object serialization, write the json bytes
    byte[] bytes = toString().getBytes(UTF8);
    out.writeInt(bytes.length);
    out.write(bytes);//from   w  ww .j av  a  2 s .  c  o m

}

From source file:net.sf.jasperreports.engine.base.ElementsBlock.java

private void writeObject(java.io.ObjectOutputStream out) throws IOException {
    lockContext();// ww w  .j  ava2  s .c om
    try {
        ensureDataAndTouch();
        beforeExternalization();

        try {
            // maybe we should no longer serialize the id, as a new one is
            // generated on deserialization
            out.writeObject(uid);
            out.writeObject(context);

            ByteArrayOutputStream bout = new ByteArrayOutputStream();
            VirtualizationObjectOutputStream stream = new VirtualizationObjectOutputStream(bout, context);
            stream.writeObject(elements);
            stream.flush();

            byte[] bytes = bout.toByteArray();
            out.writeInt(bytes.length);
            out.write(bytes);
        } finally {
            afterExternalization();
        }
    } finally {
        unlockContext();
    }
}

From source file:org.rdv.DockingDataPanelManager.java

/**
 * Creates the root window and the views.
 *///from  ww  w .  j a v a 2s  .com
private void createRootWindow() {

    // The mixed view map makes it easy to mix static and dynamic views inside the same root window
    MixedViewHandler handler = new MixedViewHandler(viewMap_, new ViewSerializer() {
        public void writeView(View view, ObjectOutputStream out) throws IOException {
            out.writeInt(((DockingView) view).getId());
        }

        public View readView(ObjectInputStream in) throws IOException {
            return viewMap_.getView(in.readInt());
        }
    });

    rootWindow_ = DockingUtil.createRootWindow(viewMap_, handler, true);

    // turn off tab window buttons
    rootWindow_.getRootWindowProperties().getTabWindowProperties().getCloseButtonProperties().setVisible(false);//getTabProperties().getFocusedButtonProperties().getCloseButtonProperties().setVisible(false);
    //rootWindow_.getRootWindowProperties().getTabWindowProperties().getCloseButtonProperties().setVisible(false);
    rootWindow_.getRootWindowProperties().setRecursiveTabsEnabled(true);

    rootWindow_.getRootWindowProperties().getFloatingWindowProperties().setUseFrame(true);

    // disable per-tab buttons like undock/minimize
    rootWindow_.getRootWindowProperties().getTabWindowProperties().getTabProperties()
            .getHighlightedButtonProperties().getUndockButtonProperties().setVisible(false);
    rootWindow_.getRootWindowProperties().getTabWindowProperties().getTabProperties()
            .getHighlightedButtonProperties().getDockButtonProperties().setVisible(false);
    rootWindow_.getRootWindowProperties().getTabWindowProperties().getTabProperties()
            .getHighlightedButtonProperties().getMinimizeButtonProperties().setVisible(false);

    final Icon closeIcon = rootWindow_.getRootWindowProperties().getTabWindowProperties()
            .getCloseButtonProperties().getIcon();
    final Icon undockIcon = rootWindow_.getRootWindowProperties().getTabWindowProperties()
            .getUndockButtonProperties().getIcon();
    final Icon dockIcon = rootWindow_.getRootWindowProperties().getTabWindowProperties()
            .getDockButtonProperties().getIcon();

    rootWindow_.setPopupMenuFactory(new WindowPopupMenuFactory() {
        public JPopupMenu createPopupMenu(final DockingWindow window) {

            JPopupMenu menu = new JPopupMenu();
            // Check that the window is a View
            if (window instanceof View) {
                final View v = (View) window;

                if (window instanceof DockingPanelView) {
                    final DockingPanelView dpv = (DockingPanelView) window;

                    JMenuItem renameItem = menu.add("Set Description");
                    renameItem.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent e) {

                            String s = (String) JOptionPane.showInputDialog(window, "Enter new description:\n",
                                    "Set Description", JOptionPane.PLAIN_MESSAGE, null, null,
                                    dpv.getDataPanel().getDescription());

                            if (s != null) {
                                //v.setName(s); 
                                //v.getViewProperties().setTitle(s);
                                dpv.getDataPanel().setDescription((s.isEmpty()) ? null : s);
                            }
                        }
                    });
                }

                JMenuItem closeItem = menu.add("Close");
                closeItem.setIcon(closeIcon);
                closeItem.addActionListener(new ActionListener() {
                    public void actionPerformed(ActionEvent e) {
                        try {
                            window.closeWithAbort();
                        } catch (OperationAbortedException e1) {
                            //e1.printStackTrace();
                        }
                    }
                });

                if (v.isUndocked()) {
                    JMenuItem dockItem = menu.add("Dock");
                    dockItem.setIcon(dockIcon);
                    dockItem.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent e) {
                            try {
                                window.dock();
                            } catch (Exception e1) {
                                //e1.printStackTrace();
                            }
                        }
                    });
                } else {
                    JMenuItem undockItem = menu.add("Undock");
                    undockItem.setIcon(undockIcon);
                    undockItem.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent e) {
                            try {
                                window.undock(new Point(0, 0));
                            } catch (Exception e1) {
                                //e1.printStackTrace();
                            }
                        }
                    });
                }
            }
            return menu;
        }
    });

    properties_.addSuperObject(titleBarStyleProperties);
    titleBarTheme_ = true;

    // Set gradient theme. The theme properties object is the super object of our properties object, which
    // means our property value settings will override the theme values
    properties_.addSuperObject(currentTheme_.getRootWindowProperties());

    // Our properties object is the super object of the root window properties object, so all property values of the
    // theme and in our property object will be used by the root window
    rootWindow_.getRootWindowProperties().addSuperObject(properties_);

    // Enable the bottom window bar
    rootWindow_.getWindowBar(Direction.DOWN).setEnabled(true);

    // Add a listener which shows dialogs when a window is closing or closed.
    rootWindow_.addListener(new DockingWindowAdapter() {
        public void windowAdded(DockingWindow addedToWindow, DockingWindow addedWindow) {
            updateViews(addedWindow, true);

            // If the added window is a floating window, then update it
            if (addedWindow instanceof FloatingWindow)
                updateFloatingWindow((FloatingWindow) addedWindow);
        }

        public void windowRemoved(DockingWindow removedFromWindow, DockingWindow removedWindow) {
            //updateViews(removedWindow, false);
        }

        public void windowClosing(DockingWindow window) throws OperationAbortedException {
            // Confirm close operation
            if (JOptionPane.showConfirmDialog(UIUtilities.getMainFrame(),
                    "Really close data panel '" + window + "'?") != JOptionPane.YES_OPTION)
                throw new OperationAbortedException("Data panel close was aborted!");
            updateViews(window, false);
        }

        public void windowDocking(DockingWindow window) throws OperationAbortedException {
            // Confirm dock operation
            if (JOptionPane.showConfirmDialog(UIUtilities.getMainFrame(),
                    "Really dock data panel '" + window + "'?") != JOptionPane.YES_OPTION)
                throw new OperationAbortedException("Data panel dock was aborted!");
        }

        public void windowUndocking(DockingWindow window) throws OperationAbortedException {
            // Confirm undock operation 
            if (JOptionPane.showConfirmDialog(UIUtilities.getMainFrame(),
                    "Really undock data panel '" + window + "'?") != JOptionPane.YES_OPTION)
                throw new OperationAbortedException("Data panel undock was aborted!");
        }

    });

    // Add a mouse button listener that closes a window when it's clicked with the middle mouse button.
    rootWindow_.addTabMouseButtonListener(DockingWindowActionMouseButtonListener.MIDDLE_BUTTON_CLOSE_LISTENER);

    mainPanel_.add(rootWindow_);
}

From source file:IntHashMap.java

/**
 * Save the state of the <tt>HashMap</tt> instance to a stream (i.e.,
 * serialize it)./*from   w  ww . j  av a2 s .  com*/
 * 
 * @param s
 *            The ObjectOutputStream
 * @throws IOException
 * 
 * @serialData The <i>capacity</i> of the HashMap (the length of the bucket
 *             array) is emitted (int), followed by the <i>size</i> of the
 *             HashMap (the number of key-value mappings), followed by the
 *             key (Object) and value (Object) for each key-value mapping
 *             represented by the HashMap The key-value mappings are emitted
 *             in the order that they are returned by
 *             <tt>entrySet().iterator()</tt>.
 * 
 */
private void writeObject(java.io.ObjectOutputStream s) throws IOException {
    // Write out the threshold, loadfactor, and any hidden stuff
    s.defaultWriteObject();

    // Write out number of buckets
    s.writeInt(table.length);

    // Write out size (number of Mappings)
    s.writeInt(size);

    // Write out keys and values (alternating)
    for (Iterator i = entrySet().iterator(); i.hasNext();) {
        Entry e = (Entry) i.next();
        s.writeInt(e.getKey());
        s.writeObject(e.getValue());
    }
}

From source file:IntHashMap.java

/**
 * Save the state of the <tt>HashMap</tt> instance to a stream (i.e., serialize it).
 * /*from  ww w  .  j a v  a2  s. c o m*/
 * @param s
 *            The ObjectOutputStream
 * @throws IOException
 * 
 * @serialData The <i>capacity</i> of the HashMap (the length of the bucket array) is emitted
 *             (int), followed by the <i>size</i> of the HashMap (the number of key-value
 *             mappings), followed by the key (Object) and value (Object) for each key-value
 *             mapping represented by the HashMap The key-value mappings are emitted in the
 *             order that they are returned by <tt>entrySet().iterator()</tt>.
 * 
 */
private void writeObject(java.io.ObjectOutputStream s) throws IOException {
    // Write out the threshold, loadfactor, and any hidden stuff
    s.defaultWriteObject();

    // Write out number of buckets
    s.writeInt(table.length);

    // Write out size (number of Mappings)
    s.writeInt(size);

    // Write out keys and values (alternating)
    for (Iterator<Entry<V>> i = entrySet().iterator(); i.hasNext();) {
        Entry<V> e = i.next();
        s.writeInt(e.getKey());
        s.writeObject(e.getValue());
    }
}

From source file:org.mortbay.ijetty.IJetty.java

License:asdf

protected void setStoredJettyVersion(int version) {
    File jettyDir = __JETTY_DIR;/*from   w ww .j a  v a2 s.c  o  m*/
    if (!jettyDir.exists()) {
        return;
    }
    File versionFile = new File(jettyDir, "version.code");
    ObjectOutputStream oos = null;
    try {
        FileOutputStream fos = new FileOutputStream(versionFile);
        oos = new ObjectOutputStream(fos);
        oos.writeInt(version);
        oos.flush();
    } catch (Exception e) {
        Log.e(TAG, "Problem writing jetty version", e);
    } finally {
        if (oos != null) {
            try {
                oos.close();
            } catch (Exception e) {
                Log.d(TAG, "Error closing version.code output stream", e);
            }
        }
    }
}

From source file:org.apache.flink.cep.nfa.SharedBuffer.java

private void writeObject(ObjectOutputStream oos) throws IOException {
    DataOutputViewStreamWrapper target = new DataOutputViewStreamWrapper(oos);
    Map<SharedBufferEntry<K, V>, Integer> entryIDs = new HashMap<>();
    int totalEdges = 0;
    int entryCounter = 0;

    oos.defaultWriteObject();//from   ww w. j av a 2s. c  om

    // number of pages
    oos.writeInt(pages.size());

    for (Map.Entry<K, SharedBufferPage<K, V>> pageEntry : pages.entrySet()) {
        SharedBufferPage<K, V> page = pageEntry.getValue();

        // key for the current page
        oos.writeObject(page.getKey());
        // number of page entries
        oos.writeInt(page.entries.size());

        for (Map.Entry<ValueTimeWrapper<V>, SharedBufferEntry<K, V>> sharedBufferEntry : page.entries
                .entrySet()) {
            // serialize the sharedBufferEntry
            SharedBufferEntry<K, V> sharedBuffer = sharedBufferEntry.getValue();

            // assign id to the sharedBufferEntry for the future serialization of the previous
            // relation
            entryIDs.put(sharedBuffer, entryCounter++);

            ValueTimeWrapper<V> valueTimeWrapper = sharedBuffer.getValueTime();

            valueSerializer.serialize(valueTimeWrapper.value, target);
            oos.writeLong(valueTimeWrapper.getTimestamp());

            int edges = sharedBuffer.edges.size();
            totalEdges += edges;

            oos.writeInt(sharedBuffer.referenceCounter);
        }
    }

    // write the edges between the shared buffer entries
    oos.writeInt(totalEdges);

    for (Map.Entry<K, SharedBufferPage<K, V>> pageEntry : pages.entrySet()) {
        SharedBufferPage<K, V> page = pageEntry.getValue();

        for (Map.Entry<ValueTimeWrapper<V>, SharedBufferEntry<K, V>> sharedBufferEntry : page.entries
                .entrySet()) {
            SharedBufferEntry<K, V> sharedBuffer = sharedBufferEntry.getValue();

            if (!entryIDs.containsKey(sharedBuffer)) {
                throw new RuntimeException("Could not find id for entry: " + sharedBuffer);
            } else {
                int id = entryIDs.get(sharedBuffer);

                for (SharedBufferEdge<K, V> edge : sharedBuffer.edges) {
                    // in order to serialize the previous relation we simply serialize the ids
                    // of the source and target SharedBufferEntry
                    if (edge.target != null) {
                        if (!entryIDs.containsKey(edge.getTarget())) {
                            throw new RuntimeException("Could not find id for entry: " + edge.getTarget());
                        } else {
                            int targetId = entryIDs.get(edge.getTarget());

                            oos.writeInt(id);
                            oos.writeInt(targetId);
                            oos.writeObject(edge.version);
                        }
                    } else {
                        oos.writeInt(id);
                        oos.writeInt(-1);
                        oos.writeObject(edge.version);
                    }
                }
            }
        }
    }
}

From source file:org.dishevelled.multimap.impl.AbstractHashedMap.java

/**
 * Writes the map data to the stream. This method must be overridden if a
 * subclass must be setup before <code>put()</code> is used.
 *
 * Serialization is not one of the JDK's nicest topics. Normal serialization will
 * initialise the superclass before the subclass. Sometimes however, this isn't
 * what you want, as in this case the <code>put()</code> method on read can be
 * affected by subclass state.//w  w  w .java  2 s.  com
 *
 * The solution adopted here is to serialize the state data of this class in
 * this protected method. This method must be called by the
 * <code>writeObject()</code> of the first serializable subclass.
 *
 * Subclasses may override if they have a specific field that must be present
 * on read before this implementation will work. Generally, the read determines
 * what must be serialized here, if anything.
 *
 * @param out the output stream
 * @throws IOException if an I/O error occurs
 */
protected void doWriteObject(ObjectOutputStream out) throws IOException {
    out.writeFloat(loadFactor);
    out.writeInt(data.length);
    out.writeInt(size);
    for (Iterator<Map.Entry<K, V>> it = createEntrySetIterator(); it.hasNext();) {
        Map.Entry entry = it.next();
        out.writeObject(entry.getKey());
        out.writeObject(entry.getValue());
    }
}

From source file:edu.umd.cs.marmoset.modelClasses.Project.java

private void writeObject(ObjectOutputStream stream) throws IOException {
    stream.writeInt(serialMinorVersion);
    stream.defaultWriteObject();/* ww  w . j  a  va2s . c  om*/
}