/**
   * @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;
  }
Esempio n. 2
0
  @Override
  public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
    int len = in.readInt();
    byte[] b = new byte[len];

    // read fully
    int done = 0;
    while (done < len) {
      int got = in.read(b, done, len - done);
      if (got < 0) throw new IOException();
      done += got;
    }

    FileSystemProto.Directory proto = FileSystemProto.Directory.parseFrom(b);

    path = proto.getPath();
    lastModified = proto.getLastModified();
    List<FileSystemProto.File> files = proto.getFilesList();
    children = new CacheFileProto[files.size()];
    for (int i = 0; i < files.size(); i++) {
      FileSystemProto.File fp = files.get(i);
      CacheFileProto cf = new CacheFileProto();
      cf.setShortName(fp.getName());
      cf.setDirectory(fp.getIsDirectory());
      cf.setLastModified(fp.getLastModified());
      cf.setLength(fp.getLength());

      children[i] = cf;
    }
  }
Esempio n. 3
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);
    }
  }
Esempio n. 4
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());
      }
    }
  }
 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;
 }
  /** {@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());
  }
 @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
    }
  }
  // Implements Externalizable
  public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {

    // VERSION
    in.readByte();

    // MAP
    _map = (TCharDoubleMap) in.readObject();
  }
 public void readExternal(final ObjectInput in) throws IOException, ClassNotFoundException {
   in.readByte();
   this._pos = in.readInt();
   final int len = in.readInt();
   this._data = new short[len];
   for (int i = 0; i < len; ++i) {
     this._data[i] = in.readShort();
   }
 }
Esempio n. 11
0
 @Override
 public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
   this.baseOffset = BYTE_ARRAY_OFFSET;
   this.sizeInBytes = in.readInt();
   this.numFields = in.readInt();
   this.bitSetWidthInBytes = calculateBitSetWidthInBytes(numFields);
   this.baseObject = new byte[sizeInBytes];
   in.readFully((byte[]) baseObject);
 }
  // 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 val = in.readInt();
     this.add(val);
   }
 }
Esempio n. 14
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();
 }
 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);
   }
 }
 @Override
 public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
   // little endian
   this.cardinality = 0xFFFF & Short.reverseBytes(in.readShort());
   if (this.content.limit() < this.cardinality)
     this.content = ShortBuffer.allocate(this.cardinality);
   for (int k = 0; k < this.cardinality; ++k) {
     this.content.put(k, Short.reverseBytes(in.readShort()));
   }
 }
  /** {@inheritDoc} */
  @Override
  public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
    jobName = U.readString(in);
    user = U.readString(in);

    hasCombiner = in.readBoolean();
    numReduces = in.readInt();

    props = U.readStringMap(in);
  }
 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);
     }
   }
 }
 @Override
 public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
   int v1 = in.readInt();
   int v2 = in.readInt();
   int v3 = in.readInt();
   bytes1 = new byte[v2];
   in.readFully(bytes1);
   bytes2 = new byte[v3];
   in.readFully(bytes2);
   int v4 = 0;
 }
Esempio n. 20
0
 protected void readPackager(ObjectInput in) throws IOException, ClassNotFoundException {
   byte[] b = new byte[in.readShort()];
   in.readFully(b);
   try {
     Class mypClass = Class.forName(new String(b));
     ISOPackager myp = (ISOPackager) mypClass.newInstance();
     setPackager(myp);
   } catch (Exception e) {
     setPackager(null);
   }
 }
Esempio n. 21
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;
  }
  /** {@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();
    }
  }
  /** {@inheritDoc} */
  @Override
  public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
    super.readExternal(in);

    threadId = in.readLong();
    commit = in.readBoolean();
    invalidate = in.readBoolean();
    reply = in.readBoolean();

    futId = U.readGridUuid(in);
    commitVer = CU.readVersion(in);
    baseVer = CU.readVersion(in);

    writeEntries = U.readList(in);
  }
Esempio n. 24
0
  public static LiveRef read(ObjectInput in, boolean useNewFormat)
      throws IOException, ClassNotFoundException {
    Endpoint ep;
    ObjID id;

    // Now read in the endpoint, id, and result flag
    // (need to choose whether or not to read old JDK1.1 endpoint format)
    if (useNewFormat) {
      ep = TCPEndpoint.read(in);
    } else {
      ep = TCPEndpoint.readHostPortFormat(in);
    }
    id = ObjID.read(in);
    boolean isResultStream = in.readBoolean();

    LiveRef ref = new LiveRef(id, ep, false);

    if (in instanceof ConnectionInputStream) {
      ConnectionInputStream stream = (ConnectionInputStream) in;
      // save ref to send "dirty" call after all args/returns
      // have been unmarshaled.
      stream.saveRef(ref);
      if (isResultStream) {
        // set flag in stream indicating that remote objects were
        // unmarshaled.  A DGC ack should be sent by the transport.
        stream.setAckNeeded();
      }
    } else {
      DGCClient.registerRefs(ep, Arrays.asList(new LiveRef[] {ref}));
    }

    return ref;
  }
Esempio n. 25
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);
   }
 }
Esempio n. 26
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();
    }
  }
Esempio n. 27
0
  /** {@inheritDoc} */
  public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
    // VERSION
    in.readByte();

    // SUPER
    super.readExternal(in);

    // NUMBER OF ENTRIES
    int size = in.readInt();
    setUp(size);

    // ENTRIES
    while (size-- > 0) {
      int key = in.readInt();
      int val = in.readInt();
      put(key, val);
    }
  }
  // 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;
  }
  /** {@inheritDoc} */
  @Override
  public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
    nodeId = GridUtils.readUuid(in);

    ver = CU.readVersion(in);

    timeout = in.readLong();
    threadId = in.readLong();
    id = in.readLong();

    short flags = in.readShort();

    mask(OWNER, OWNER.get(flags));
    mask(USED, USED.get(flags));
    mask(TX, TX.get(flags));

    ts = U.currentTimeMillis();
  }
Esempio n. 30
0
 public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
   in.readByte(); // ignore version for now
   fieldNumber = in.readShort();
   byte fieldType;
   ISOComponent c;
   try {
     while ((fieldType = in.readByte()) != 'E') {
       c = null;
       switch (fieldType) {
         case 'F':
           c = new ISOField();
           break;
         case 'A':
           c = new ISOAmount();
           break;
         case 'B':
           c = new ISOBinaryField();
           break;
         case 'M':
           c = new ISOMsg();
           break;
         case 'H':
           readHeader(in);
           break;
         case 'P':
           readPackager(in);
           break;
         case 'D':
           readDirection(in);
           break;
         default:
           throw new IOException("malformed ISOMsg");
       }
       if (c != null) {
         ((Externalizable) c).readExternal(in);
         set(c);
       }
     }
   } catch (ISOException e) {
     throw new IOException(e.getMessage());
   }
 }