Examples of UnsafeByteArrayInputStream


Examples of com.alibaba.dubbo.common.io.UnsafeByteArrayInputStream

            }

            NettyChannel channel = NettyChannel.getOrAddChannel(ctx.getChannel(), url, handler);
            boolean remaining = true;
            Object msg;
            UnsafeByteArrayInputStream bis;
            try {
                do {
                    // read data into buffer.
                    int read = Math.min(readable, buf.length - limit);
                    input.readBytes(buf, limit, read);
                    limit += read;
                    readable -= read;
                    bis = new UnsafeByteArrayInputStream(buf, off, limit - off); // 不需要关闭
                    // decode object.
                    do {
                        try {
                            msg = upstreamCodec.decode(channel, bis);
                        } catch (IOException e) {
                            remaining = false;
                            throw e;
                        }
                        if (msg == Codec.NEED_MORE_INPUT) {
                            if (off == 0) {
                                if (readable > 0) {
                                    buf = Bytes.copyOf(buf, buf.length << 1);
                                }
                            } else {
                                int len = limit - off;
                                System.arraycopy(buf, off, buf, 0, len); // adjust buffer.
                                off = 0;
                                limit = len;
                            }
                            break;
                        } else {
                            int pos = bis.position();
                            if (off == pos) {
                                remaining = false;
                                throw new IOException("Decode without read data.");
                            }
                            if (msg != null) {
                                Channels.fireMessageReceived(ctx, msg, event.getRemoteAddress());
                            }
                            off = pos;
                        }
                    } while (bis.available() > 0);
                } while (readable > 0);
            } finally {
                if (remaining) {
                    int len = limit - off;
                    if (len < buf.length / 2) {
View Full Code Here

Examples of com.alibaba.dubbo.common.io.UnsafeByteArrayInputStream

                header = Bytes.copyOf(header, readable);
                is.read(header, length, readable - length);
            }
            for (int i = 1; i < header.length - 1; i ++) {
                if (header[i] == MAGIC_HIGH && header[i + 1] == MAGIC_LOW) {
                    UnsafeByteArrayInputStream bis = ((UnsafeByteArrayInputStream) is);
                    bis.position(bis.position() - header.length + i);
                    header = Bytes.copyOf(header, i);
                    break;
                }
            }
            return super.decode(channel, is, readable, header);
View Full Code Here

Examples of de.undercouch.bson4jackson.io.UnsafeByteArrayInputStream

        return _createParser(r, ctxt);
    }
 
  @Override
  protected BsonParser _createParser(byte[] data, int offset, int len, IOContext ctxt) {
    return _createParser(new UnsafeByteArrayInputStream(data, offset, len), ctxt);
  }
View Full Code Here

Examples of httl.util.UnsafeByteArrayInputStream

    public InputStream getResourceAsStream(final String name) {
      if (name.endsWith(ClassUtils.CLASS_EXTENSION)) {
        String qualifiedClassName = name.substring(0, name.length() - ClassUtils.CLASS_EXTENSION.length()).replace('/', '.');
        JavaFileObjectImpl file = (JavaFileObjectImpl) classes.get(qualifiedClassName);
        if (file != null) {
          return new UnsafeByteArrayInputStream(file.getByteCode());
        }
      }
      return super.getResourceAsStream(name);
    }
View Full Code Here

Examples of httl.util.UnsafeByteArrayInputStream

      return source;
    }

    @Override
    public InputStream openInputStream() {
      return new UnsafeByteArrayInputStream(getByteCode());
    }
View Full Code Here

Examples of httl.util.UnsafeByteArrayInputStream

  public <T> T valueOf(byte[] str, Class<T> type) throws ParseException {
    if (str == null) {
      return null;
    }
    if (type == null) {
      return (T) XSTREAM.fromXML(new UnsafeByteArrayInputStream(str));
    }
    try {
      return (T) XSTREAM.fromXML(new UnsafeByteArrayInputStream(str), type.newInstance());
    } catch (Exception e) {
      throw new RuntimeException(e.getMessage(), e);
    }
  }
View Full Code Here

Examples of jetbrick.template.utils.UnsafeByteArrayInputStream

        return 0;
    }

    @Override
    public InputStream getInputStream() throws IOException {
        return new UnsafeByteArrayInputStream(source.getBytes(ENCODING));
    }
View Full Code Here

Examples of org.apache.giraph.utils.UnsafeByteArrayInputStream

   * @return ExtendedDataInput object
   */
  public ExtendedDataInput createExtendedDataInput(
      byte[] buf, int off, int length) {
    if (useUnsafeSerialization) {
      return new UnsafeByteArrayInputStream(buf, off, length);
    } else {
      return new ExtendedByteArrayDataInput(buf, off, length);
    }
  }
View Full Code Here

Examples of org.apache.giraph.utils.UnsafeByteArrayInputStream

    assertEquals(0, partition.getEdgeCount());
    assertEquals(7, partition.getVertexCount());
    UnsafeByteArrayOutputStream outputStream = new
        UnsafeByteArrayOutputStream();
    partition.write(outputStream);
    UnsafeByteArrayInputStream inputStream = new UnsafeByteArrayInputStream(
        outputStream.getByteArray(), 0, outputStream.getPos());
    Partition<IntWritable, IntWritable, NullWritable,
        IntWritable> deserializatedPartition = conf.createPartition(-1,
        context);
    deserializatedPartition.readFields(inputStream);
View Full Code Here

Examples of org.apache.giraph.utils.UnsafeByteArrayInputStream

    long deserializeNanosStart;
    long deserializeNanos = 0;
    for (int i = 0; i < REPS; ++i) {
      deserializeNanosStart = SystemTime.get().getNanoseconds();
      UnsafeByteArrayInputStream inputStream = new
          UnsafeByteArrayInputStream(
          outputStream.getByteArray(), 0, outputStream.getPos());
      WritableUtils.reinitializeVertexFromDataInput(
          inputStream, readVertex, readVertex.getConf());
      deserializeNanos += Times.getNanosecondsSince(SystemTime.get(),
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.