Ejemplo n.º 1
0
    @Override
    public void read(Kryo kryo, Input input) {
      objectID = input.readInt(true);

      int methodClassID = input.readInt(true);
      Class methodClass = kryo.getRegistration(methodClassID).getType();
      byte methodIndex = input.readByte();
      CachedMethod cachedMethod;
      try {
        cachedMethod = getMethods(kryo, methodClass)[methodIndex];
      } catch (IndexOutOfBoundsException ex) {
        throw new KryoException(
            "Invalid method index " + methodIndex + " for class: " + methodClass.getName());
      }
      method = cachedMethod.method;

      args = new Object[cachedMethod.serializers.length];
      for (int i = 0, n = args.length; i < n; i++) {
        Serializer serializer = cachedMethod.serializers[i];
        if (serializer != null) {
          args[i] = kryo.readObjectOrNull(input, method.getParameterTypes()[i], serializer);
        } else {
          args[i] = kryo.readClassAndObject(input);
        }
      }

      responseID = input.readByte();
    }
Ejemplo n.º 2
0
 @Override
 public void read(Kryo kryo, Input in) {
   this.baseOffset = BYTE_ARRAY_OFFSET;
   this.sizeInBytes = in.readInt();
   this.numFields = in.readInt();
   this.bitSetWidthInBytes = calculateBitSetWidthInBytes(numFields);
   this.baseObject = new byte[sizeInBytes];
   in.read((byte[]) baseObject);
 }
Ejemplo n.º 3
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;
 }
Ejemplo n.º 4
0
 public BigDecimal read(Kryo kryo, Input input, Class<BigDecimal> type) {
   BigInteger unscaledValue = bigIntegerSerializer.read(kryo, input, BigInteger.class);
   if (unscaledValue == null) return null;
   int scale = input.readInt(false);
   if (type != BigDecimal.class && type != null) {
     // For subclasses, use reflection
     try {
       Constructor<BigDecimal> constructor = type.getConstructor(BigInteger.class, int.class);
       if (!constructor.isAccessible()) {
         try {
           constructor.setAccessible(true);
         } catch (SecurityException se) {
         }
       }
       return constructor.newInstance(unscaledValue, scale);
     } catch (Exception ex) {
       throw new KryoException(ex);
     }
   }
   // fast-path optimizations for BigDecimal constants
   if (unscaledValue == BigInteger.ZERO && scale == 0) {
     return BigDecimal.ZERO;
   }
   // default behaviour
   return new BigDecimal(unscaledValue, scale);
 }
Ejemplo n.º 5
0
 @Override
 public void read(Kryo kryo, Input input) {
   playerId = input.readInt();
   targetId = input.readInt();
   time = input.readLong();
   meanOfDeath = kryo.readObject(input, EnumMeanOfDeath.class);
 }
Ejemplo n.º 6
0
 @Override
 public void read(Kryo kryo, Input in) {
   this.offset = BYTE_ARRAY_OFFSET;
   this.numBytes = in.readInt();
   this.base = new byte[numBytes];
   in.read((byte[]) base);
 }
Ejemplo n.º 7
0
 public int readSmallInt() throws EOFException {
   try {
     return input.readInt(true);
   } catch (KryoException e) {
     throw maybeEndOfStream(e);
   }
 }
Ejemplo n.º 8
0
 public EnumSet read(Kryo kryo, Input input, Class<EnumSet> type) {
   Registration registration = kryo.readClass(input);
   EnumSet object = EnumSet.noneOf(registration.getType());
   Serializer serializer = registration.getSerializer();
   int length = input.readInt(true);
   for (int i = 0; i < length; i++) object.add(serializer.read(kryo, input, null));
   return object;
 }
Ejemplo n.º 9
0
 public byte[] readBinary() throws IOException {
   try {
     int length = input.readInt(true);
     byte[] result = new byte[length];
     input.readBytes(result);
     return result;
   } catch (KryoException e) {
     throw maybeEndOfStream(e);
   }
 }
 @Override
 public void read(Kryo kryo, Input input) {
   this.firstname = input.readString();
   this.lastname = input.readString();
   this.emailAddress = kryo.readObjectOrNull(input, SerializableEmailAddress.class);
   this.addresses = new HashSet<Address>();
   int numAddresses = input.readInt();
   for (int i = 0; i < numAddresses; i++) {
     this.add(kryo.readObject(input, SerializableAddress.class));
   }
 }
Ejemplo n.º 11
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;
 }
Ejemplo n.º 12
0
 @Override
 public List<?> read(final Kryo kryo, final Input input, final Class<List<?>> type) {
   final int length = input.readInt(true);
   Class<?> componentType = kryo.readClass(input).getType();
   if (componentType.isPrimitive()) {
     componentType = getPrimitiveWrapperClass(componentType);
   }
   try {
     final Object items = Array.newInstance(componentType, length);
     for (int i = 0; i < length; i++) {
       Array.set(items, i, kryo.readClassAndObject(input));
     }
     return Arrays.asList((Object[]) items);
   } catch (final Exception e) {
     throw new RuntimeException(e);
   }
 }
Ejemplo n.º 13
0
  private void runIntTest(Output write) throws IOException {
    write.writeInt(0);
    write.writeInt(63);
    write.writeInt(64);
    write.writeInt(127);
    write.writeInt(128);
    write.writeInt(8192);
    write.writeInt(16384);
    write.writeInt(2097151);
    write.writeInt(1048575);
    write.writeInt(134217727);
    write.writeInt(268435455);
    write.writeInt(134217728);
    write.writeInt(268435456);
    write.writeInt(-2097151);
    write.writeInt(-1048575);
    write.writeInt(-134217727);
    write.writeInt(-268435455);
    write.writeInt(-134217728);
    write.writeInt(-268435456);
    assertEquals(1, write.writeInt(0, true));
    assertEquals(1, write.writeInt(0, false));
    assertEquals(1, write.writeInt(63, true));
    assertEquals(1, write.writeInt(63, false));
    assertEquals(1, write.writeInt(64, true));
    assertEquals(2, write.writeInt(64, false));
    assertEquals(1, write.writeInt(127, true));
    assertEquals(2, write.writeInt(127, false));
    assertEquals(2, write.writeInt(128, true));
    assertEquals(2, write.writeInt(128, false));
    assertEquals(2, write.writeInt(8191, true));
    assertEquals(2, write.writeInt(8191, false));
    assertEquals(2, write.writeInt(8192, true));
    assertEquals(3, write.writeInt(8192, false));
    assertEquals(2, write.writeInt(16383, true));
    assertEquals(3, write.writeInt(16383, false));
    assertEquals(3, write.writeInt(16384, true));
    assertEquals(3, write.writeInt(16384, false));
    assertEquals(3, write.writeInt(2097151, true));
    assertEquals(4, write.writeInt(2097151, false));
    assertEquals(3, write.writeInt(1048575, true));
    assertEquals(3, write.writeInt(1048575, false));
    assertEquals(4, write.writeInt(134217727, true));
    assertEquals(4, write.writeInt(134217727, false));
    assertEquals(4, write.writeInt(268435455, true));
    assertEquals(5, write.writeInt(268435455, false));
    assertEquals(4, write.writeInt(134217728, true));
    assertEquals(5, write.writeInt(134217728, false));
    assertEquals(5, write.writeInt(268435456, true));
    assertEquals(5, write.writeInt(268435456, false));
    assertEquals(1, write.writeInt(-64, false));
    assertEquals(5, write.writeInt(-64, true));
    assertEquals(2, write.writeInt(-65, false));
    assertEquals(5, write.writeInt(-65, true));
    assertEquals(2, write.writeInt(-8192, false));
    assertEquals(5, write.writeInt(-8192, true));
    assertEquals(3, write.writeInt(-1048576, false));
    assertEquals(5, write.writeInt(-1048576, true));
    assertEquals(4, write.writeInt(-134217728, false));
    assertEquals(5, write.writeInt(-134217728, true));
    assertEquals(5, write.writeInt(-134217729, false));
    assertEquals(5, write.writeInt(-134217729, true));

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

    Random random = new Random();
    for (int i = 0; i < 10000; i++) {
      int value = random.nextInt();
      write.clear();
      write.writeInt(value);
      write.writeInt(value, true);
      write.writeInt(value, false);
      read.setBuffer(write.toBytes());
      assertEquals(value, read.readInt());
      assertEquals(value, read.readInt(true));
      assertEquals(value, read.readInt(false));
    }
  }
Ejemplo n.º 14
0
 @Override
 public MastershipTerm read(Kryo kryo, Input input, Class<MastershipTerm> type) {
   final NodeId node = (NodeId) kryo.readClassAndObject(input);
   final int term = input.readInt();
   return MastershipTerm.of(node, term);
 }
Ejemplo n.º 15
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);
      }
    }
Ejemplo n.º 16
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;
      }
    }
Ejemplo n.º 17
0
 @Override
 public void read(Kryo kryo, Input input) {
   super.read(kryo, input);
   this.code = input.readInt();
 }
Ejemplo n.º 18
0
 public Integer read(Kryo kryo, Input input, Class<Integer> type) {
   return input.readInt(false);
 }
Ejemplo n.º 19
0
 @Override
 public void read(Kryo kryo, Input input) {
   this.icID = input.readInt();
 }
Ejemplo n.º 20
0
 @Override
 public Timestamp read(Kryo kryo, Input input, Class<Timestamp> clazz) {
   Timestamp ts = new Timestamp(input.readLong());
   ts.setNanos(input.readInt());
   return ts;
 }