コード例 #1
0
 public void write(Kryo kryo, Output output, Calendar object) {
   timeZoneSerializer.write(kryo, output, object.getTimeZone()); // can't be null
   output.writeLong(object.getTimeInMillis(), true);
   output.writeBoolean(object.isLenient());
   output.writeInt(object.getFirstDayOfWeek(), true);
   output.writeInt(object.getMinimalDaysInFirstWeek(), true);
   if (object instanceof GregorianCalendar)
     output.writeLong(((GregorianCalendar) object).getGregorianChange().getTime(), false);
   else output.writeLong(DEFAULT_GREGORIAN_CUTOVER, false);
 }
コード例 #2
0
ファイル: Kill.java プロジェクト: Kissy/q3-log-parser
 @Override
 public void write(Kryo kryo, Output output) {
   output.writeInt(player.getId());
   output.writeInt(target.getId());
   output.writeLong(time);
   kryo.writeObject(output, meanOfDeath);
 }
コード例 #3
0
 @Override
 protected void writeObject(Kryo kryo, Output output, VideoChunk video) throws Exception {
   output.writeLong(video.getDuration());
   output.writeInt(video.getVideo().length);
   output.writeBytes(video.getVideo());
   output.writeString(video.getContainer());
 }
コード例 #4
0
    public void onOutput(long classId, long testId, TestOutputEvent outputEvent) {
      boolean stdout = outputEvent.getDestination() == TestOutputEvent.Destination.StdOut;
      mark(classId, testId, stdout);

      output.writeBoolean(stdout);
      output.writeLong(classId);
      output.writeLong(testId);

      byte[] bytes;
      try {
        bytes = outputEvent.getMessage().getBytes(messageStorageCharset.name());
      } catch (UnsupportedEncodingException e) {
        throw UncheckedException.throwAsUncheckedException(e);
      }
      output.writeInt(bytes.length);
      output.writeBytes(bytes);
    }
コード例 #5
0
    private void writeIndex() {
      Output indexOutput;
      try {
        indexOutput = new Output(new FileOutputStream(getIndexFile()));
      } catch (FileNotFoundException e) {
        throw new UncheckedIOException(e);
      }

      try {
        indexOutput.writeInt(index.size(), true);

        for (Map.Entry<Long, Map<Long, TestCaseRegion>> classEntry : index.entrySet()) {
          Long classId = classEntry.getKey();
          Map<Long, TestCaseRegion> regions = classEntry.getValue();

          indexOutput.writeLong(classId, true);
          indexOutput.writeInt(regions.size(), true);

          for (Map.Entry<Long, TestCaseRegion> testCaseEntry : regions.entrySet()) {
            long id = testCaseEntry.getKey();
            TestCaseRegion region = testCaseEntry.getValue();
            indexOutput.writeLong(id, true);
            indexOutput.writeLong(region.stdOutRegion.start);
            indexOutput.writeLong(region.stdOutRegion.stop);
            indexOutput.writeLong(region.stdErrRegion.start);
            indexOutput.writeLong(region.stdErrRegion.stop);
          }
        }
      } finally {
        indexOutput.close();
      }
    }
コード例 #6
0
  /**
   * @@@ in the furture, it will skill serialize 'targetTask' through check some flag
   *
   * @see ITupleSerializer#serialize(int, Tuple)
   */
  private void serializeTuple(Output output, Tuple tuple) {
    try {
      if (tuple instanceof TupleExt) {
        output.writeInt(((TupleExt) tuple).getTargetTaskId());
        output.writeLong(((TupleExt) tuple).getCreationTimeStamp());
      }

      output.writeInt(tuple.getSourceTask(), true);
      output.writeInt(
          _ids.getStreamId(tuple.getSourceComponent(), tuple.getSourceStreamId()), true);
      tuple.getMessageId().serialize(output);
      _kryo.serializeInto(tuple.getValues(), output);
    } catch (IOException e) {
      throw new RuntimeException(e);
    }
  }
コード例 #7
0
 @Override
 public void write(Kryo kryo, Output output, HostLocation object) {
   kryo.writeClassAndObject(output, object.deviceId());
   kryo.writeClassAndObject(output, object.port());
   output.writeLong(object.time());
 }
コード例 #8
0
ファイル: HelloMessage.java プロジェクト: kisorbiswal/ecgine
 @Override
 public void write(Kryo kryo, Output output) {
   super.write(kryo, output);
   output.writeShort(orgId);
   output.writeLong(deviceId);
 }
コード例 #9
0
 public void writeLong(long value) {
   output.writeLong(value);
 }
コード例 #10
0
 @Override
 public void write(Kryo kryo, Output output, java.sql.Date sqlDate) {
   output.writeLong(sqlDate.getTime());
 }
コード例 #11
0
 @Override
 public void write(Kryo kryo, Output output, Timestamp ts) {
   output.writeLong(ts.getTime());
   output.writeInt(ts.getNanos());
 }
コード例 #12
0
 public void write(Kryo kryo, Output output, Date object) {
   output.writeLong(object.getTime(), true);
 }
コード例 #13
0
 public void write(Kryo kryo, Output output, Long object) {
   output.writeLong(object, false);
 }
コード例 #14
0
ファイル: InputOutputTest.java プロジェクト: esialb/kryo
  private void runLongTest(Output write) throws IOException {
    write.writeLong(0);
    write.writeLong(63);
    write.writeLong(64);
    write.writeLong(127);
    write.writeLong(128);
    write.writeLong(8192);
    write.writeLong(16384);
    write.writeLong(2097151);
    write.writeLong(1048575);
    write.writeLong(134217727);
    write.writeLong(268435455);
    write.writeLong(134217728);
    write.writeLong(268435456);
    write.writeLong(-2097151);
    write.writeLong(-1048575);
    write.writeLong(-134217727);
    write.writeLong(-268435455);
    write.writeLong(-134217728);
    write.writeLong(-268435456);
    assertEquals(1, write.writeLong(0, true));
    assertEquals(1, write.writeLong(0, false));
    assertEquals(1, write.writeLong(63, true));
    assertEquals(1, write.writeLong(63, false));
    assertEquals(1, write.writeLong(64, true));
    assertEquals(2, write.writeLong(64, false));
    assertEquals(1, write.writeLong(127, true));
    assertEquals(2, write.writeLong(127, false));
    assertEquals(2, write.writeLong(128, true));
    assertEquals(2, write.writeLong(128, false));
    assertEquals(2, write.writeLong(8191, true));
    assertEquals(2, write.writeLong(8191, false));
    assertEquals(2, write.writeLong(8192, true));
    assertEquals(3, write.writeLong(8192, false));
    assertEquals(2, write.writeLong(16383, true));
    assertEquals(3, write.writeLong(16383, false));
    assertEquals(3, write.writeLong(16384, true));
    assertEquals(3, write.writeLong(16384, false));
    assertEquals(3, write.writeLong(2097151, true));
    assertEquals(4, write.writeLong(2097151, false));
    assertEquals(3, write.writeLong(1048575, true));
    assertEquals(3, write.writeLong(1048575, false));
    assertEquals(4, write.writeLong(134217727, true));
    assertEquals(4, write.writeLong(134217727, false));
    assertEquals(4, write.writeLong(268435455l, true));
    assertEquals(5, write.writeLong(268435455l, false));
    assertEquals(4, write.writeLong(134217728l, true));
    assertEquals(5, write.writeLong(134217728l, false));
    assertEquals(5, write.writeLong(268435456l, true));
    assertEquals(5, write.writeLong(268435456l, false));
    assertEquals(1, write.writeLong(-64, false));
    assertEquals(9, write.writeLong(-64, true));
    assertEquals(2, write.writeLong(-65, false));
    assertEquals(9, write.writeLong(-65, true));
    assertEquals(2, write.writeLong(-8192, false));
    assertEquals(9, write.writeLong(-8192, true));
    assertEquals(3, write.writeLong(-1048576, false));
    assertEquals(9, write.writeLong(-1048576, true));
    assertEquals(4, write.writeLong(-134217728, false));
    assertEquals(9, write.writeLong(-134217728, true));
    assertEquals(5, write.writeLong(-134217729, false));
    assertEquals(9, write.writeLong(-134217729, true));

    Input read = new Input(write.toBytes());
    assertEquals(0, read.readLong());
    assertEquals(63, read.readLong());
    assertEquals(64, read.readLong());
    assertEquals(127, read.readLong());
    assertEquals(128, read.readLong());
    assertEquals(8192, read.readLong());
    assertEquals(16384, read.readLong());
    assertEquals(2097151, read.readLong());
    assertEquals(1048575, read.readLong());
    assertEquals(134217727, read.readLong());
    assertEquals(268435455, read.readLong());
    assertEquals(134217728, read.readLong());
    assertEquals(268435456, read.readLong());
    assertEquals(-2097151, read.readLong());
    assertEquals(-1048575, read.readLong());
    assertEquals(-134217727, read.readLong());
    assertEquals(-268435455, read.readLong());
    assertEquals(-134217728, read.readLong());
    assertEquals(-268435456, read.readLong());
    assertEquals(0, read.readLong(true));
    assertEquals(0, read.readLong(false));
    assertEquals(63, read.readLong(true));
    assertEquals(63, read.readLong(false));
    assertEquals(64, read.readLong(true));
    assertEquals(64, read.readLong(false));
    assertEquals(127, read.readLong(true));
    assertEquals(127, read.readLong(false));
    assertEquals(128, read.readLong(true));
    assertEquals(128, read.readLong(false));
    assertEquals(8191, read.readLong(true));
    assertEquals(8191, read.readLong(false));
    assertEquals(8192, read.readLong(true));
    assertEquals(8192, read.readLong(false));
    assertEquals(16383, read.readLong(true));
    assertEquals(16383, read.readLong(false));
    assertEquals(16384, read.readLong(true));
    assertEquals(16384, read.readLong(false));
    assertEquals(2097151, read.readLong(true));
    assertEquals(2097151, read.readLong(false));
    assertEquals(1048575, read.readLong(true));
    assertEquals(1048575, read.readLong(false));
    assertEquals(134217727, read.readLong(true));
    assertEquals(134217727, read.readLong(false));
    assertEquals(268435455, read.readLong(true));
    assertEquals(268435455, read.readLong(false));
    assertEquals(134217728, read.readLong(true));
    assertEquals(134217728, read.readLong(false));
    assertEquals(268435456, read.readLong(true));
    assertEquals(268435456, read.readLong(false));
    assertEquals(-64, read.readLong(false));
    assertEquals(-64, read.readLong(true));
    assertEquals(-65, read.readLong(false));
    assertEquals(-65, read.readLong(true));
    assertEquals(-8192, read.readLong(false));
    assertEquals(-8192, read.readLong(true));
    assertEquals(-1048576, read.readLong(false));
    assertEquals(-1048576, read.readLong(true));
    assertEquals(-134217728, read.readLong(false));
    assertEquals(-134217728, read.readLong(true));
    assertEquals(-134217729, read.readLong(false));
    assertEquals(-134217729, read.readLong(true));

    Random random = new Random();
    for (int i = 0; i < 10000; i++) {
      long value = random.nextLong();
      write.clear();
      write.writeLong(value);
      write.writeLong(value, true);
      write.writeLong(value, false);
      read.setBuffer(write.toBytes());
      assertEquals(value, read.readLong());
      assertEquals(value, read.readLong(true));
      assertEquals(value, read.readLong(false));
    }
  }