Esempio n. 1
0
 private void writeObject(ObjectOutputStream out) throws IOException {
   out.writeInt(CURRENT_SERIAL_VERSION);
   out.writeObject(dictionary);
   out.writeInt(features.length);
   for (int i = 0; i < features.length; i++) out.writeInt(features[i]);
   out.writeInt(length);
 }
 /**
  * Serializes the Response into an {@link OutputStream}
  *
  * @param outStream the {@link OutputStream} which write objects to
  * @throws IOException the OutputStream default exception
  */
 public final void serialize(OutputStream outStream) throws IOException {
   ObjectOutputStream out = new ObjectOutputStream(outStream);
   out.writeInt(this.format.ordinal());
   out.writeInt(this.status);
   out.writeObject(this.getBody());
   out.close();
 }
Esempio n. 3
0
 private void writeObject(ObjectOutputStream out) throws IOException {
   out.writeInt(CURRENT_SERIAL_VERSION);
   out.writeObject(prefix);
   out.writeInt(gramSizes.length);
   for (int i = 0; i < gramSizes.length; i++) out.writeInt(gramSizes[i]);
   out.writeBoolean(distinguishBorders);
 }
  public void run() {
    try {
      int playerTurn = 1;

      ObjectInputStream fromPlayer1 = new ObjectInputStream(player1.getInputStream());
      ObjectOutputStream toPlayer1 = new ObjectOutputStream(player1.getOutputStream());
      ObjectInputStream fromPlayer2 = new ObjectInputStream(player2.getInputStream());
      ObjectOutputStream toPlayer2 = new ObjectOutputStream(player2.getOutputStream());

      String[] players = {"Player 1", "Player 2"};
      Color[] colors = {Color.RED, Color.BLUE};
      System.out.println("Starting a new game");
      CantStop game = new CantStop(players, colors);

      // send player numbers
      toPlayer1.writeInt(PLAYER1);
      toPlayer2.writeInt(PLAYER2);

      // send players turn
      toPlayer1.writeInt(playerTurn);
      toPlayer2.writeInt(playerTurn);

      // TODO:start the game*/

    } catch (IOException e) {
      e.printStackTrace();
    }
  }
Esempio n. 5
0
 private void writeObject(java.io.ObjectOutputStream out) throws IOException {
   out.writeObject(name);
   out.writeInt(resourceId);
   out.writeInt(value);
   if (iptv == null) {
     // No POI vector
     out.writeInt(0);
     return;
   }
   long vectorSize = iptv.size();
   out.writeLong(vectorSize);
   Log.d(TAG, "Written vector size: " + vectorSize);
   for (int j = 0; j < vectorSize; j++) {
     Ipoint p = iptv.get(j);
     out.writeFloat(p.getX());
     out.writeFloat(p.getY());
     out.writeFloat(p.getScale());
     out.writeFloat(p.getOrientation());
     out.writeInt(p.getLaplacian());
     out.writeFloat(p.getDx());
     out.writeFloat(p.getDy());
     out.writeInt(p.getClusterIndex());
     out.writeObject(p.getDescriptor());
   }
 }
Esempio n. 6
0
 private void writeObject(ObjectOutputStream out) throws IOException {
   out.writeInt(CURRENT_SERIAL_VERSION);
   out.writeObject(ilist);
   out.writeInt(numTopics);
   out.writeDouble(alpha);
   out.writeDouble(beta);
   out.writeDouble(gamma);
   out.writeDouble(delta);
   out.writeDouble(tAlpha);
   out.writeDouble(vBeta);
   out.writeDouble(vGamma);
   out.writeInt(numTypes);
   out.writeInt(numBitypes);
   out.writeInt(numTokens);
   out.writeInt(biTokens);
   for (int di = 0; di < topics.length; di++)
     for (int si = 0; si < topics[di].length; si++) out.writeInt(topics[di][si]);
   for (int di = 0; di < topics.length; di++)
     for (int si = 0; si < topics[di].length; si++) out.writeInt(grams[di][si]);
   writeIntArray2(docTopicCounts, out);
   for (int fi = 0; fi < numTypes; fi++)
     for (int n = 0; n < 2; n++)
       for (int ti = 0; ti < numTopics; ti++) out.writeInt(typeNgramTopicCounts[fi][n][ti]);
   writeIntArray2(unitypeTopicCounts, out);
   writeIntArray2(bitypeTopicCounts, out);
   for (int ti = 0; ti < numTopics; ti++) out.writeInt(tokensPerTopic[ti]);
   writeIntArray2(bitokensPerTopic, out);
 }
Esempio n. 7
0
 private void writeObject(ObjectOutputStream out) throws IOException {
   out.defaultWriteObject();
   out.writeInt(_data.length);
   for (int i = 0; i < _size; i++) {
     out.writeInt(_data[i]);
   }
 }
  /**
   * Handles serialization.
   *
   * @param stream the output stream.
   * @throws IOException if there is an I/O problem.
   */
  private void writeObject(ObjectOutputStream stream) throws IOException {
    stream.defaultWriteObject();

    int paintCount = this.paintSequence.length;
    stream.writeInt(paintCount);
    for (int i = 0; i < paintCount; i++) {
      SerialUtilities.writePaint(this.paintSequence[i], stream);
    }

    int outlinePaintCount = this.outlinePaintSequence.length;
    stream.writeInt(outlinePaintCount);
    for (int i = 0; i < outlinePaintCount; i++) {
      SerialUtilities.writePaint(this.outlinePaintSequence[i], stream);
    }

    int strokeCount = this.strokeSequence.length;
    stream.writeInt(strokeCount);
    for (int i = 0; i < strokeCount; i++) {
      SerialUtilities.writeStroke(this.strokeSequence[i], stream);
    }

    int outlineStrokeCount = this.outlineStrokeSequence.length;
    stream.writeInt(outlineStrokeCount);
    for (int i = 0; i < outlineStrokeCount; i++) {
      SerialUtilities.writeStroke(this.outlineStrokeSequence[i], stream);
    }

    int shapeCount = this.shapeSequence.length;
    stream.writeInt(shapeCount);
    for (int i = 0; i < shapeCount; i++) {
      SerialUtilities.writeShape(this.shapeSequence[i], stream);
    }
  }
  public static void writeComplete(String filename, InterestPointListInfo ipl) {

    ObjectOutputStream out = null;
    try {
      out = new ObjectOutputStream(new FileOutputStream(filename));
      List<SURFInterestPoint> list = ipl.getList();
      out.writeInt(list.size());
      for (SURFInterestPoint ip : list) {
        out.writeObject(ip);
      }
      out.writeInt(ipl.getWidth());
      out.writeInt(ipl.getHeight());
      out.flush();
    } catch (Exception e) {
      logger.error(e.getMessage());
    } finally {
      if (out != null) {
        try {
          out.close();
        } catch (IOException e) {
          logger.error(e.getMessage());
        }
      }
    }
  }
Esempio n. 10
0
  public static void writeWorkItem(MarshallerWriteContext context, WorkItem workItem)
      throws IOException {
    ObjectOutputStream stream = context.stream;
    stream.writeLong(workItem.getId());
    stream.writeLong(workItem.getProcessInstanceId());
    stream.writeUTF(workItem.getName());
    stream.writeInt(workItem.getState());

    // Work Item Parameters
    Map<String, Object> parameters = workItem.getParameters();
    Collection<Object> notNullValues = new ArrayList<Object>();
    for (Object value : parameters.values()) {
      if (value != null) {
        notNullValues.add(value);
      }
    }

    stream.writeInt(notNullValues.size());
    for (String key : parameters.keySet()) {
      Object object = parameters.get(key);
      if (object != null) {
        stream.writeUTF(key);

        ObjectMarshallingStrategy strategy =
            context.objectMarshallingStrategyStore.getStrategyObject(object);
        String strategyClassName = strategy.getClass().getName();
        stream.writeInt(-2); // backwards compatibility
        stream.writeUTF(strategyClassName);
        if (strategy.accept(object)) {
          strategy.write(stream, object);
        }
      }
    }
  }
Esempio n. 11
0
  public static void writeLeftTuples(
      MarshallerWriteContext context, InternalFactHandle[] factHandles) throws IOException {
    ObjectOutputStream stream = context.stream;
    InternalWorkingMemory wm = context.wm;

    // Write out LeftTuples
    // context.out.println( "LeftTuples Start" );
    for (InternalFactHandle handle : factHandles) {
      // InternalFactHandle handle = (InternalFactHandle) it.next();

      for (LeftTuple leftTuple = handle.getFirstLeftTuple();
          leftTuple != null;
          leftTuple = (LeftTuple) leftTuple.getLeftParentNext()) {
        stream.writeShort(PersisterEnums.LEFT_TUPLE);
        int sinkId = leftTuple.getLeftTupleSink().getId();
        stream.writeInt(sinkId);
        stream.writeInt(handle.getId());

        // context.out.println( "LeftTuple sinkId:" + leftTuple.getLeftTupleSink().getId() + "
        // handleId:" + handle.getId() );
        writeLeftTuple(leftTuple, context, true);
      }
    }

    stream.writeShort(PersisterEnums.END);
    // context.out.println( "LeftTuples End" );
  }
Esempio n. 12
0
 private void writeObject(ObjectOutputStream out) throws IOException {
   int i, size;
   out.writeInt(CURRENT_SERIAL_VERSION);
   out.writeObject(name);
   out.writeInt(index);
   size = (destinationNames == null) ? NULL_INTEGER : destinationNames.length;
   out.writeInt(size);
   if (size != NULL_INTEGER) {
     for (i = 0; i < size; i++) {
       out.writeObject(destinationNames[i]);
     }
   }
   size = (destinations == null) ? NULL_INTEGER : destinations.length;
   out.writeInt(size);
   if (size != NULL_INTEGER) {
     for (i = 0; i < size; i++) {
       out.writeObject(destinations[i]);
     }
   }
   size = (labels == null) ? NULL_INTEGER : labels.length;
   out.writeInt(size);
   if (size != NULL_INTEGER) {
     for (i = 0; i < size; i++) out.writeObject(labels[i]);
   }
   out.writeObject(hmm);
 }
 public void saveView(NetView view) {
   if (viewFile == null) {
     return;
   }
   if (!viewFile.delete() && viewFile.exists()) {
     logger.warn(
         "Peer locator is unable to delete persistent membership information in "
             + viewFile.getAbsolutePath());
   }
   try {
     ObjectOutputStream oos = null;
     try {
       oos = new ObjectOutputStream(new FileOutputStream(viewFile));
       oos.writeInt(LOCATOR_FILE_STAMP);
       oos.writeInt(Version.CURRENT_ORDINAL);
       DataSerializer.writeObject(view, oos);
     } finally {
       oos.flush();
       oos.close();
     }
   } catch (Exception e) {
     logger.warn(
         "Peer locator encountered an error writing current membership to disk.  Disabling persistence.  Care should be taken when bouncing this locator as it will not be able to recover knowledge of the running distributed system",
         e);
     this.viewFile = null;
   }
 }
 private void handleKeepAlive() {
   Connection c = null;
   try {
     netCode = ois.readInt();
     c = checkConnectionNetCode();
     if (c != null && c.getState() == Connection.STATE_CONNECTED) {
       oos.writeInt(ACK_KEEP_ALIVE);
       oos.flush();
       System.out.println("->ACK_KEEP_ALIVE"); // $NON-NLS-1$
     } else {
       System.out.println("->NOT_CONNECTED"); // $NON-NLS-1$
       oos.writeInt(NOT_CONNECTED);
       oos.flush();
     }
   } catch (IOException e) {
     System.out.println("handleKeepAlive: " + e.getMessage()); // $NON-NLS-1$
     if (c != null) {
       c.setState(Connection.STATE_DISCONNECTED);
       System.out.println(
           "Connection closed with "
               + c.getRemoteAddress()
               + //$NON-NLS-1$
               ":"
               + c.getRemotePort()); // $NON-NLS-1$
     }
   }
 }
Esempio n. 15
0
  private void writeObject(ObjectOutputStream objectOutputStream) throws IOException {
    objectOutputStream.defaultWriteObject();

    if (entryData == null) {
      objectOutputStream.writeInt(0);
    } else {
      // Write the capacity and the size.
      //
      objectOutputStream.writeInt(entryData.length);
      objectOutputStream.writeInt(size);

      // Write all the entryData; there will be size of them.
      //
      for (int i = 0; i < entryData.length; ++i) {
        BasicEList<Entry<K, V>> eList = entryData[i];
        if (eList != null) {
          Object[] entries = eList.data;
          int size = eList.size;
          for (int j = 0; j < size; ++j) {
            @SuppressWarnings("unchecked")
            Entry<K, V> entry = (Entry<K, V>) entries[j];
            objectOutputStream.writeObject(entry.getKey());
            objectOutputStream.writeObject(entry.getValue());
          }
        }
      }
    }
  }
  /**
   * Save the state of the Hashtable to a stream (i.e., serialize it).
   *
   * @serialData The <i>capacity</i> of the Hashtable (the length of the bucket array) is emitted
   *     (int), followed by the <i>size</i> of the Hashtable (the number of key-value mappings),
   *     followed by the key (Object) and value (Object) for each key-value mapping represented by
   *     the Hashtable The key-value mappings are emitted in no particular order.
   */
  private void writeObject(java.io.ObjectOutputStream s) throws IOException {
    Entry<Object, Object> entryStack = null;

    synchronized (this) {
      // Write out the threshold and loadFactor
      s.defaultWriteObject();

      // Write out the length and count of elements
      s.writeInt(table.length);
      s.writeInt(count);

      // Stack copies of the entries in the table
      for (Entry<?, ?> entry : table) {

        while (entry != null) {
          entryStack = new Entry<>(0, entry.key, entry.value, entryStack);
          entry = entry.next;
        }
      }
    }

    // Write out the key/value objects from the stacked entries
    while (entryStack != null) {
      s.writeObject(entryStack.key);
      s.writeObject(entryStack.value);
      entryStack = entryStack.next;
    }
  }
Esempio n. 17
0
  private void writeObject(final ObjectOutputStream out) throws IOException {
    out.defaultWriteObject();

    out.writeInt(_length);
    out.writeDouble(_p);
    out.writeInt(_genes.length);
    out.write(_genes);
  }
Esempio n. 18
0
 /**
  * Write the multiset out using a custom routine.
  *
  * @param out the output stream
  * @throws IOException any of the usual I/O related exceptions
  */
 @Override
 protected void doWriteObject(final ObjectOutputStream out) throws IOException {
   out.writeInt(map.size());
   for (final Map.Entry<E, MutableInteger> entry : map.entrySet()) {
     out.writeObject(entry.getKey());
     out.writeInt(entry.getValue().value);
   }
 }
Esempio n. 19
0
  /**
   * Overrides the default serialization operation. Since edge adjacency lists of Nodes are not
   * written out upon serialization, all the information needed to recreate them must be written to
   * the object stream as well. Since the edge list is not written out, and the node does not store
   * its degree explicitly, it must be written to the output stream.
   *
   * @param in Object output stream containing serialized objects.
   * @throws IOException
   * @throws ClassNotFoundException
   */
  private void writeObject(ObjectOutputStream out) throws IOException {

    out.defaultWriteObject();

    // write the degree of the node to the output stream
    out.writeInt(getInDegree());
    out.writeInt(getOutDegree());
  }
Esempio n. 20
0
  public static void writeActivation(
      MarshallerWriteContext context,
      LeftTuple leftTuple,
      AgendaItem agendaItem,
      RuleTerminalNode ruleTerminalNode)
      throws IOException {
    ObjectOutputStream stream = context.stream;

    stream.writeLong(agendaItem.getActivationNumber());

    stream.writeInt(context.terminalTupleMap.get(leftTuple));

    stream.writeInt(agendaItem.getSalience());

    Rule rule = agendaItem.getRule();
    stream.writeUTF(rule.getPackage());
    stream.writeUTF(rule.getName());

    // context.out.println( "Rule " + rule.getPackage() + "." + rule.getName() );

    // context.out.println( "AgendaItem long:" +
    // agendaItem.getPropagationContext().getPropagationNumber() );
    stream.writeLong(agendaItem.getPropagationContext().getPropagationNumber());

    if (agendaItem.getActivationGroupNode() != null) {
      stream.writeBoolean(true);
      // context.out.println( "ActivationGroup bool:" + true );
      stream.writeUTF(agendaItem.getActivationGroupNode().getActivationGroup().getName());
      // context.out.println( "ActivationGroup string:" +
      // agendaItem.getActivationGroupNode().getActivationGroup().getName() );
    } else {
      stream.writeBoolean(false);
      // context.out.println( "ActivationGroup bool:" + false );
    }

    stream.writeBoolean(agendaItem.isActivated());
    // context.out.println( "AgendaItem bool:" + agendaItem.isActivated() );

    if (agendaItem.getFactHandle() != null) {
      stream.writeBoolean(true);
      stream.writeInt(agendaItem.getFactHandle().getId());
    } else {
      stream.writeBoolean(false);
    }

    org.drools.core.util.LinkedList list = agendaItem.getLogicalDependencies();
    if (list != null && !list.isEmpty()) {
      for (LogicalDependency node = (LogicalDependency) list.getFirst();
          node != null;
          node = (LogicalDependency) node.getNext()) {
        stream.writeShort(PersisterEnums.LOGICAL_DEPENDENCY);
        stream.writeInt(((InternalFactHandle) node.getJustified()).getId());
        // context.out.println( "Logical Depenency : int " + ((InternalFactHandle)
        // node.getFactHandle()).getId() );
      }
    }
    stream.writeShort(PersisterEnums.END);
  }
 static <E> void a(Multiset<E> paramMultiset, ObjectOutputStream paramObjectOutputStream) {
   paramObjectOutputStream.writeInt(paramMultiset.a().size());
   Iterator localIterator = paramMultiset.a().iterator();
   while (localIterator.hasNext()) {
     Multiset.Entry localEntry = (Multiset.Entry) localIterator.next();
     paramObjectOutputStream.writeObject(localEntry.a());
     paramObjectOutputStream.writeInt(localEntry.b());
   }
 }
Esempio n. 22
0
 private void writeObject(ObjectOutputStream out) throws IOException {
   out.writeInt(CURRENT_SERIAL_VERSION);
   int size = data.length;
   out.writeInt(size);
   for (int i = 1; i < size; i++) {
     out.writeDouble(data[i]);
   }
   out.writeInt(this.size);
 }
Esempio n. 23
0
 private void writeObject(ObjectOutputStream out) throws IOException {
   out.writeInt(version);
   out.writeObject(textRenderer);
   out.writeObject(chartRenderer);
   out.writeObject(pointLocator);
   out.writeDouble(discardLowLimit);
   out.writeDouble(discardHighLimit);
   SerializationHelper.writeSafeUTF(out, chartColour);
   out.writeInt(plotType);
 }
 /** Adapted from {@link org.apache.commons.collections.map.AbstractHashedMap}. */
 protected void doWriteObject(ObjectOutputStream out) throws IOException {
   out.writeInt(table.length);
   out.writeInt(size);
   for (int i = 0; i < table.length; ++i) {
     Object e = table[i];
     if (e != null) {
       out.writeObject(unmaskNull(e));
     }
   }
 }
Esempio n. 25
0
  // tato metoda zde musi byt, a to z duvodu, aby mohla probehnout spravne serializace
  // zapis objektu do proudu bajtu
  private void writeObject(ObjectOutputStream stream) throws IOException {
    stream.writeInt(userDiscountTypeId);

    // User u = new User(user.getFirstName(), user.getLastName(), user.getUsername(),
    // user.getPassword(), user.getIsDeleted());
    // u.setUserId(user.getUserId());
    // stream.writeObject(u);

    stream.writeInt(isDeleted);
  }
Esempio n. 26
0
 private void writeObject(java.io.ObjectOutputStream out) throws IOException {
   out.writeFloat(_goodness);
   out.writeInt(getWidth());
   out.writeInt(getHeight());
   int[] row = new int[getWidth()];
   for (int y = 0; y < getHeight(); y++) {
     _i.getRGB(0, y, row.length, 1, row, 0, 0);
     out.writeObject(row);
   }
 }
Esempio n. 27
0
 public void writeTo(ObjectOutputStream out) throws java.io.IOException {
   checkBuild();
   out.writeObject(wordClasses);
   out.writeObject(wordClassMap);
   out.writeObject(skipHeader);
   out.writeObject(values);
   out.writeInt(interpretationCountBits);
   out.writeInt(interpretationLengthBits);
   out.writeInt(valueCountBits);
   out.writeInt(valuePointerBits);
   out.writeInt(wordClassBits);
   out.writeInt(wordClassCount);
   out.writeInt(maxFreeValueCount);
   int entryCount = entries.length;
   out.writeInt(entryCount);
   UNKNOWN.writeTo(out);
   UNKNOWN_WORD_UPPER.writeTo(out);
   UNKNOWN_WORD_LOWER.writeTo(out);
   CHAR.writeTo(out);
   NUMBER.writeTo(out);
   for (int i = 0; i < entryCount; i++) {
     out.writeInt(hashCodes[i]);
     entries[i].writeTo(out);
   }
 }
Esempio n. 28
0
  private static void writeFactHandle(
      MarshallerWriteContext context,
      ObjectOutputStream stream,
      ObjectMarshallingStrategyStore objectMarshallingStrategyStore,
      int type,
      InternalFactHandle handle)
      throws IOException {
    stream.writeInt(type);
    stream.writeInt(handle.getId());
    stream.writeLong(handle.getRecency());

    if (type == 2) {
      // is event
      EventFactHandle efh = (EventFactHandle) handle;
      stream.writeLong(efh.getStartTimestamp());
      stream.writeLong(efh.getDuration());
      stream.writeBoolean(efh.isExpired());
      stream.writeLong(efh.getActivationsCount());
    }

    // context.out.println( "Object : int:" + handle.getId() + " long:" + handle.getRecency() );
    // context.out.println( handle.getObject() );

    Object object = handle.getObject();

    // Old versions wrote -1 and tested >= 0 to see if there was a strategy available
    // Now, we write -2 to indicate that we write the strategy class name to the stream
    stream.writeInt(-2);
    if (object != null) {
      ObjectMarshallingStrategy strategy = objectMarshallingStrategyStore.getStrategyObject(object);

      String strategyClassName = strategy.getClass().getName();
      stream.writeUTF(strategyClassName);

      strategy.write(stream, object);
    } else {
      stream.writeUTF("");
    }

    if (handle.getEntryPoint() instanceof InternalWorkingMemoryEntryPoint) {
      String entryPoint =
          ((InternalWorkingMemoryEntryPoint) handle.getEntryPoint())
              .getEntryPoint()
              .getEntryPointId();
      if (entryPoint != null && !entryPoint.equals("")) {
        stream.writeBoolean(true);
        stream.writeUTF(entryPoint);
      } else {
        stream.writeBoolean(false);
      }
    } else {
      stream.writeBoolean(false);
    }
  }
 static <K, V> void a(Multimap<K, V> paramMultimap, ObjectOutputStream paramObjectOutputStream) {
   paramObjectOutputStream.writeInt(paramMultimap.b().size());
   Iterator localIterator1 = paramMultimap.b().entrySet().iterator();
   while (localIterator1.hasNext()) {
     Map.Entry localEntry = (Map.Entry) localIterator1.next();
     paramObjectOutputStream.writeObject(localEntry.getKey());
     paramObjectOutputStream.writeInt(((Collection) localEntry.getValue()).size());
     Iterator localIterator2 = ((Collection) localEntry.getValue()).iterator();
     while (localIterator2.hasNext()) paramObjectOutputStream.writeObject(localIterator2.next());
   }
 }
Esempio n. 30
0
  private void writeObject(java.io.ObjectOutputStream out) throws IOException {
    out.defaultWriteObject();

    if (userDefinedSchema != null) {
      byte[] json = userDefinedSchema.toString().getBytes();
      out.writeInt(json.length);
      out.write(json);
    } else {
      out.writeInt(0);
    }
  }