Exemplo n.º 1
0
  /** DOCUMENT ME! */
  public void loadRaids() {
    File f = new File(REPO);

    if (!f.exists()) {
      return;
    }

    FileInputStream fIn = null;
    ObjectInputStream oIn = null;

    try {
      fIn = new FileInputStream(REPO);
      oIn = new ObjectInputStream(fIn);
      // de-serializing object
      raids = (HashMap<String, GregorianCalendar>) oIn.readObject();
    } catch (IOException e) {
      e.printStackTrace();
    } catch (ClassNotFoundException e) {
      e.printStackTrace();
    } finally {
      try {
        oIn.close();
        fIn.close();
      } catch (IOException e1) {
        e1.printStackTrace();
      }
    }
  }
 public void windowOpened(WindowEvent e) // read file on start
     {
   FileInputStream in = null;
   ObjectInputStream data = null;
   try {
     in = new FileInputStream(DB);
     data = new ObjectInputStream(in);
     p = (Person) data.readObject();
     while (p != null) {
       persons.add(p); // store Person object in ArrayList collection
       p = (Person) data.readObject(); // read the next record
     }
     data.close();
   } catch (Exception ex) {
     // IOException will always occur on the last read above
   } finally {
     if (persons.size() > 0) displayRecord();
   }
 }
Exemplo n.º 3
0
  /** @bug 4110613 */
  public void TestSerialization()
      throws ClassNotFoundException, OptionalDataException, IOException, StreamCorruptedException {
    ObjectOutputStream ostream;
    ByteArrayOutputStream obstream;
    byte[] bytes = null;

    obstream = new ByteArrayOutputStream();
    ostream = new ObjectOutputStream(obstream);

    Locale test1 = new Locale("zh", "TW", "");
    int dummy = test1.hashCode(); // fill in the cached hash-code value
    ostream.writeObject(test1);

    bytes = obstream.toByteArray();

    ObjectInputStream istream = new ObjectInputStream(new ByteArrayInputStream(bytes));

    Locale test2 = (Locale) (istream.readObject());

    if (!test1.equals(test2) || test1.hashCode() != test2.hashCode())
      errln("Locale failed to deserialize correctly.");
  }
    /** Background thread used to receive data from the server. */
    public void run() {
      Long id;
      Integer message_type;
      String target;
      String soap;
      SOAPMonitorData data;
      int selected;
      int row;
      boolean update_needed;
      while (socket != null) {
        try {
          // Get the data from the server
          message_type = (Integer) in.readObject();
          // Process the data depending on its type
          switch (message_type.intValue()) {
            case SOAPMonitorConstants.SOAP_MONITOR_REQUEST:
              // Get the id, target and soap info
              id = (Long) in.readObject();
              target = (String) in.readObject();
              soap = (String) in.readObject();
              // Add new request data to the table
              data = new SOAPMonitorData(id, target, soap);
              model.addData(data);
              // If "most recent" selected then update
              // the details area if needed
              selected = table.getSelectedRow();
              if ((selected == 0) && model.filterMatch(data)) {
                valueChanged(null);
              }
              break;
            case SOAPMonitorConstants.SOAP_MONITOR_RESPONSE:
              // Get the id and soap info
              id = (Long) in.readObject();
              soap = (String) in.readObject();
              data = model.findData(id);
              if (data != null) {
                update_needed = false;
                // Get the selected row
                selected = table.getSelectedRow();
                // If "most recent", then always
                // update details area
                if (selected == 0) {
                  update_needed = true;
                }
                // If the data being updated is
                // selected then update details
                row = model.findRow(data);
                if ((row != -1) && (row == selected)) {
                  update_needed = true;
                }
                // Set the response and update table
                data.setSOAPResponse(soap);
                model.updateData(data);
                // Refresh details area (if needed)
                if (update_needed) {
                  valueChanged(null);
                }
              }
              break;
          }

        } catch (Exception e) {
          // Exceptions are expected here when the
          // server communication has been terminated.
          if (stop_button.isEnabled()) {
            stop();
            setErrorStatus(STATUS_CLOSED);
          }
        }
      }
    }