当前位置: 首页>>代码示例>>Java>>正文


Java BoundedInputStream类代码示例

本文整理汇总了Java中org.apache.commons.io.input.BoundedInputStream的典型用法代码示例。如果您正苦于以下问题:Java BoundedInputStream类的具体用法?Java BoundedInputStream怎么用?Java BoundedInputStream使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


BoundedInputStream类属于org.apache.commons.io.input包,在下文中一共展示了BoundedInputStream类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getContent

import org.apache.commons.io.input.BoundedInputStream; //导入依赖的package包/类
@Override
public Optional<InputStream> getContent(final IRI identifier, final List<Range<Integer>> ranges) {
    requireNonNull(ranges, "Byte ranges may not be null");
    return getFileFromIdentifier(identifier).map(file -> {
        try {
            if (ranges.isEmpty()) {
                return new FileInputStream(file);
            } else {
                final List<InputStream> iss = new ArrayList<>();
                for (final Range<Integer> r : ranges) {
                    final InputStream input = new FileInputStream(file);
                    final long skipped = input.skip(r.getMinimum());
                    LOGGER.debug("Skipped {} bytes", skipped);
                    iss.add(new BoundedInputStream(input, r.getMaximum() - r.getMinimum()));
                }
                return new SequenceInputStream(asEnumeration(iss.iterator()));
            }
        } catch (final IOException ex) {
            throw new UncheckedIOException(ex);
        }
    });
}
 
开发者ID:trellis-ldp,项目名称:trellis,代码行数:23,代码来源:FileBasedBinaryService.java

示例2: getDownloadersInputStream

import org.apache.commons.io.input.BoundedInputStream; //导入依赖的package包/类
@Override
protected InputStream getDownloadersInputStream() throws IOException {
    Request request = Request.createGET(sourcePath, connection);
    Response response = request.send();
    fileDetails = response.toFileDetails();

    // TODO: Manage the dependency which includes this class better?
    // Right now, I only needed the one class from apache commons.
    // There are countless classes online which provide this functionality,
    // including some which are available from the Android SDK - the only
    // problem is that they have a funky API which doesn't just wrap a
    // plain old InputStream (the class is ContentLengthInputStream -
    // whereas this BoundedInputStream is much more generic and useful
    // to us).
    BoundedInputStream stream = new BoundedInputStream(response.toContentStream(), fileDetails.getFileSize());
    stream.setPropagateClose(false);

    return stream;
}
 
开发者ID:uhuru-mobile,项目名称:mobile-store,代码行数:20,代码来源:BluetoothDownloader.java

示例3: copyPart

import org.apache.commons.io.input.BoundedInputStream; //导入依赖的package包/类
private void copyPart(final String bucket,
    final String key,
    final int from,
    final int to,
    final boolean useV4Signing,
    final File partFile) throws IOException {
  final int len = to - from + 1;
  final S3Object s3Object = resolveS3Object(bucket, key);

  try (InputStream sourceStream =
      wrapStream(FileUtils.openInputStream(s3Object.getDataFile()), useV4Signing);
      OutputStream targetStream = new FileOutputStream(partFile)) {
    sourceStream.skip(from);
    IOUtils.copy(new BoundedInputStream(sourceStream, len), targetStream);
  }
}
 
开发者ID:adobe,项目名称:S3Mock,代码行数:17,代码来源:FileStore.java

示例4: readFileToByteBuffer

import org.apache.commons.io.input.BoundedInputStream; //导入依赖的package包/类
static public int readFileToByteBuffer(File file, long offset,
		long readSize, ByteBuffer buffer) throws IOException {
	final long fileSize = Math.max(file.length(), 0l);
	offset  = Math.max(offset, 0l);
	offset = Math.min(offset, fileSize);
	
	if (0 >= readSize)
	{
		readSize = fileSize - offset;
	}
	readSize = Math.min(readSize, fileSize - offset);
	readSize = Math.min(readSize, buffer.remaining());
	
	int positionBefore = buffer.position();
	if (0 < readSize && file.isFile()) {
		final FileInputStream inFileStr = FileUtils.openInputStream(file);
		IOUtils.skip(inFileStr, offset);
		final BoundedInputStream inStr = new BoundedInputStream(inFileStr, readSize);
		
		final OutputStream outStr = new ByteBufferBackedOutputStream(buffer);

		IOUtils.copy(inStr, outStr);
	}

	return buffer.position() - positionBefore;
}
 
开发者ID:ict-carch,项目名称:hadoop-plus,代码行数:27,代码来源:BufferUtils.java

示例5: requestCRL

import org.apache.commons.io.input.BoundedInputStream; //导入依赖的package包/类
public X509CRL requestCRL(String url) throws IOException, MalformedURLException, CertificateException, CRLException {
	HttpURLConnection con = (HttpURLConnection) new URL(url).openConnection();
	try {
		con.setUseCaches(false);

		InputStream in = new BoundedInputStream(con.getInputStream(), maxCrlSize);
		try {
			CertificateFactory certificateFactory = CertificateFactory.getInstance("X.509");
			X509CRL crl = (X509CRL) certificateFactory.generateCRL(in);
			log.debug("CRL size: " + crl.getEncoded().length + " bytes");

			return crl;
		} finally {
			IOUtils.closeQuietly(in);
		}
	} catch (IOException ex) {
		log.error("Failed to download CRL from '" + url + "'", ex);
	} finally {
		if (con != null) {
			con.disconnect();
		}
	}
	
	return null;
}
 
开发者ID:GluuFederation,项目名称:oxAuth,代码行数:26,代码来源:CRLCertificateVerifier.java

示例6: submit

import org.apache.commons.io.input.BoundedInputStream; //导入依赖的package包/类
private Future<B2UploadPartResponse> submit(final ThreadPool pool, final Path file, final Local local,
                                            final BandwidthThrottle throttle, final StreamListener listener,
                                            final TransferStatus overall,
                                            final int partNumber,
                                            final Long offset, final Long length, final ConnectionCallback callback) {
    if(log.isInfoEnabled()) {
        log.info(String.format("Submit part %d of %s to queue with offset %d and length %d", partNumber, file, offset, length));
    }
    return pool.execute(new DefaultRetryCallable<B2UploadPartResponse>(new BackgroundExceptionCallable<B2UploadPartResponse>() {
        @Override
        public B2UploadPartResponse call() throws BackgroundException {
            if(overall.isCanceled()) {
                throw new ConnectionCanceledException();
            }
            final TransferStatus status = new TransferStatus()
                    .length(length)
                    .skip(offset);
            status.setHeader(overall.getHeader());
            status.setNonces(overall.getNonces());
            status.setChecksum(writer.checksum(file).compute(
                    StreamCopier.skip(new BoundedInputStream(local.getInputStream(), offset + length), offset),
                    status));
            status.setSegment(true);
            status.setPart(partNumber);
            return (B2UploadPartResponse) B2LargeUploadService.super.upload(file, local, throttle, listener, status, overall, new StreamProgress() {
                @Override
                public void progress(final long bytes) {
                    status.progress(bytes);
                    // Discard sent bytes in overall progress if there is an error reply for segment.
                    overall.progress(bytes);
                }

                @Override
                public void setComplete() {
                    status.setComplete();
                }
            }, callback);
        }
    }, overall));
}
 
开发者ID:iterate-ch,项目名称:cyberduck,代码行数:41,代码来源:B2LargeUploadService.java

示例7: submit

import org.apache.commons.io.input.BoundedInputStream; //导入依赖的package包/类
private Future<StorageObject> submit(final ThreadPool pool, final Path segment, final Local local,
                                     final BandwidthThrottle throttle, final StreamListener listener,
                                     final TransferStatus overall, final Long offset, final Long length, final ConnectionCallback callback) {
    return pool.execute(new DefaultRetryCallable<StorageObject>(new BackgroundExceptionCallable<StorageObject>() {
        @Override
        public StorageObject call() throws BackgroundException {
            if(overall.isCanceled()) {
                throw new ConnectionCanceledException();
            }
            final TransferStatus status = new TransferStatus()
                    .length(length)
                    .skip(offset);
            status.setHeader(overall.getHeader());
            status.setNonces(overall.getNonces());
            status.setChecksum(writer.checksum(segment).compute(
                    StreamCopier.skip(new BoundedInputStream(local.getInputStream(), offset + length), offset), status));
            status.setSegment(true);
            return SwiftLargeObjectUploadFeature.super.upload(
                    segment, local, throttle, listener, status, overall, new StreamProgress() {
                        @Override
                        public void progress(final long bytes) {
                            status.progress(bytes);
                            // Discard sent bytes in overall progress if there is an error reply for segment.
                            overall.progress(bytes);
                        }

                        @Override
                        public void setComplete() {
                            status.setComplete();
                        }
                    }, callback);
        }
    }, overall));
}
 
开发者ID:iterate-ch,项目名称:cyberduck,代码行数:35,代码来源:SwiftLargeObjectUploadFeature.java

示例8: getObjectWithRange

import org.apache.commons.io.input.BoundedInputStream; //导入依赖的package包/类
/**
 * supports range different range ends. eg. if content has 100 bytes, the range request could
 * be: bytes=10-100,
 * 10--1 and 10-200
 *
 * see: http://docs.aws.amazon.com/AmazonS3/latest/API/RESTObjectGET.html
 *
 * @param response {@link HttpServletResponse}
 * @param range {@link String}
 * @param s3Object {@link S3Object}
 * @throws IOException if invalid range request value
 */
private void getObjectWithRange(final HttpServletResponse response, final Range range,
    final S3Object s3Object)
    throws IOException {
  final long fileSize = s3Object.getDataFile().length();
  final long bytesToRead = Math.min(fileSize - 1, range.getEnd()) - range.getStart() + 1;

  if (bytesToRead < 0 || fileSize < range.getStart()) {
    response.setStatus(HttpStatus.REQUESTED_RANGE_NOT_SATISFIABLE.value());
    response.flushBuffer();
    return;
  }

  response.setStatus(HttpStatus.PARTIAL_CONTENT.value());
  response.setHeader(HttpHeaders.ACCEPT_RANGES, RANGES_BYTES);
  response.setHeader(HttpHeaders.CONTENT_RANGE,
      String.format("bytes %s-%s", range.getStart(), bytesToRead + range.getStart() - 1));
  response.setHeader(HttpHeaders.ETAG, "\"" + s3Object.getMd5() + "\"");
  response.setDateHeader(HttpHeaders.LAST_MODIFIED, s3Object.getLastModified());

  response.setContentType(s3Object.getContentType());
  response.setContentLengthLong(bytesToRead);

  try (OutputStream outputStream = response.getOutputStream()) {
    try (FileInputStream fis = new FileInputStream(s3Object.getDataFile())) {
      fis.skip(range.getStart());
      IOUtils.copy(new BoundedInputStream(fis, bytesToRead), outputStream);
    }
  }
}
 
开发者ID:adobe,项目名称:S3Mock,代码行数:42,代码来源:FileStoreController.java

示例9: getFileChecksumLocally

import org.apache.commons.io.input.BoundedInputStream; //导入依赖的package包/类
/**
 * Get the checksum of a file, from the beginning of the file till the
 * specific length. Warning this operation is slow because we have to
 * download the entire file in order to calculate the checksum.
 *
 * @param mantaPath The file path
 * @param length The length of the file range for checksum calculation*
 * @return the checksum of an arbitrary amount of bytes from the start of a file
 * @throws IOException thrown when unable to compute the checksum
 */
FileChecksum getFileChecksumLocally(final String mantaPath, final long length) throws IOException {
    LOG.debug("Calculating checksum for file {} locally by downloading all content",
            mantaPath);

    try (InputStream in = client.getAsInputStream(mantaPath);
         BoundedInputStream bin = new BoundedInputStream(in, length)) {
        byte[] bytes = DigestUtils.md5(bin);
        return new MantaChecksum(bytes);
    }
}
 
开发者ID:joyent,项目名称:hadoop-manta,代码行数:21,代码来源:MantaFileSystem.java

示例10: nextMessage

import org.apache.commons.io.input.BoundedInputStream; //导入依赖的package包/类
/**
 * @return Data input for the next message. Note that it does not automatically skip over the last message if it was
 *         not fully read, for that purpose, skipRemainingBytes() should be explicitly called after reading every
 *         message. A null return value indicates the position where MessageOutput#finish() had written the end
 *         marker.
 * @throws IOException On IO error
 */
public DataInput nextMessage() throws IOException {
  int value = dataInputStream.readInt();
  messageFlags = (int) ((value & 0xC0000000L) >> 30L);
  messageSize = value & 0x3FFFFFFF;

  if (messageSize == 0) {
    return null;
  }

  return new DataInputStream(new BoundedInputStream(countingInputStream, messageSize));
}
 
开发者ID:sedmelluq,项目名称:lavaplayer,代码行数:19,代码来源:MessageInput.java

示例11: readAcontainerLogs

import org.apache.commons.io.input.BoundedInputStream; //导入依赖的package包/类
/**
 * Writes all logs for a single container to the provided writer.
 * @param valueStream
 * @param writer
 * @throws IOException
 */
public static void readAcontainerLogs(DataInputStream valueStream,
    Writer writer) throws IOException {
  int bufferSize = 65536;
  char[] cbuf = new char[bufferSize];
  String fileType;
  String fileLengthStr;
  long fileLength;

  while (true) {
    try {
      fileType = valueStream.readUTF();
    } catch (EOFException e) {
      // EndOfFile
      return;
    }
    fileLengthStr = valueStream.readUTF();
    fileLength = Long.parseLong(fileLengthStr);
    writer.write("\n\nLogType:");
    writer.write(fileType);
    writer.write("\nLogLength:");
    writer.write(fileLengthStr);
    writer.write("\nLog Contents:\n");
    // ByteLevel
    BoundedInputStream bis =
        new BoundedInputStream(valueStream, fileLength);
    InputStreamReader reader = new InputStreamReader(bis);
    int currentRead = 0;
    int totalRead = 0;
    while ((currentRead = reader.read(cbuf, 0, bufferSize)) != -1) {
      writer.write(cbuf, 0, currentRead);
      totalRead += currentRead;
    }
  }
}
 
开发者ID:ict-carch,项目名称:hadoop-plus,代码行数:41,代码来源:AggregatedLogFormat.java

示例12: read

import org.apache.commons.io.input.BoundedInputStream; //导入依赖的package包/类
@Override
public Object read(Kryo kryo, Input input, Class type) {

  //First item to read is an integer representing the length of the written byte array
  int lDOMLength = input.readInt();

  //Restrict the InputStream to be read to the length of the serialised DOM, so the DOM constructor doesn't deplete the raw Kryo InputStream
  BoundedInputStream lBoundedInputStream = new BoundedInputStream(input, lDOMLength);
  //Don't allow close calls from the XML deserialiser to propogate to the wrapped InputStream
  lBoundedInputStream.setPropagateClose(false);

  return DOM.createDocument(lBoundedInputStream, false);
}
 
开发者ID:Fivium,项目名称:FOXopen,代码行数:14,代码来源:KryoManager.java

示例13: readAcontainerLogs

import org.apache.commons.io.input.BoundedInputStream; //导入依赖的package包/类
/**
 * Writes all logs for a single container to the provided writer.
 *
 * @param valueStream
 * @param writer
 * @throws IOException
 */
public static void readAcontainerLogs(DataInputStream valueStream,
        Writer writer) throws IOException {
  int bufferSize = 65536;
  char[] cbuf = new char[bufferSize];
  String fileType;
  String fileLengthStr;
  long fileLength;

  while (true) {
    try {
      fileType = valueStream.readUTF();
    } catch (EOFException e) {
      // EndOfFile
      return;
    }
    fileLengthStr = valueStream.readUTF();
    fileLength = Long.parseLong(fileLengthStr);
    writer.write("\n\nLogType:");
    writer.write(fileType);
    writer.write("\nLogLength:");
    writer.write(fileLengthStr);
    writer.write("\nLog Contents:\n");
    // ByteLevel
    BoundedInputStream bis = new BoundedInputStream(valueStream, fileLength);
    InputStreamReader reader = new InputStreamReader(bis);
    int currentRead = 0;
    int totalRead = 0;
    while ((currentRead = reader.read(cbuf, 0, bufferSize)) != -1) {
      writer.write(cbuf, 0, currentRead);
      totalRead += currentRead;
    }
  }
}
 
开发者ID:hopshadoop,项目名称:hopsworks,代码行数:41,代码来源:LogReader.java

示例14: getRawSource

import org.apache.commons.io.input.BoundedInputStream; //导入依赖的package包/类
@Override
public RawPreview getRawSource(int maxLength, MultivaluedMap<String, String> previewParams) throws PipelineException {
  changeState(PreviewStatus.RUNNING, null);
  int bytesToRead = configuration.get(MAX_SOURCE_PREVIEW_SIZE_KEY, MAX_SOURCE_PREVIEW_SIZE_DEFAULT);
  bytesToRead = Math.min(bytesToRead, maxLength);

  PipelineConfiguration pipelineConf = pipelineStore.load(name, rev);
  if(pipelineConf.getStages().isEmpty()) {
    throw new PipelineRuntimeException(ContainerError.CONTAINER_0159, name);
  }

  //find the source stage in the pipeline configuration
  StageDefinition sourceStageDef = getSourceStageDef(pipelineConf);

  RawSourcePreviewer rawSourcePreviewer = createRawSourcePreviewer(sourceStageDef, previewParams);
  RawPreview rawPreview;
  ClassLoader classLoader = sourceStageDef.getStageClassLoader();
  ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
  try {
    Thread.currentThread().setContextClassLoader(classLoader);
    try(BoundedInputStream bIn = new BoundedInputStream(rawSourcePreviewer.preview(bytesToRead), bytesToRead)) {
      rawPreview = new RawPreviewImpl(IOUtils.toString(bIn), rawSourcePreviewer.getMimeType());
    }
  } catch (IOException ex) {
    throw new PipelineRuntimeException(PreviewError.PREVIEW_0003, ex.toString(), ex);
  } finally {
    Thread.currentThread().setContextClassLoader(contextClassLoader);
  }
  changeState(PreviewStatus.FINISHED, null);
  return rawPreview;
}
 
开发者ID:streamsets,项目名称:datacollector,代码行数:32,代码来源:SyncPreviewer.java

示例15: extractHtml

import org.apache.commons.io.input.BoundedInputStream; //导入依赖的package包/类
private void extractHtml(InputStream record, Document doc) throws TextExtractionException {
    try {
        BoundedInputStream in = new BoundedInputStream(record, maxDocSize);
        TextDocument textDoc = new BoilerpipeSAXInput(new InputSource(in)).getTextDocument();
        doc.setTitle(textDoc.getTitle());
        doc.setText(textDoc.getText(true, true).replace("\uFFFF", ""));
        if (boilingEnabled) {
            DefaultExtractor.INSTANCE.process(textDoc);
            doc.setBoiled(textDoc.getContent().replace("\uFFFF", ""));
        }
    } catch (SAXException | BoilerpipeProcessingException | IllegalArgumentException | ArrayIndexOutOfBoundsException e) {
        throw new TextExtractionException(e);
    }
}
 
开发者ID:nla,项目名称:bamboo,代码行数:15,代码来源:TextExtractor.java


注:本文中的org.apache.commons.io.input.BoundedInputStream类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。