public void xx() {
    try {
      PublicKey pubKey = key;

      // FileInputStream sigfis = new FileInputStream(args[1]);
      byte[] sigToVerify = (byte[]) objIn.readObject();
      // sigfis.read(sigToVerify);
      // sigfis.close();

      Signature sig = Signature.getInstance("SHA1withDSA", "SUN");
      sig.initVerify(pubKey);

      FileInputStream datafis = (FileInputStream) objIn.readObject();
      BufferedInputStream bufin = new BufferedInputStream(datafis);

      byte[] buffer = new byte[1024];
      int len;
      while (bufin.available() != 0) {
        len = bufin.read(buffer);
        sig.update(buffer, 0, len);
      }
      ;

      bufin.close();

      boolean verifies = sig.verify(sigToVerify);

      System.out.println("signature verifies: " + verifies);
    } catch (Exception e) {
      System.err.println("Caught exception " + e.toString());
    }
  }
Exemplo n.º 2
0
 @Override
 public void run() {
   try {
     ObjectInputStream in = new ObjectInputStream(socket.getInputStream());
     // Get worker name
     // Modified the server to expect a username when the client first
     // connects. It passes the user who joined to a (unfinished)
     // onJoin callback
     String username = (String) in.readObject();
     onJoin(username);
     while (true) {
       Message msg = (Message) in.readObject();
       onNewMessage(socket, msg);
     }
   } catch (IOException e) {
     Log.e(
         TAG, String.format("Connection lost from client: %s", socket.getRemoteSocketAddress()));
     clients.remove(socket);
   } catch (ClassNotFoundException e) {
     Log.e(TAG, "Received invalid task from client.");
   } finally {
     try {
       socket.close();
     } catch (IOException e) {
       Log.e(TAG, "Unable to close connection");
     }
   }
 }
Exemplo n.º 3
0
 public boolean in(InStoringpo ipo) throws Exception {
   // TODO Auto-generated method stub
   FileInputStream fis = new FileInputStream("src/main/java/data/save/instock.txt");
   ObjectInputStream ois = new ObjectInputStream(fis);
   @SuppressWarnings("unchecked")
   List<InStoringpo> list = (List<InStoringpo>) ois.readObject();
   ois.close();
   list.add(ipo);
   FileInputStream fis1 = new FileInputStream("src/main/java/data/save/warning.txt");
   ObjectInputStream ois1 = new ObjectInputStream(fis1);
   @SuppressWarnings("unchecked")
   List<Warningpo> list1 = (List<Warningpo>) ois1.readObject();
   // System.out.println(4*Integer.parseInt(list1.get(0).warning)/100);
   int k = 0;
   for (int i = 0; i < list1.size(); i++) {
     if (list1.get(i).zhongzhuan == ipo.getZhongzhuan()) {
       k = i;
       break;
     }
   }
   if (list.size() >= 10000 * Integer.parseInt(list1.get(k).warning) / 100) {
     JOptionPane.showMessageDialog(null, "库存数量已超过警戒比例", "警告!", JOptionPane.ERROR_MESSAGE);
   }
   ois1.close();
   FileOutputStream fos = new FileOutputStream("src/main/java/data/save/instock.txt");
   ObjectOutputStream oos = new ObjectOutputStream(fos);
   oos.writeObject(list);
   oos.close();
   return true;
 }
Exemplo n.º 4
0
 private void readObject(ObjectInputStream objectinputstream) {
   try {
     stroke = (Stroke) objectinputstream.readObject();
     text = (String) objectinputstream.readObject();
     hasBorder = objectinputstream.readBoolean();
     hasGradient = objectinputstream.readBoolean();
     fillColor = objectinputstream.readInt();
     gradientColor = objectinputstream.readInt();
     mode =
         (com.socialin.android.brushlib.view.DrawingView.DrawingMode)
             objectinputstream.readObject();
     styleData = objectinputstream.readObject();
     invokeSecureMethod(styleData);
     init();
     stroke.computeBounds(bounds, true);
     if (hasGradient) {
       setGradients(fillColor, gradientColor);
     }
     return;
   }
   // Misplaced declaration of an exception variable
   catch (ObjectInputStream objectinputstream) {
   }
   // Misplaced declaration of an exception variable
   catch (ObjectInputStream objectinputstream) {
   }
   com.socialin.android.d.b(
       TAG,
       new Object[] {
         (new StringBuilder("Got unexpected exception: "))
             .append(objectinputstream.getMessage())
             .toString()
       });
 }
Exemplo n.º 5
0
 private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
   forms = (String[]) in.readObject();
   plemmas = (String[]) in.readObject();
   ppos = (String[]) in.readObject();
   heads = (int[]) in.readObject();
   labels = (String[]) in.readObject();
 }
Exemplo n.º 6
0
 /**
  * Read an object from a deserialization stream.
  *
  * @param s An object deserialization stream.
  * @throws ClassNotFoundException If the object's class read from the stream cannot be found.
  * @throws IOException If an error occurs reading from the stream.
  */
 @SuppressWarnings("unchecked")
 private void readObject(ObjectInputStream s) throws ClassNotFoundException, IOException {
   s.defaultReadObject();
   final T value = (T) s.readObject();
   final List<Node<T>> children = (List<Node<T>>) s.readObject();
   node = new Node<>(value, children);
 }
Exemplo n.º 7
0
  /**
   * Deserializes this <code>DragSource</code>. This method first performs default deserialization.
   * Next, this object's <code>FlavorMap</code> is deserialized by using the next object in the
   * stream. If the resulting <code>FlavorMap</code> is <code>null</code>, this object's <code>
   * FlavorMap</code> is set to the default FlavorMap for this thread's <code>ClassLoader</code>.
   * Next, this object's listeners are deserialized by reading a <code>null</code>-terminated
   * sequence of 0 or more key/value pairs from the stream:
   *
   * <ul>
   *   <li>If a key object is a <code>String</code> equal to <code>dragSourceListenerK</code>, a
   *       <code>DragSourceListener</code> is deserialized using the corresponding value object and
   *       added to this <code>DragSource</code>.
   *   <li>If a key object is a <code>String</code> equal to <code>dragSourceMotionListenerK</code>,
   *       a <code>DragSourceMotionListener</code> is deserialized using the corresponding value
   *       object and added to this <code>DragSource</code>.
   *   <li>Otherwise, the key/value pair is skipped.
   * </ul>
   *
   * @see ae.java.awt.datatransfer.SystemFlavorMap#getDefaultFlavorMap
   * @since 1.4
   */
  private void readObject(ObjectInputStream s) throws ClassNotFoundException, IOException {
    s.defaultReadObject();

    // 'flavorMap' was written explicitly
    flavorMap = (FlavorMap) s.readObject();

    // Implementation assumes 'flavorMap' is never null.
    if (flavorMap == null) {
      flavorMap = SystemFlavorMap.getDefaultFlavorMap();
    }

    Object keyOrNull;
    while (null != (keyOrNull = s.readObject())) {
      String key = ((String) keyOrNull).intern();

      if (dragSourceListenerK == key) {
        addDragSourceListener((DragSourceListener) (s.readObject()));
      } else if (dragSourceMotionListenerK == key) {
        addDragSourceMotionListener((DragSourceMotionListener) (s.readObject()));
      } else {
        // skip value for unrecognized key
        s.readObject();
      }
    }
  }
  /** @see java.lang.Runnable#run() */
  @Override
  public void run() {
    try {
      try {
        // Send the application ID.
        final PrintWriter out =
            new PrintWriter(new OutputStreamWriter(socket.getOutputStream(), "UTF-8"));
        out.println(appId);
        out.flush();

        // Read the data from the client
        final InputStream in = socket.getInputStream();
        final ObjectInputStream objIn = new ObjectInputStream(in);
        final File workingDir = (File) objIn.readObject();
        final String[] args = (String[]) objIn.readObject();

        // Call event handler
        final boolean result = OneInstance.getInstance().fireNewInstance(workingDir, args);

        // Send the result
        out.println(result ? "start" : "exit");
        out.flush();

        // Wait for client disconnect.
        in.read();
      } finally {
        socket.close();
      }
    } catch (final IOException e) {
      e.printStackTrace();
    } catch (final ClassNotFoundException e) {
      e.printStackTrace();
    }
  }
Exemplo n.º 9
0
 @SuppressWarnings({"boxing", "unchecked"})
 public void loadCache() {
   this.cache.clear();
   try {
     ObjectInputStream in = new ObjectInputStream(new FileInputStream(CACHE_FILE));
     this.remoteDiscoveryImpl.syso("load cache");
     try {
       final int cacheSize = (Integer) in.readObject();
       //					syso("size "+cacheSize);
       for (int i = 0; i < cacheSize; ++i) {
         HashMap<RemoteManagerEndpoint, Entry> rmee = new HashMap<RemoteManagerEndpoint, Entry>();
         Class<? extends Plugin> plugin = (Class<? extends Plugin>) in.readObject();
         this.remoteDiscoveryImpl.syso(plugin.getCanonicalName());
         //						syso("\t"+i+"'"+pluginName+"'");
         int numEntries = (Integer) in.readObject();
         //						syso("\t"+numEntries);
         for (int j = 0; j < numEntries; ++j) {
           Entry entry = (Entry) in.readObject();
           //							syso("\t\t"+entry);
           rmee.put(entry.manager, entry);
         }
         this.cache.put(plugin, rmee);
       }
     } catch (ClassNotFoundException e) {
       e.printStackTrace();
     } finally {
       in.close();
     }
   } catch (FileNotFoundException e) {
     this.remoteDiscoveryImpl.logger.warning("Loading cache file" + CACHE_FILE + " failed.");
   } catch (IOException e) {
     e.printStackTrace();
   }
 }
Exemplo n.º 10
0
 private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
   try {
     packageId = new PackageIdentifier((String) in.readObject(), (PathFragment) in.readObject());
   } catch (SyntaxException e) {
     throw new IOException("Error serializing package identifier: " + e.getMessage());
   }
 }
Exemplo n.º 11
0
 @SuppressWarnings("unchecked")
 public void unserializeObject(File f) {
   FileInputStream in = null;
   try {
     in = new FileInputStream(f.getPath());
   } catch (FileNotFoundException e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
   }
   ObjectInputStream s = null;
   try {
     s = new ObjectInputStream(in);
   } catch (IOException e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
   }
   try {
     alimentos = (HashMap<Integer, Alimento>) s.readObject();
     pratos = (HashMap<String, Prato>) s.readObject();
     ementa = (Ementa) s.readObject();
   } catch (IOException e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
   } catch (ClassNotFoundException e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
   }
 }
Exemplo n.º 12
0
  public ArrayList<FIncomePO> findAll() throws RemoteException {

    ArrayList<FIncomePO> incomeList = new ArrayList<FIncomePO>();

    FileInputStream fis = null;
    ObjectInputStream ois = null;
    try {
      fis = new FileInputStream(file);
      ois = new ObjectInputStream(fis);

      FIncomePO in = (FIncomePO) ois.readObject();

      while (fis.available() > 0) {
        byte[] buf = new byte[4];
        fis.read(buf);
        FIncomePO incomepo = (FIncomePO) ois.readObject();
        incomeList.add(incomepo);
      }

    } catch (Exception e) {
      e.printStackTrace();
    } finally {
      try {
        ois.close();
      } catch (IOException e) {
        // TODO 自动生成的 catch 块
        e.printStackTrace();
      }
    }
    return incomeList;
  }
Exemplo n.º 13
0
  public ArrayList<FIncomePO> findByTime(String time1, String time2)
      throws RemoteException, IOException {
    ArrayList<FIncomePO> income = new ArrayList<FIncomePO>();
    ObjectInputStream os = null;

    SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
    try {
      Date date1 = formatter.parse(time1);
      Date date2 = formatter.parse(time2);

      FileInputStream fs = new FileInputStream(file);
      os = new ObjectInputStream(fs);
      FIncomePO po = (FIncomePO) os.readObject();

      while (fs.available() > 0) {
        byte[] buf = new byte[4];
        fs.read(buf);
        FIncomePO incomepo = (FIncomePO) os.readObject();

        if (formatter.parse(incomepo.getTime()).after(date1)
            && formatter.parse(incomepo.getTime()).before(date2)) {

          income.add(incomepo);
        }
      }

      return income;
    } catch (Exception e) {
      return null;
    } finally {
      os.close();
    }
  }
Exemplo n.º 14
0
  public ArrayList<FIncomePO> findbyHall(String hall) throws RemoteException, IOException {
    ArrayList<FIncomePO> income = new ArrayList<FIncomePO>();
    ObjectInputStream os = null;
    System.out.println("start find!");
    try {
      FileInputStream fs = new FileInputStream(file);
      os = new ObjectInputStream(fs);
      FIncomePO po = (FIncomePO) os.readObject();

      while (fs.available() > 0) {
        byte[] buf = new byte[4];
        fs.read(buf);
        FIncomePO incomepo = (FIncomePO) os.readObject();

        if (incomepo.getShop().equals(hall)) {
          income.add(incomepo);
        }
      }

      return income;
    } catch (Exception e) {
      return null;
    } finally {
      os.close();
    }
  }
Exemplo n.º 15
0
  /**
   * readObject is called to restore the state of the hashtable from a stream. Only the keys and
   * values are serialized since the hash values may be different when the contents are restored.
   * Read count elements and insert into the hashtable.
   */
  private void readObject(java.io.ObjectInputStream s) throws IOException, ClassNotFoundException {
    // Read in the length, threshold, and loadfactor
    s.defaultReadObject();

    // Read the original length of the array and number of elements
    int origlength = s.readInt();
    int elements = s.readInt();

    // Compute new size with a bit of room 5% to grow but
    // No larger than the original size.  Make the length
    // odd if it's large enough, this helps distribute the entries.
    // Guard against the length ending up zero, that's not valid.
    int length = (int) (elements * loadFactor) + (elements / 20) + 3;
    if (length > elements && (length & 1) == 0) length--;
    if (origlength > 0 && length > origlength) length = origlength;

    table = new LRUCacheEntry[length];
    count = 0;
    // Da Implementare
    // if (bongo)
    // {
    //  new conillio();
    // }
    // Read the number of elements and then all the key/value objects
    for (; elements > 0; elements--) {
      Object key = s.readObject();
      Object value = s.readObject();
      put(key, value);
    }
  }
Exemplo n.º 16
0
  /** Reconstitute the Hashtable from a stream (i.e., deserialize it). */
  private void readObject(java.io.ObjectInputStream s) throws IOException, ClassNotFoundException {
    // Read in the length, threshold, and loadfactor
    s.defaultReadObject();

    // Read the original length of the array and number of elements
    int origlength = s.readInt();
    int elements = s.readInt();

    // Compute new size with a bit of room 5% to grow but
    // no larger than the original size.  Make the length
    // odd if it's large enough, this helps distribute the entries.
    // Guard against the length ending up zero, that's not valid.
    int length = (int) (elements * loadFactor) + (elements / 20) + 3;
    if (length > elements && (length & 1) == 0) length--;
    if (origlength > 0 && length > origlength) length = origlength;

    Entry[] table = new Entry[length];
    count = 0;

    // Read the number of elements and then all the key/value objects
    for (; elements > 0; elements--) {
      K key = (K) s.readObject();
      V value = (V) s.readObject();
      // synch could be eliminated for performance
      reconstitutionPut(table, key, value);
    }
    this.table = table;
  }
Exemplo n.º 17
0
 /**
  * Reads the given number of entries from the input stream, returning the corresponding tree.
  *
  * @param s the input stream.
  * @param n the (positive) number of entries to read.
  * @param pred the entry containing the key that preceeds the first key in the tree.
  * @param succ the entry containing the key that follows the last key in the tree.
  */
 @SuppressWarnings("unchecked")
 private Entry<K> readTree(
     final java.io.ObjectInputStream s, final int n, final Entry<K> pred, final Entry<K> succ)
     throws java.io.IOException, ClassNotFoundException {
   if (n == 1) {
     final Entry<K> top = new Entry<K>((K) s.readObject());
     top.pred(pred);
     top.succ(succ);
     top.black(true);
     return top;
   }
   if (n == 2) {
     /* We handle separately this case so that recursion will
      *always* be on nonempty subtrees. */
     final Entry<K> top = new Entry<K>((K) s.readObject());
     top.black(true);
     top.right(new Entry<K>((K) s.readObject()));
     top.right.pred(top);
     top.pred(pred);
     top.right.succ(succ);
     return top;
   }
   // The right subtree is the largest one.
   final int rightN = n / 2, leftN = n - rightN - 1;
   final Entry<K> top = new Entry<K>();
   top.left(readTree(s, leftN, pred, top));
   top.key = (K) s.readObject();
   top.black(true);
   top.right(readTree(s, rightN, top, succ));
   if (n + 2 == ((n + 2) & -(n + 2)))
     top.right.black(false); // Quick test for determining whether n + 2 is a power of 2.
   return top;
 }
Exemplo n.º 18
0
 private void readObject(java.io.ObjectInputStream ois)
     throws IOException, ClassNotFoundException {
   this.keystore = (String) ois.readObject();
   this.keypass = (String) ois.readObject();
   this.truststore = (String) ois.readObject();
   this.trustpass = (String) ois.readObject();
 }
Exemplo n.º 19
0
  /**
   * Reconstitutes this object based on the specified InputStream for JDK Serialization.
   *
   * @param in the input stream to use for reading data to populate this object.
   * @throws IOException if the input stream cannot be used.
   * @throws ClassNotFoundException if a required class needed for instantiation is not available in
   *     the present JVM
   * @since 1.0
   */
  @SuppressWarnings({"unchecked"})
  private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
    in.defaultReadObject();
    short bitMask = in.readShort();

    if (isFieldPresent(bitMask, ID_BIT_MASK)) {
      this.id = (Serializable) in.readObject();
    }
    if (isFieldPresent(bitMask, START_TIMESTAMP_BIT_MASK)) {
      this.startTimestamp = (Date) in.readObject();
    }
    if (isFieldPresent(bitMask, STOP_TIMESTAMP_BIT_MASK)) {
      this.stopTimestamp = (Date) in.readObject();
    }
    if (isFieldPresent(bitMask, LAST_ACCESS_TIME_BIT_MASK)) {
      this.lastAccessTime = (Date) in.readObject();
    }
    if (isFieldPresent(bitMask, TIMEOUT_BIT_MASK)) {
      this.timeout = in.readLong();
    }
    if (isFieldPresent(bitMask, EXPIRED_BIT_MASK)) {
      this.expired = in.readBoolean();
    }
    if (isFieldPresent(bitMask, HOST_BIT_MASK)) {
      this.host = in.readUTF();
    }
    if (isFieldPresent(bitMask, ATTRIBUTES_BIT_MASK)) {
      this.attributes = (Map<Object, Object>) in.readObject();
    }
  }
Exemplo n.º 20
0
  /**
   * Deserializes an {@link MBeanFeatureInfo} from an {@link ObjectInputStream}.
   *
   * @serialData For compatibility reasons, an object of this class is deserialized as follows.
   *     <ul>
   *       The method {@link ObjectInputStream#defaultReadObject defaultReadObject()} is called
   *       first to deserialize the object except the field {@code descriptor}, which is not
   *       serialized in the default way. Then the method {@link ObjectInputStream#read read()} is
   *       called to read a byte, the field {@code descriptor} is deserialized according to the
   *       value of the byte value:
   *       <ul>
   *         <li>1. The method {@link ObjectInputStream#readObject readObject()} is called twice to
   *             obtain the field names (a {@code String[]}) and the field values (a {@code
   *             Object[]}) of the {@code descriptor}. The two obtained values then are used to
   *             construct an {@link ImmutableDescriptor} instance for the field {@code descriptor};
   *         <li>0. The value for the field {@code descriptor} is obtained directly by calling the
   *             method {@link ObjectInputStream#readObject readObject()}. If the obtained value is
   *             null, the field {@code descriptor} is set to {@link
   *             ImmutableDescriptor#EMPTY_DESCRIPTOR EMPTY_DESCRIPTOR};
   *         <li>-1. This means that there is no byte to read and that the object is from an earlier
   *             version of the JMX API. The field {@code descriptor} is set to {@link
   *             ImmutableDescriptor#EMPTY_DESCRIPTOR EMPTY_DESCRIPTOR}
   *         <li>Any other value. A {@link StreamCorruptedException} is thrown.
   *       </ul>
   *     </ul>
   *
   * @since 1.6
   */
  private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {

    in.defaultReadObject();

    switch (in.read()) {
      case 1:
        final String[] names = (String[]) in.readObject();

        if (names.length == 0) {
          descriptor = ImmutableDescriptor.EMPTY_DESCRIPTOR;
        } else {
          final Object[] values = (Object[]) in.readObject();
          descriptor = new ImmutableDescriptor(names, values);
        }

        break;
      case 0:
        descriptor = (Descriptor) in.readObject();

        if (descriptor == null) {
          descriptor = ImmutableDescriptor.EMPTY_DESCRIPTOR;
        }

        break;
      case -1: // from an earlier version of the JMX API
        descriptor = ImmutableDescriptor.EMPTY_DESCRIPTOR;

        break;
      default:
        throw new StreamCorruptedException("Got unexpected byte.");
    }
  }
Exemplo n.º 21
0
  /**
   * Loads the user scores data from a given binary file (two UxM sparse matrices that the first
   * holds for each user an array of all the movies ids that the user rated and the second holds all
   * the rating scores the user gave the movies)
   *
   * @param fileName the name of the file that holds the data.
   * @param loadDates mark if a dates model matrix should be loaded from the file in addition to the
   *     other models.
   * @return an array with two elements, the first is a UxM short matrix that containing the movies
   *     ids that each user rated, and the other is a UxM byte matrix containing the rating scores
   *     that each movie got. in case loadDates is set to true, the array will hold another cell
   *     containing a UxM short matrix containing the ratings dates. in case of an error reading the
   *     file, the returned array will be empty (will hold 2/3 uninitialized places).
   */
  public static Object[] loadUserIndexedModel(String fileName, boolean loadDates) {
    ObjectInputStream ois = null;
    Object[] retVal = null;

    if (loadDates) {
      retVal = new Object[3];
    } else {
      retVal = new Object[2];
    }

    try {
      ois = new ObjectInputStream(new FileInputStream(fileName));
      retVal[0] = (short[][]) ois.readObject();
      retVal[1] = (byte[][]) ois.readObject();

      if (loadDates) {
        retVal[2] = (short[][]) ois.readObject();
      }

    } catch (IOException e) {
      e.printStackTrace();
    } catch (ClassNotFoundException e) {
      e.printStackTrace();
    } finally {
      FileUtils.outputClose(ois);
    }

    return retVal;
  }
 private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
   b = in.readInt();
   in.defaultReadObject();
   c = (String) in.readObject();
   d = in.readObject();
   e = (Software) in.readObject();
 }
Exemplo n.º 23
0
  /**
   * java.io.ObjectOutputStream#writeInt(int)
   * java.io.ObjectOutputStream#writeObject(java.lang.Object)
   * java.io.ObjectOutputStream#writeUTF(java.lang.String)
   */
  public void testMixPrimitivesAndObjects() throws Exception {
    int i = 7;
    String s1 = "string 1";
    String s2 = "string 2";
    byte[] bytes = {1, 2, 3};
    try {
      oos = new ObjectOutputStream(bao = new ByteArrayOutputStream());
      oos.writeInt(i);
      oos.writeObject(s1);
      oos.writeUTF(s2);
      oos.writeObject(bytes);
      oos.close();

      ois = new ObjectInputStream(new ByteArrayInputStream(bao.toByteArray()));

      int j = ois.readInt();
      assertTrue("Wrong int :" + j, i == j);

      String l1 = (String) ois.readObject();
      assertTrue("Wrong obj String :" + l1, s1.equals(l1));

      String l2 = ois.readUTF();
      assertTrue("Wrong UTF String :" + l2, s2.equals(l2));

      byte[] bytes2 = (byte[]) ois.readObject();
      assertTrue("Wrong byte[]", Arrays.equals(bytes, bytes2));
    } finally {
      try {
        if (oos != null) oos.close();
        if (ois != null) ois.close();
      } catch (IOException e) {
      }
    }
  }
Exemplo n.º 24
0
  /**
   * Reads a memory object from disk.
   *
   * @param file
   * @return memory object.
   */
  private MemoryObject deserializeMO(File file) {
    // DESERIALIZE
    MemoryObject mo2 = null;
    try {
      // Deserialize from a file
      // File file = new File(path+filename+extension);
      ObjectInputStream in = new ObjectInputStream(new FileInputStream(file));
      // Deserialize the object
      mo2 = (MemoryObject) in.readObject();
      in.close();

      // Get some byte array data
      byte[] bytes = getBytesFromFile(file);
      // see Reading a File into a Byte Array for the implementation of this method

      // Deserialize from a byte array
      in = new ObjectInputStream(new ByteArrayInputStream(bytes));
      mo2 = (MemoryObject) in.readObject();
      in.close();

    } catch (ClassNotFoundException e) {
      System.out.println("Could not deserialize memory object from long term memory.");
    } catch (IOException e) {
      System.out.println("Could not deserialize memory object from long term memory.");
    }
    return mo2;
  }
Exemplo n.º 25
0
 public static void main(String[] args) throws IOException, ClassNotFoundException {
   House house = new House();
   List<Animal> animals = new ArrayList<Animal>();
   animals.add(new Animal("Bosco the dog", house));
   animals.add(new Animal("Ralph the hamster", house));
   animals.add(new Animal("Molly the cat", house));
   print("animals: " + animals);
   ByteArrayOutputStream buf1 = new ByteArrayOutputStream();
   ObjectOutputStream o1 = new ObjectOutputStream(buf1);
   o1.writeObject(animals);
   o1.writeObject(animals); // Write a 2nd set
   // Write to a different stream:
   ByteArrayOutputStream buf2 = new ByteArrayOutputStream();
   ObjectOutputStream o2 = new ObjectOutputStream(buf2);
   o2.writeObject(animals);
   // Now get them back:
   ObjectInputStream in1 = new ObjectInputStream(new ByteArrayInputStream(buf1.toByteArray()));
   ObjectInputStream in2 = new ObjectInputStream(new ByteArrayInputStream(buf2.toByteArray()));
   List animals1 = (List) in1.readObject(),
       animals2 = (List) in1.readObject(),
       animals3 = (List) in2.readObject();
   print("animals1: " + animals1);
   print("animals2: " + animals2);
   print("animals3: " + animals3);
 }
 private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
   int version = in.readInt();
   this.name = (String) in.readObject();
   this.lexicon = (java.util.Vector) in.readObject();
   this.ignoreCase = in.readBoolean();
   this.indvMatch = in.readBoolean();
 }
Exemplo n.º 27
0
  public boolean out(OutStoringpo opo) throws Exception {
    // TODO Auto-generated method stub
    FileInputStream fis = new FileInputStream("src/main/java/data/save/outstock.txt");
    ObjectInputStream ois = new ObjectInputStream(fis);
    @SuppressWarnings("unchecked")
    List<OutStoringpo> list = (List<OutStoringpo>) ois.readObject();
    ois.close();
    list.add(opo);
    FileOutputStream fos = new FileOutputStream("src/main/java/data/save/outstock.txt");
    ObjectOutputStream oos = new ObjectOutputStream(fos);
    oos.writeObject(list);
    oos.close();
    FileInputStream fis1 = new FileInputStream("src/main/java/data/save/instock.txt");
    ObjectInputStream ois1 = new ObjectInputStream(fis1);
    @SuppressWarnings("unchecked")
    List<InStoringpo> list1 = (List<InStoringpo>) ois1.readObject();
    for (int i = 0; i < list1.size(); i++) {
      if (((list1.get(i)).getID()).equals(opo.getID())) {
        list1.remove(i);
        i--;
        // System.out.println("Delete ");
      }
    }
    ois1.close();
    FileOutputStream fos1 = new FileOutputStream("src/main/java/data/save/instock.txt");
    ObjectOutputStream oos1 = new ObjectOutputStream(fos1);
    oos1.writeObject(list1);
    oos1.close();

    return true;
  }
Exemplo n.º 28
0
  static boolean loadDat(String path) {
    //        ByteArray byteArray = ByteArray.createByteArray(path);
    //        if (byteArray == null) return false;
    //
    //        int size = byteArray.nextInt(); // 这两个数组从byte转为int竟然要花4秒钟
    //        start = new int[size];
    //        for (int i = 0; i < size; ++i)
    //        {
    //            start[i] = byteArray.nextInt();
    //        }
    //
    //        size = byteArray.nextInt();
    //        pair = new int[size];
    //        for (int i = 0; i < size; ++i)
    //        {
    //            pair[i] = byteArray.nextInt();
    //        }

    try {
      ObjectInputStream in = new ObjectInputStream(new FileInputStream(path));
      start = (int[]) in.readObject();
      pair = (int[]) in.readObject();
      in.close();
    } catch (Exception e) {
      logger.warning("尝试载入缓存文件" + path + "发生异常[" + e + "],下面将载入源文件并自动缓存……");
      return false;
    }
    return true;
  }
 public static void main(String[] args) throws Exception {
   int choice = 0;
   Socket server = new Socket("127.0.0.1", 1300);
   ObjectOutputStream out = new ObjectOutputStream(server.getOutputStream());
   ObjectInputStream in = new ObjectInputStream(server.getInputStream());
   Scanner scan = new Scanner(System.in);
   while (true) {
     System.out.println("::::::::::::::::::::::::::::::::MENU::::::::::::::::::::::::::::::::::");
     System.out.println("1.Arithmetic Operations\n2.Logical Operations\n3.FileLookUpOperations");
     System.out.println("Enter the choice:");
     choice = scan.nextInt();
     switch (choice) {
       case 1:
         out.writeObject(1);
         System.out.println(in.readObject());
         break;
       case 2:
         out.writeObject(2);
         System.out.println(in.readObject());
         break;
       case 3:
         out.writeObject(3);
         System.out.println(in.readObject());
         break;
       default:
         System.out.println("Invalid Option");
         break;
     }
   }
 }
Exemplo n.º 30
0
  private void readObject(ObjectInputStream stream) throws IOException, ClassNotFoundException {
    stream.defaultReadObject();
    int capacity = stream.readInt();
    if (capacity < 0) {
      throw new InvalidObjectException("Capacity: " + capacity);
    }
    if (capacity < MINIMUM_CAPACITY) {
      capacity = MINIMUM_CAPACITY;
    } else if (capacity > MAXIMUM_CAPACITY) {
      capacity = MAXIMUM_CAPACITY;
    } else {
      capacity = roundUpToPowerOfTwo(capacity);
    }
    makeTable(capacity);

    int size = stream.readInt();
    if (size < 0) {
      throw new InvalidObjectException("Size: " + size);
    }

    for (int i = 0; i < size; i++) {
      @SuppressWarnings("unchecked")
      K key = (K) stream.readObject();
      @SuppressWarnings("unchecked")
      V val = (V) stream.readObject();
      constructorPut(key, val);
    }
  }