Package com.google.common.io

Examples of com.google.common.io.LimitInputStream


   * @throws IOException
   */
  private static String readUnparsedPart(InputStream in)
      throws UnsupportedEncodingException, IOException
  {
    return CharStreams.toString(new InputStreamReader(new LimitInputStream(
        in, MAX_UNPARSED_PART_SIZE), DEFAULT_ENCODING));
  }
View Full Code Here


    return this;
  }

  @Override
  public ByteBuf getBytes(int index, OutputStream dst, int length) throws IOException {
    ByteStreams.copy(new LimitInputStream(input, length), dst);
    return this;
  }
View Full Code Here

    return this;
  }

  @Override
  public int getBytes(int index, GatheringByteChannel out, int length) throws IOException {
    byte[] data = ByteStreams.toByteArray(new LimitInputStream(input, length));
   
    out.write(ByteBuffer.wrap(data));
    return data.length;
  }
View Full Code Here

    }
  }

  @Override
  public int setBytes(int index, InputStream in, int length) throws IOException {
    LimitInputStream limit = new LimitInputStream(in, length);
    ByteStreams.copy(limit, output);
    return length - limit.available();
  }
View Full Code Here

  private void setContentAndHeadersOnCurrentRequest(long bytesWritten) throws IOException {
    int blockSize = (int) Math.min(chunkSize, getMediaContentLength() - bytesWritten);
    // TODO(rmistry): Add tests for LimitInputStream.
    InputStreamContent contentChunk =
        new InputStreamContent(mediaContent.getType(),
          new LimitInputStream(contentInputStream, blockSize));
    contentChunk.setCloseInputStream(false);
    contentChunk.setRetrySupported(true);
    contentChunk.setLength(blockSize);
    // Mark the current position in case we need to retry the request.
    contentInputStream.mark(blockSize);
View Full Code Here

       */
      Step currentStep = null;

      for (FileSummary.Section s : sections) {
        channel.position(s.getOffset());
        InputStream in = new BufferedInputStream(new LimitInputStream(fin,
            s.getLength()));

        in = FSImageUtil.wrapInputStreamForCompression(conf,
            summary.getCodec(), in);

View Full Code Here

          });

      for (FsImageProto.FileSummary.Section s : sections) {
        fin.getChannel().position(s.getOffset());
        InputStream is = FSImageUtil.wrapInputStreamForCompression(conf,
            summary.getCodec(), new BufferedInputStream(new LimitInputStream(
            fin, s.getLength())));

        switch (FSImageFormatProtobuf.SectionName.fromString(s.getName())) {
          case STRING_TABLE:
            loadStringTable(is);
View Full Code Here

    InputStream input = CommandLineRunner.class.getResourceAsStream(
        "/externs.zip");
    ZipInputStream zip = new ZipInputStream(input);
    Map<String, JSSourceFile> externsMap = Maps.newHashMap();
    for (ZipEntry entry = null; (entry = zip.getNextEntry()) != null; ) {
      LimitInputStream entryStream = new LimitInputStream(zip, entry.getSize());
      externsMap.put(entry.getName(),
          JSSourceFile.fromInputStream(
              // Give the files an odd prefix, so that they do not conflict
              // with the user's files.
              "externs.zip//" + entry.getName(),
View Full Code Here

        InputStream input = Compiler.class
            .getResourceAsStream("/externs.zip");
        ZipInputStream zip = new ZipInputStream(input);
        List externs = Lists.newLinkedList();
        for (ZipEntry entry = null; (entry = zip.getNextEntry()) != null;) {
            LimitInputStream entryStream = new LimitInputStream(zip, entry
                .getSize());
            externs.add(JSSourceFile.fromInputStream(entry.getName(),
                entryStream));
        }
        return externs;
View Full Code Here

  @Override
  public byte[] generateSeed(int length) throws SeedException {
    FileInputStream in = null;
    try {
      in = new FileInputStream(DEV_URANDOM);
      return ByteStreams.toByteArray(new LimitInputStream(in, length));
    } catch (IOException ex) {
      throw new SeedException("Failed reading from " + DEV_URANDOM.getName(), ex);
    } catch (SecurityException ex) {
      // Might be thrown if resource access is restricted (such as in
      // an applet sandbox).
View Full Code Here

TOP

Related Classes of com.google.common.io.LimitInputStream

Copyright © 2018 www.massapicom. 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.