Пример #1
0
  /** Create the serversocket and use its stream to receive serialized objects */
  public static void main(String args[]) {

    ServerSocket ser = null;
    Socket soc = null;
    String str = null;
    Date d = null;

    try {
      ser = new ServerSocket(8020);
      /*
       * This will wait for a connection to be made to this socket.
       */
      soc = ser.accept();
      InputStream o = soc.getInputStream();
      ObjectInput s = new ObjectInputStream(o);
      str = (String) s.readObject();
      d = (Date) s.readObject();
      s.close();

      // print out what we just received
      System.out.println(str);
      System.out.println(d);
    } catch (Exception e) {
      System.out.println(e.getMessage());
      System.out.println("Error during serialization");
      System.exit(1);
    }
  }
Пример #2
0
  /** Restores this <code>DataFlavor</code> from a Serialized state. */
  public synchronized void readExternal(ObjectInput is) throws IOException, ClassNotFoundException {
    String rcn = null;
    mimeType = (MimeType) is.readObject();

    if (mimeType != null) {
      humanPresentableName = mimeType.getParameter("humanPresentableName");
      mimeType.removeParameter("humanPresentableName");
      rcn = mimeType.getParameter("class");
      if (rcn == null) {
        throw new IOException("no class parameter specified in: " + mimeType);
      }
    }

    try {
      representationClass = (Class) is.readObject();
    } catch (OptionalDataException ode) {
      if (!ode.eof || ode.length != 0) {
        throw ode;
      }
      // Ensure backward compatibility.
      // Old versions didn't write the representation class to the stream.
      if (rcn != null) {
        representationClass = DataFlavor.tryToLoadClass(rcn, getClass().getClassLoader());
      }
    }
  }
Пример #3
0
 @Override
 public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
   firstName = in.readUTF();
   lastName = in.readUTF();
   age = in.readInt();
   mother = (Person) in.readObject();
   father = (Person) in.readObject();
   children = (ArrayList) in.readObject();
 }
Пример #4
0
  /** {@inheritDoc} */
  @Override
  public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
    depEnabled = in.readBoolean();

    if (depEnabled) {
      topicBytes = U.readByteArray(in);
      predBytes = U.readByteArray(in);
      clsName = U.readString(in);
      depInfo = (GridDeploymentInfoBean) in.readObject();
    } else {
      topic = in.readObject();
      pred = (GridBiPredicate<UUID, Object>) in.readObject();
    }
  }
Пример #5
0
 public Object nativeToJava(TransferData transferData) {
   Object o = null;
   if (transferData == null) {
     getLog().error("transferData is null");
   }
   if (isSupportedType(transferData)) {
     byte[] bs = (byte[]) super.nativeToJava(transferData);
     if (bs != null) {
       ByteArrayInputStream bis = new ByteArrayInputStream(bs);
       ObjectInput in;
       try {
         in = new ObjectInputStream(bis);
         o = in.readObject();
         bis.close();
         in.close();
       } catch (OptionalDataException e) {
         getLog().error("Wrong data", e);
       } catch (IOException | ClassNotFoundException e) {
         getLog().error("Error while transfering dnd object back to java", e);
       }
     } else {
       getLog().error("bs is null");
       if (transferData == null) {
         getLog().error("transferData also");
       }
     }
   }
   return o;
 }
Пример #6
0
  public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
    // esto es solo para serializar tickets que no estan en la bolsa de tickets pendientes
    m_sId = (String) in.readObject();
    tickettype = in.readInt();
    m_iTicketId = in.readInt();
    m_iTicketNCF = in.readInt(); // NCF
    m_Customer = (CustomerInfoExt) in.readObject();
    m_dDate = (Date) in.readObject();
    attributes = (Properties) in.readObject();
    m_aLines = (List<TicketLineInfo>) in.readObject();
    m_User = null;
    m_sActiveCash = null;

    payments = new ArrayList<PaymentInfo>();
    taxes = null;
  }
 @Override
 public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
   int len = in.readInt();
   for (int i = 0; i < len; i++) {
     add(in.readObject());
   }
 }
  /**
   * Serialize an instance, restore it, and check for equality. In addition, test for a bug that was
   * reported where the listener list is 'null' after deserialization.
   */
  public void testSerialization() {

    BarRenderer r1 = new BarRenderer();
    r1.setBaseLegendTextFont(new Font("Dialog", Font.PLAIN, 4));
    r1.setBaseLegendTextPaint(new GradientPaint(1.0f, 2.0f, Color.red, 3.0f, 4.0f, Color.green));
    r1.setBaseLegendShape(new Line2D.Double(1.0, 2.0, 3.0, 4.0));
    BarRenderer r2 = null;

    try {
      ByteArrayOutputStream buffer = new ByteArrayOutputStream();
      ObjectOutput out = new ObjectOutputStream(buffer);
      out.writeObject(r1);
      out.close();

      ObjectInput in = new ObjectInputStream(new ByteArrayInputStream(buffer.toByteArray()));
      r2 = (BarRenderer) in.readObject();
      in.close();
    } catch (Exception e) {
      e.printStackTrace();
    }
    assertEquals(r1, r2);
    try {
      r2.notifyListeners(new RendererChangeEvent(r2));
    } catch (NullPointerException e) {
      assertTrue(false); // failed
    }
  }
  /** {@inheritDoc} */
  @Override
  public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
    GridBiTuple<GridCacheContext, String> t = stash.get();

    t.set1((GridCacheContext) in.readObject());
    t.set2(in.readUTF());
  }
 static void readSlotWithFields(
     short fieldsKey[], ClassMetaDataSlot slot, ObjectInput input, Object obj)
     throws IOException, ClassNotFoundException {
   short numberOfFields = (short) fieldsKey.length;
   for (short i = 0; i < numberOfFields; i++) {
     ClassMetadataField field = slot.getFields()[fieldsKey[i]];
     if (field.getField().getType() == Integer.TYPE) {
       FieldsManager.getFieldsManager().setInt(obj, field, input.readInt());
     } else if (field.getField().getType() == Byte.TYPE) {
       FieldsManager.getFieldsManager().setByte(obj, field, input.readByte());
     } else if (field.getField().getType() == Long.TYPE) {
       FieldsManager.getFieldsManager().setLong(obj, field, input.readLong());
     } else if (field.getField().getType() == Float.TYPE) {
       FieldsManager.getFieldsManager().setFloat(obj, field, input.readFloat());
     } else if (field.getField().getType() == Double.TYPE) {
       FieldsManager.getFieldsManager().setDouble(obj, field, input.readDouble());
     } else if (field.getField().getType() == Short.TYPE) {
       FieldsManager.getFieldsManager().setShort(obj, field, input.readShort());
     } else if (field.getField().getType() == Character.TYPE) {
       FieldsManager.getFieldsManager().setCharacter(obj, field, input.readChar());
     } else if (field.getField().getType() == Boolean.TYPE) {
       FieldsManager.getFieldsManager().setBoolean(obj, field, input.readBoolean());
     } else {
       Object objTmp = input.readObject();
       FieldsManager.getFieldsManager().setObject(obj, field, objTmp);
     }
   }
 }
Пример #11
0
  /**
   * @param in Object input.
   * @return Read collection.
   * @throws IOException If failed.
   * @throws ClassNotFoundException If failed.
   */
  private Collection<Object> readFieldsCollection(ObjectInput in)
      throws IOException, ClassNotFoundException {
    assert fields;

    int size = in.readInt();

    if (size == -1) return null;

    Collection<Object> res = new ArrayList<>(size);

    for (int i = 0; i < size; i++) {
      int size0 = in.readInt();

      Collection<Object> col = new ArrayList<>(size0);

      for (int j = 0; j < size0; j++) col.add(in.readObject());

      assert col.size() == size0;

      res.add(col);
    }

    assert res.size() == size;

    return res;
  }
Пример #12
0
  public void readExternal(ObjectInput in) {

    try {
      String tag = "";

      while (!tag.equals("SKILL END")) {

        tag = (String) in.readObject();

        if (tag.equals("LEVEL")) level = ((Integer) in.readObject()).intValue();
        else if (tag.equals("TIMESUSED")) timesUsed = ((Integer) in.readObject()).intValue();
        else if (!tag.equals("SKILL END")) in.readObject();
      }
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
Пример #13
0
  // Implements Externalizable
  public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {

    // VERSION
    in.readByte();

    // MAP
    _map = (TCharDoubleMap) in.readObject();
  }
  // Implements Externalizable
  @Override
  public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {

    // VERSION
    in.readByte();

    // SET
    _set = (TCharSet) in.readObject();
  }
 public void readExternal(final ObjectInput in) throws IOException, ClassNotFoundException {
   in.readByte();
   int size = in.readInt();
   this.setUp(size);
   while (size-- > 0) {
     final int key = in.readInt();
     final V val = (V) in.readObject();
     this.put(key, val);
   }
 }
Пример #16
0
  public void loadIndex(PreparePlatform platform) {

    // try to load the index of the current author
    try {
      InputStream inStream = new FileInputStream(FileHelper.getIndexTargetPath(author, platform));
      BufferedInputStream bInStream = new BufferedInputStream(inStream);
      ObjectInput input = new ObjectInputStream(bInStream);
      this.tokenCountMap = (HashMap<String, Integer>) input.readObject();
      this.references = (HashMap<String, short[]>) input.readObject();
    } catch (FileNotFoundException fnfe) {
      System.out.println(
          "Could not file find file: " + FileHelper.getIndexTargetPath(author, platform));
    } catch (IOException ioe) {
      System.out.println("Error loading from: " + FileHelper.getIndexTargetPath(author, platform));
    } catch (ClassCastException cce) {
      System.out.println("Error casting class when loading new index");
    } catch (ClassNotFoundException cnfe) {
      System.out.println("Class not found when loading new index");
    }
  }
Пример #17
0
  public static Object byteArray2Object(byte[] b) throws IOException, ClassNotFoundException {
    /*
     * http://stackoverflow.com/questions/2836646/java-serializable-object-to-byte-array
     */
    ByteArrayInputStream bis = new ByteArrayInputStream(b);
    ObjectInput oi = new ObjectInputStream(bis);
    Object nesne = oi.readObject();
    bis.close();
    oi.close();

    return nesne;
  }
Пример #18
0
  private static void readFrom(ObjectInput o, ViewComponentInfo v)
      throws IOException, ClassNotFoundException {
    v.x = o.readInt();
    v.y = o.readInt();
    v.width = o.readInt();
    v.height = o.readInt();
    v.measuredWidth = o.readInt();
    v.measuredHeight = o.readInt();
    v.scrollX = o.readInt();
    v.scrollY = o.readInt();
    v.absoluteX = o.readInt();
    v.absoluteY = o.readInt();
    v.cameraDistance = o.readFloat();
    v.visible = o.readBoolean();
    v.drawingTime = o.readLong();
    v.isShown = o.readBoolean();
    v.hasFocus = o.readBoolean();
    v.focusable = o.readBoolean();
    v.hasOnClickListener = o.readBoolean();
    v.viewType = (String) o.readObject();
    v.textContent = (String) o.readObject();
    v.isEditText = o.readBoolean();
    v.isInputMethodTarget = o.readBoolean();
    v.isContainer = o.readBoolean();
    v.inputMethod = o.readInt();
    v.id = o.readInt();

    int size = o.readInt();
    if (size != 0) {
      v.children = new LinkedList<ViewComponentInfo>();
      for (int i = 0; i < size; i++) {
        ViewComponentInfo c = new ViewComponentInfo();
        readFrom(o, c);
        v.children.add(c);
      }
    }
  }
Пример #19
0
  /** {@inheritDoc} */
  @SuppressWarnings({"unchecked"})
  @Override
  public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
    boolean done = in.readBoolean();

    syncNotify = in.readBoolean();
    concurNotify = in.readBoolean();

    if (!done) valid = false;
    else {
      boolean cancelled = in.readBoolean();

      R res = (R) in.readObject();

      Throwable err = (Throwable) in.readObject();

      synchronized (mux) {
        this.done = done;
        this.cancelled = cancelled;
        this.res = res;
        this.err = err;
      }
    }
  }
Пример #20
0
 private void readFromObjectInput(String filename) {
   try {
     URL url = new URL(getCodeBase(), filename);
     InputStream stream = url.openStream();
     ObjectInput input = new ObjectInputStream(stream);
     fDrawing.release();
     fDrawing = (Drawing) input.readObject();
     view().setDrawing(fDrawing);
   } catch (IOException e) {
     initDrawing();
     showStatus("Error: " + e);
   } catch (ClassNotFoundException e) {
     initDrawing();
     showStatus("Class not found: " + e);
   }
 }
  /** {@inheritDoc} */
  @Override
  public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
    super.readExternal(in);

    topVer = in.readLong();
    implicitTx = in.readBoolean();
    implicitSingleTx = in.readBoolean();
    syncCommit = in.readBoolean();
    syncRollback = in.readBoolean();
    filterBytes = (byte[][]) in.readObject();

    dhtVers = U.readArray(in, CU.versionArrayFactory());

    miniId = U.readGridUuid(in);

    assert miniId != null;
  }
  // read data from a file
  private Object readFile(String file_name) {
    Object contents = null;

    try {
      File file = new File(file_name);
      if (file.exists()) {
        InputStream file_data = new FileInputStream(file_name);
        InputStream buffer = new BufferedInputStream(file_data);
        ObjectInput data_in = new ObjectInputStream(buffer);

        contents = data_in.readObject();
      }
    } catch (Exception e) {
      System.out.println("readFile: Failed to read data in " + file_name);
    }

    return contents;
  }
Пример #23
0
  /** {@inheritDoc} */
  @Override
  public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
    super.readExternal(in);

    futId = U.readGridUuid(in);
    miniId = U.readGridUuid(in);
    entries = U.readCollection(in);
    invalidParts = U.readIntSet(in);

    ver = CU.readVersion(in);

    err = (Throwable) in.readObject();

    if (invalidParts == null) invalidParts = Collections.emptyList();

    assert futId != null;
    assert miniId != null;
    assert ver != null;
  }
Пример #24
0
  private void readExternall(ObjectInput in) throws IOException, ClassNotFoundException {
    {
      int objarrsize = com.devexperts.egen.processor.IOUtils.readCompactInt(in);

      if (objarrsize != -1) {

        objarr = new Object[objarrsize];

        for (int objarrindex = 0; objarrindex < objarrsize; objarrindex++) {

          Object objarrelem = null;

          objarrelem = (Object) in.readObject();

          objarr[objarrindex] = objarrelem;
        }
      }
    }
  }
Пример #25
0
  /** {@inheritDoc} */
  @SuppressWarnings("unchecked")
  @Override
  public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
    id = in.readInt();

    String clsName = in.readUTF();

    if (clsName == null) innerSplit = in.readObject();
    else {
      // Split wrapper only used when classes available in our classpath, so Class.forName is ok
      // here.
      Class<Writable> cls = (Class<Writable>) Class.forName(clsName);

      try {
        innerSplit = U.newInstance(cls);
      } catch (GridException e) {
        throw new IOException(e);
      }

      ((Writable) innerSplit).readFields(in);
    }
  }
Пример #26
0
 @Override
 public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
   fieldName = new String((char[]) in.readObject()).intern();
   curHashCode = fieldName.hashCode();
 }
Пример #27
0
  /** {@inheritDoc} */
  @Override
  public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
    tx = (GridCacheTx) in.readObject();

    gate = null;
  }
Пример #28
0
 public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
   base = (CharSequence) in.readObject();
   start = in.readInt();
   end = in.readInt();
 }
 /** {@inheritDoc} */
 @Override
 public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
   stash.get().set1((GridCacheContext) in.readObject());
   stash.get().set2(in.readUTF());
 }
Пример #30
0
 /** {@inheritDoc} */
 @Override
 public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
   key = (K) in.readObject();
   val = (V) in.readObject();
 }