示例#1
0
  public static IOStaging createStagingAndCopyFromInputstream(
      InputStream is, long length, IOStagingFactory factory) throws NetIOException {
    IOStaging staging = factory.newInstance();
    ReadableByteChannel channel = Channels.newChannel(is);

    staging.transferFrom(channel, 0, length);
    staging.reset();

    return staging;
  }
示例#2
0
  public static IOStaging createStringIOStaging(
      String message, Charset charset, IOStagingFactory factory) throws NetIOException {
    try {
      IOStaging staging = factory.newInstance();
      StringReadableChannel channel = new StringReadableChannel(message, charset.name());

      staging.transferFrom(channel, 0, channel.size());
      staging.reset();

      return staging;
    } catch (IOException e) {
      throw new NetIOException(e);
    }
  }