List of usage examples for java.io ObjectInputStream readInt
public int readInt() throws IOException
From source file:IntHashMap.java
/** * Reconstitutes the <code>IntHashMap</code> instance from a stream (i.e., * deserialize it)./*ww w. j a v a 2 s. c om*/ * * @exception IOException * @exception ClassNotFoundException */ private void readObject(java.io.ObjectInputStream s) throws IOException, ClassNotFoundException { // read in the threshold, loadfactor, and any hidden stuff s.defaultReadObject(); // read in number of buckets and allocate the bucket array; int numBuckets = s.readInt(); table = new Entry[numBuckets]; // read in size (number of Mappings) int size = s.readInt(); // read the keys and values, and put the mappings in the IntHashMap for (int i = 0; i < size; i++) { int key = s.readInt(); Object value = s.readObject(); put(key, value); } }
From source file:IdentityHashMap.java
/** * Reconstitute the <tt>IdentityHashMap</tt> instance from a stream (i.e., * deserialize it)./*from w w w . j a v a 2 s .c o m*/ */ private void readObject(java.io.ObjectInputStream s) throws IOException, ClassNotFoundException { // Read in the threshold, loadfactor, and any hidden stuff s.defaultReadObject(); // Read in number of buckets and allocate the bucket array; int numBuckets = s.readInt(); table = new Entry[numBuckets]; // Read in size (number of Mappings) int size = s.readInt(); // Read the keys and values, and put the mappings in the IdentityHashMap for (int i = 0; i < size; i++) { Object key = s.readObject(); Object value = s.readObject(); put(key, value); } }
From source file:org.apache.ojb.broker.util.ReferenceMap.java
/** * Reads the contents of this object from the given input stream. * * @param inp the input stream to read from * @throws java.io.IOException if the stream raises it * @throws java.lang.ClassNotFoundException if the stream raises it *//*from ww w . j av a 2 s. c o m*/ private void readObject(ObjectInputStream inp) throws IOException, ClassNotFoundException { inp.defaultReadObject(); table = new Entry[inp.readInt()]; threshold = (int) (table.length * loadFactor); queue = new ReferenceQueue(); Object key = inp.readObject(); while (key != null) { Object value = inp.readObject(); put(key, value); key = inp.readObject(); } }
From source file:com.github.jsonj.JsonObject.java
void readObject(java.io.ObjectInputStream in) throws IOException, ClassNotFoundException { // when deserializing, parse the json string try {//from w ww .j av a 2 s.c o m int length = in.readInt(); byte[] buf = new byte[length]; in.readFully(buf); if (parser == null) { // create it lazily, static so won't increase object size parser = new JsonParser(); } JsonElement o = parser.parse(new String(buf, UTF8)); Field f = getClass().getDeclaredField("intMap"); f.setAccessible(true); f.set(this, new SimpleIntKeyMap<>()); for (Entry<String, JsonElement> e : o.asObject().entrySet()) { put(e.getKey(), e.getValue()); } } catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e) { throw new IllegalStateException(e); } }
From source file:aprofplot.jfreechart.SamplingXYLineAndShapeRenderer.java
/** * Provides serialization support.//from w w w .j ava2s . c o m * * @param stream the input stream. * * @throws IOException if there is an I/O error. * @throws ClassNotFoundException if there is a classpath problem. */ private void readObject(ObjectInputStream stream) throws IOException, ClassNotFoundException { stream.defaultReadObject(); this.lineWidth = stream.readInt(); this.shapeSize = stream.readInt(); }
From source file:net.sf.nmedit.jtheme.store.DefaultStorageContext.java
private boolean initializeFromCache(File cacheFile, ClassLoader loader) throws Exception { ObjectInputStream in = new PluginObjectInputStream(loader, new BufferedInputStream(new FileInputStream(cacheFile))); try {//from ww w . ja v a 2 s. c om { // css cssStyleSheet = (String) in.readObject(); try { buildCssFromString(cssStyleSheet); } finally { cssStyleSheet = null; } } { // defs ClassLoader cl = getContextClassLoader(); if (cl == null) cl = loader; int size = in.readInt(); imageResourceMap = new HashMap<String, ImageResource>(size * 2); for (int i = 0; i < size; i++) { String key = (String) in.readObject(); ImageResource ir = (ImageResource) in.readObject(); ir.setCustomClassLoader(cl); ir.setImageCache(imageCache); imageResourceMap.put(key, ir); } } { // module elements int size = in.readInt(); moduleStoreMap = new HashMap<Object, ModuleElement>(size); for (int i = 0; i < size; i++) { ModuleElement e = (ModuleElement) in.readObject(); moduleStoreMap.put(e.getId(), e); e.initializeElement(this); } } } finally { in.close(); } return true; }
From source file:FastMap.java
/** * Requires special handling during de-serialization process. * * @param stream the object input stream. * @throws IOException if an I/O error occurs. * @throws ClassNotFoundException if the class for the object de-serialized * is not found.//w ww. ja va2 s . c o m */ private void readObject(ObjectInputStream stream) throws IOException, ClassNotFoundException { int capacity = stream.readInt(); initialize(capacity); int size = stream.readInt(); for (int i = 0; i < size; i++) { Object key = stream.readObject(); Object value = stream.readObject(); addEntry(key, value); } }
From source file:org.mortbay.ijetty.IJetty.java
License:asdf
protected int getStoredJettyVersion() { File jettyDir = __JETTY_DIR;//from w w w .j a v a 2 s.c o m if (!jettyDir.exists()) { return -1; } File versionFile = new File(jettyDir, "version.code"); if (!versionFile.exists()) { return -1; } int val = -1; ObjectInputStream ois = null; try { ois = new ObjectInputStream(new FileInputStream(versionFile)); val = ois.readInt(); return val; } catch (Exception e) { Log.e(TAG, "Problem reading version.code", e); return -1; } finally { if (ois != null) { try { ois.close(); } catch (Exception e) { Log.d(TAG, "Error closing version.code input stream", e); } } } }
From source file:org.apache.flink.cep.nfa.SharedBuffer.java
private void readObject(ObjectInputStream ois) throws IOException, ClassNotFoundException { DataInputViewStreamWrapper source = new DataInputViewStreamWrapper(ois); ArrayList<SharedBufferEntry<K, V>> entryList = new ArrayList<>(); ois.defaultReadObject();/* ww w .j av a 2 s . c o m*/ this.pages = new HashMap<>(); int numberPages = ois.readInt(); for (int i = 0; i < numberPages; i++) { // key of the page @SuppressWarnings("unchecked") K key = (K) ois.readObject(); SharedBufferPage<K, V> page = new SharedBufferPage<>(key); pages.put(key, page); int numberEntries = ois.readInt(); for (int j = 0; j < numberEntries; j++) { // restore the SharedBufferEntries for the given page V value = valueSerializer.deserialize(source); long timestamp = ois.readLong(); ValueTimeWrapper<V> valueTimeWrapper = new ValueTimeWrapper<>(value, timestamp); SharedBufferEntry<K, V> sharedBufferEntry = new SharedBufferEntry<K, V>(valueTimeWrapper, page); sharedBufferEntry.referenceCounter = ois.readInt(); page.entries.put(valueTimeWrapper, sharedBufferEntry); entryList.add(sharedBufferEntry); } } // read the edges of the shared buffer entries int numberEdges = ois.readInt(); for (int j = 0; j < numberEdges; j++) { int sourceIndex = ois.readInt(); int targetIndex = ois.readInt(); if (sourceIndex >= entryList.size() || sourceIndex < 0) { throw new RuntimeException("Could not find source entry with index " + sourceIndex + ". This indicates a corrupted state."); } else { // We've already deserialized the shared buffer entry. Simply read its ID and // retrieve the buffer entry from the list of entries SharedBufferEntry<K, V> sourceEntry = entryList.get(sourceIndex); final DeweyNumber version = (DeweyNumber) ois.readObject(); final SharedBufferEntry<K, V> target; if (targetIndex >= 0) { if (targetIndex >= entryList.size()) { throw new RuntimeException("Could not find target entry with index " + targetIndex + ". This indicates a corrupted state."); } else { target = entryList.get(targetIndex); } } else { target = null; } sourceEntry.edges.add(new SharedBufferEdge<K, V>(target, version)); } } }
From source file:org.rdv.DockingDataPanelManager.java
/** * Creates the root window and the views. *///from w ww. ja va 2 s .co m 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_); }