コード例 #1
0
 public Calendar read(Kryo kryo, Input input, Class<Calendar> type) {
   Calendar result = Calendar.getInstance(timeZoneSerializer.read(kryo, input, TimeZone.class));
   result.setTimeInMillis(input.readLong(true));
   result.setLenient(input.readBoolean());
   result.setFirstDayOfWeek(input.readInt(true));
   result.setMinimalDaysInFirstWeek(input.readInt(true));
   long gregorianChange = input.readLong(false);
   if (gregorianChange != DEFAULT_GREGORIAN_CUTOVER)
     if (result instanceof GregorianCalendar)
       ((GregorianCalendar) result).setGregorianChange(new Date(gregorianChange));
   return result;
 }
コード例 #2
0
ファイル: Kill.java プロジェクト: Kissy/q3-log-parser
 @Override
 public void read(Kryo kryo, Input input) {
   playerId = input.readInt();
   targetId = input.readInt();
   time = input.readLong();
   meanOfDeath = kryo.readObject(input, EnumMeanOfDeath.class);
 }
コード例 #3
0
 @Override
 public HostLocation read(Kryo kryo, Input input, Class<HostLocation> type) {
   DeviceId deviceId = (DeviceId) kryo.readClassAndObject(input);
   PortNumber portNumber = (PortNumber) kryo.readClassAndObject(input);
   long time = input.readLong();
   return new HostLocation(deviceId, portNumber, time);
 }
コード例 #4
0
ファイル: KryoBackedDecoder.java プロジェクト: kensi/gradle
 public long readSmallLong() throws EOFException, IOException {
   try {
     return input.readLong(true);
   } catch (KryoException e) {
     throw maybeEndOfStream(e);
   }
 }
コード例 #5
0
 @Override
 protected VideoChunk readObject(
     Kryo kryo,
     Input input,
     Class<VideoChunk> clas,
     long requestId,
     String streamId,
     long sequenceNr)
     throws Exception {
   long duration = input.readLong();
   int length = input.readInt();
   byte[] video = input.readBytes(length);
   String container = input.readString();
   VideoChunk chunk = new VideoChunk(streamId, sequenceNr, duration, video, container);
   chunk.setRequestId(requestId);
   return chunk;
 }
コード例 #6
0
ファイル: HelloMessage.java プロジェクト: kisorbiswal/ecgine
 @Override
 public void read(Kryo kryo, Input input) {
   super.read(kryo, input);
   this.orgId = input.readShort();
   this.deviceId = input.readLong();
 }
コード例 #7
0
    private void doRead(
        long classId,
        long testId,
        boolean allClassOutput,
        TestOutputEvent.Destination destination,
        java.io.Writer writer) {
      if (dataFile == null) {
        return;
      }

      Index targetIndex = index.children.get(classId);
      if (targetIndex != null && testId != 0) {
        targetIndex = targetIndex.children.get(testId);
      }

      if (targetIndex == null) {
        return;
      }

      boolean stdout = destination == TestOutputEvent.Destination.StdOut;
      Region region = stdout ? targetIndex.stdOut : targetIndex.stdErr;

      if (region.start < 0) {
        return;
      }

      boolean ignoreClassLevel = !allClassOutput && testId != 0;
      boolean ignoreTestLevel = !allClassOutput && testId == 0;

      try {
        dataFile.seek(region.start);

        while (dataFile.getFilePointer() <= region.stop) {
          dataFile.read(recordHeaderBuffer);
          Input input = new Input(recordHeaderBuffer);
          boolean readStdout = input.readBoolean();
          long readClassId = input.readLong();
          long readTestId = input.readLong();
          int readLength = input.readInt();
          input.close();

          boolean isClassLevel = readTestId == 0;

          if (stdout != readStdout || classId != readClassId) {
            dataFile.skipBytes(readLength);
            continue;
          }

          if (ignoreClassLevel && isClassLevel) {
            dataFile.skipBytes(readLength);
            continue;
          }

          if (ignoreTestLevel && !isClassLevel) {
            dataFile.skipBytes(readLength);
            continue;
          }

          if (testId == 0 || testId == readTestId) {
            byte[] stringBytes = new byte[readLength];
            dataFile.read(stringBytes);
            String message;
            try {
              message = new String(stringBytes, messageStorageCharset.name());
            } catch (UnsupportedEncodingException e) {
              // shouldn't happen
              throw UncheckedException.throwAsUncheckedException(e);
            }

            writer.write(message);
          } else {
            dataFile.skipBytes(readLength);
            continue;
          }
        }
      } catch (IOException e1) {
        throw new UncheckedIOException(e1);
      }
    }
コード例 #8
0
    public Reader() {
      File indexFile = getIndexFile();
      File outputsFile = getOutputsFile();

      if (outputsFile.exists()) {
        if (!indexFile.exists()) {
          throw new IllegalStateException(
              String.format(
                  "Test outputs data file '%s' exists but the index file '%s' does not",
                  outputsFile, indexFile));
        }

        Input input;
        try {
          input = new Input(new FileInputStream(indexFile));
        } catch (FileNotFoundException e) {
          throw new UncheckedIOException(e);
        }

        IndexBuilder rootBuilder = null;
        try {
          int numClasses = input.readInt(true);
          rootBuilder = new IndexBuilder();

          for (int classCounter = 0; classCounter < numClasses; ++classCounter) {
            long classId = input.readLong(true);
            IndexBuilder classBuilder = new IndexBuilder();

            int numEntries = input.readInt(true);
            for (int entryCounter = 0; entryCounter < numEntries; ++entryCounter) {
              long testId = input.readLong(true);
              Region stdOut = new Region(input.readLong(), input.readLong());
              Region stdErr = new Region(input.readLong(), input.readLong());
              classBuilder.add(testId, new Index(stdOut, stdErr));
            }

            rootBuilder.add(classId, classBuilder.build());
          }
        } finally {
          input.close();
        }

        index = rootBuilder.build();

        try {
          dataFile = new RandomAccessFile(getOutputsFile(), "r");
        } catch (FileNotFoundException e) {
          throw new UncheckedIOException(e);
        }
      } else { // no outputs file
        if (indexFile.exists()) {
          throw new IllegalStateException(
              String.format(
                  "Test outputs data file '{}' does not exist but the index file '{}' does",
                  outputsFile,
                  indexFile));
        }

        index = null;
        dataFile = null;
      }
    }
コード例 #9
0
 @Override
 public java.sql.Date read(Kryo kryo, Input input, Class<java.sql.Date> clazz) {
   return new java.sql.Date(input.readLong());
 }
コード例 #10
0
 @Override
 public Timestamp read(Kryo kryo, Input input, Class<Timestamp> clazz) {
   Timestamp ts = new Timestamp(input.readLong());
   ts.setNanos(input.readInt());
   return ts;
 }
コード例 #11
0
 public Date read(Kryo kryo, Input input, Class<Date> type) {
   return create(kryo, type, input.readLong(true));
 }
コード例 #12
0
 public Long read(Kryo kryo, Input input, Class<Long> type) {
   return input.readLong(false);
 }
コード例 #13
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));
    }
  }