Exemplo n.º 1
0
  public void runStringTest(int length) throws IOException {
    Output write = new Output(1024, -1);
    StringBuilder buffer = new StringBuilder();
    for (int i = 0; i < length; i++) buffer.append((char) i);

    String value = buffer.toString();
    write.writeString(value);
    write.writeString(value);
    Input read = new Input(write.toBytes());
    assertEquals(value, read.readString());
    assertEquals(value, read.readStringBuilder().toString());

    write.clear();
    write.writeString(buffer);
    write.writeString(buffer);
    read = new Input(write.toBytes());
    assertEquals(value, read.readStringBuilder().toString());
    assertEquals(value, read.readString());

    if (length <= 127) {
      write.clear();
      write.writeAscii(value);
      write.writeAscii(value);
      read = new Input(write.toBytes());
      assertEquals(value, read.readStringBuilder().toString());
      assertEquals(value, read.readString());
    }
  }
Exemplo n.º 2
0
  public void testStrings() throws IOException {
    runStringTest(new Output(4096));
    runStringTest(new Output(897));
    runStringTest(new Output(new ByteArrayOutputStream()));

    Output write = new Output(21);
    String value = "abcdef\u00E1\u00E9\u00ED\u00F3\u00FA\u1234";
    write.writeString(value);
    Input read = new Input(write.toBytes());
    assertEquals(value, read.readString());

    write.clear();
    write.writeString(null);
    read = new Input(write.toBytes());
    assertEquals(null, read.readString());

    for (int i = 0; i <= 258; i++) runStringTest(i);
    runStringTest(1);
    runStringTest(2);
    runStringTest(127);
    runStringTest(256);
    runStringTest(1024 * 1023);
    runStringTest(1024 * 1024);
    runStringTest(1024 * 1025);
    runStringTest(1024 * 1026);
    runStringTest(1024 * 1024 * 2);
  }
 @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));
   }
 }
Exemplo n.º 4
0
 @Override
 public void read(Kryo kryo, Input input) {
   super.read(kryo, input);
   if (_has(VALUES)) {
     setValues(((List) readChildCollection(kryo, input)));
   }
   if (_has(NAMESPACE)) {
     setNameSpace(input.readString());
   }
   if (_has(IDENTITY)) {
     setIdentity(input.readString());
   }
 }
Exemplo n.º 5
0
 public String readNullableString() throws EOFException {
   try {
     return input.readString();
   } catch (KryoException e) {
     throw maybeEndOfStream(e);
   }
 }
Exemplo n.º 6
0
 public URL read(Kryo kryo, Input input, Class<URL> type) {
   try {
     return new java.net.URL(input.readString());
   } catch (MalformedURLException e) {
     throw new KryoException(e);
   }
 }
Exemplo n.º 7
0
  public void runStringTest(Output write) throws IOException {
    String value1 =
        "ABCDEFGHIJKLMNOPQRSTUVWXYZ\rabcdefghijklmnopqrstuvwxyz\n1234567890\t\"!`?'.,;:()[]{}<>|/@\\^$-%+=#_&~*";
    String value2 = "abcdef\u00E1\u00E9\u00ED\u00F3\u00FA\u1234";

    write.writeString("");
    write.writeString("1");
    write.writeString("22");
    write.writeString("uno");
    write.writeString("dos");
    write.writeString("tres");
    write.writeString(null);
    write.writeString(value1);
    write.writeString(value2);
    for (int i = 0; i < 127; i++) write.writeString(String.valueOf((char) i));
    for (int i = 0; i < 127; i++) write.writeString(String.valueOf((char) i) + "abc");

    Input read = new Input(write.toBytes());
    assertEquals("", read.readString());
    assertEquals("1", read.readString());
    assertEquals("22", read.readString());
    assertEquals("uno", read.readString());
    assertEquals("dos", read.readString());
    assertEquals("tres", read.readString());
    assertEquals(null, read.readString());
    assertEquals(value1, read.readString());
    assertEquals(value2, read.readString());
    for (int i = 0; i < 127; i++) assertEquals(String.valueOf((char) i), read.readString());
    for (int i = 0; i < 127; i++) assertEquals(String.valueOf((char) i) + "abc", read.readString());

    read.rewind();
    assertEquals("", read.readStringBuilder().toString());
    assertEquals("1", read.readStringBuilder().toString());
    assertEquals("22", read.readStringBuilder().toString());
    assertEquals("uno", read.readStringBuilder().toString());
    assertEquals("dos", read.readStringBuilder().toString());
    assertEquals("tres", read.readStringBuilder().toString());
    assertEquals(null, read.readStringBuilder());
    assertEquals(value1, read.readStringBuilder().toString());
    assertEquals(value2, read.readStringBuilder().toString());
    for (int i = 0; i < 127; i++)
      assertEquals(String.valueOf((char) i), read.readStringBuilder().toString());
    for (int i = 0; i < 127; i++)
      assertEquals(String.valueOf((char) i) + "abc", read.readStringBuilder().toString());
  }
Exemplo n.º 8
0
 public SerializablePage loadPage(InputStream in) {
   synchronized (serializeLock) {
     Input input = null;
     try {
       input = new Input(in);
       input.readString();
       kryo.readObject(input, UrlPageModel.class);
       return kryo.readObject(input, SerializablePage.class);
     } finally {
       IOUtils.closeQuietly(input);
     }
   }
 }
Exemplo n.º 9
0
 public Pair<String, UrlPageModel> loadPageInfo(InputStream in) {
   synchronized (serializeLock) {
     Input input = null;
     try {
       input = new Input(in);
       String title = input.readString();
       UrlPageModel pageModel = kryo.readObject(input, UrlPageModel.class);
       return Pair.of(title, pageModel);
     } finally {
       IOUtils.closeQuietly(input);
     }
   }
 }
Exemplo n.º 10
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;
 }
 @Override
 public void read(Kryo kryo, Input input) {
   setUser(kryo.readObject(input, KryoUser.class));
   setPassword(input.readString());
   setFriends((List<User>) kryo.readClassAndObject(input));
 }
Exemplo n.º 12
0
 @Override
 public File read(Kryo kryo, Input input, Class<File> type) {
   return new File(input.readString());
 }
Exemplo n.º 13
0
 public String read(Kryo kryo, Input input, Class<String> type) {
   return input.readString();
 }
Exemplo n.º 14
0
 @Override
 public Path read(Kryo kryo, Input input, Class<Path> type) {
   return new Path(URI.create(input.readString()));
 }
Exemplo n.º 15
0
 public Charset read(Kryo kryo, Input input, Class<Charset> type) {
   return Charset.forName(input.readString());
 }
Exemplo n.º 16
0
 public Locale read(Kryo kryo, Input input, Class<Locale> type) {
   String language = input.readString();
   String country = input.readString();
   String variant = input.readString();
   return create(language, country, variant);
 }
Exemplo n.º 17
0
 public TimeZone read(Kryo kryo, Input input, Class<TimeZone> type) {
   return TimeZone.getTimeZone(input.readString());
 }
Exemplo n.º 18
0
 public StringBuffer read(Kryo kryo, Input input, Class<StringBuffer> type) {
   String value = input.readString();
   if (value == null) return null;
   return new StringBuffer(value);
 }
Exemplo n.º 19
0
 public Currency read(Kryo kryo, Input input, Class<Currency> type) {
   String currencyCode = input.readString();
   if (currencyCode == null) return null;
   return Currency.getInstance(currencyCode);
 }