类org.apache.commons.io.input.CountingInputStream源码实例Demo

下面列出了怎么用org.apache.commons.io.input.CountingInputStream的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: cyberduck   文件: StoregateReadFeatureTest.java
@Test
public void testReadCloseReleaseEntity() throws Exception {
    final TransferStatus status = new TransferStatus();
    final byte[] content = RandomUtils.nextBytes(32769);
    final TransferStatus writeStatus = new TransferStatus();
    writeStatus.setLength(content.length);
    final StoregateIdProvider nodeid = new StoregateIdProvider(session).withCache(cache);
    final Path room = new StoregateDirectoryFeature(session, nodeid).mkdir(
        new Path(String.format("/My files/%s", new AlphanumericRandomStringService().random()),
            EnumSet.of(Path.Type.directory, Path.Type.volume)), null, new TransferStatus());
    final Path test = new Path(room, UUID.randomUUID().toString(), EnumSet.of(Path.Type.file));
    final StoregateWriteFeature writer = new StoregateWriteFeature(session, nodeid);
    final HttpResponseOutputStream<VersionId> out = writer.write(test, writeStatus, new DisabledConnectionCallback());
    assertNotNull(out);
    new StreamCopier(writeStatus, writeStatus).transfer(new ByteArrayInputStream(content), out);
    final CountingInputStream in = new CountingInputStream(new StoregateReadFeature(session, nodeid).read(test, status, new DisabledConnectionCallback()));
    in.close();
    assertEquals(0L, in.getByteCount(), 0L);
    new StoregateDeleteFeature(session, nodeid).delete(Collections.singletonList(room), new DisabledLoginCallback(), new Delete.DisabledCallback());
}
 
源代码2 项目: cyberduck   文件: SDSReadFeatureTest.java
@Test
public void testReadCloseReleaseEntity() throws Exception {
    final TransferStatus status = new TransferStatus();
    final byte[] content = RandomUtils.nextBytes(32769);
    final TransferStatus writeStatus = new TransferStatus();
    writeStatus.setLength(content.length);
    final SDSNodeIdProvider nodeid = new SDSNodeIdProvider(session).withCache(cache);
    final Path room = new SDSDirectoryFeature(session, nodeid).mkdir(
        new Path(new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.directory, Path.Type.volume, Path.Type.triplecrypt)), null, new TransferStatus());
    final Path test = new Path(room, UUID.randomUUID().toString(), EnumSet.of(Path.Type.file));
    final SDSWriteFeature writer = new SDSWriteFeature(session, nodeid);
    final HttpResponseOutputStream<VersionId> out = writer.write(test, writeStatus, new DisabledConnectionCallback());
    assertNotNull(out);
    new StreamCopier(writeStatus, writeStatus).transfer(new ByteArrayInputStream(content), out);
    final CountingInputStream in = new CountingInputStream(new SDSReadFeature(session, nodeid).read(test, status, new DisabledConnectionCallback()));
    in.close();
    assertEquals(0L, in.getByteCount(), 0L);
    new SDSDeleteFeature(session, nodeid).delete(Collections.singletonList(room), new DisabledLoginCallback(), new Delete.DisabledCallback());
}
 
源代码3 项目: cyberduck   文件: S3ReadFeatureTest.java
@Test
public void testReadCloseReleaseEntity() throws Exception {
    final Path container = new Path("test-us-east-1-cyberduck", EnumSet.of(Path.Type.directory, Path.Type.volume));
    final Path file = new Path(container, UUID.randomUUID().toString(), EnumSet.of(Path.Type.file));
    final int length = 2048;
    final byte[] content = RandomUtils.nextBytes(length);
    final TransferStatus status = new TransferStatus().length(content.length);
    status.setChecksum(new SHA256ChecksumCompute().compute(new ByteArrayInputStream(content), status));
    final OutputStream out = new S3WriteFeature(session).write(file, status, new DisabledConnectionCallback());
    new StreamCopier(new TransferStatus(), new TransferStatus()).transfer(new ByteArrayInputStream(content), out);
    out.close();
    final CountingInputStream in = new CountingInputStream(new S3ReadFeature(session).read(file, status, new DisabledConnectionCallback()));
    in.close();
    assertEquals(0L, in.getByteCount(), 0L);
    new S3DefaultDeleteFeature(session).delete(Collections.singletonList(file), new DisabledLoginCallback(), new Delete.DisabledCallback());
}
 
源代码4 项目: cyberduck   文件: GoogleStorageReadFeatureTest.java
@Test
public void testReadCloseReleaseEntity() throws Exception {
    final Path container = new Path("test.cyberduck.ch", EnumSet.of(Path.Type.directory, Path.Type.volume));
    final Path file = new Path(container, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.file));
    final int length = 2048;
    final byte[] content = RandomUtils.nextBytes(length);
    final TransferStatus status = new TransferStatus().length(content.length);
    status.setChecksum(new SHA256ChecksumCompute().compute(new ByteArrayInputStream(content), status));
    final OutputStream out = new GoogleStorageWriteFeature(session).write(file, status, new DisabledConnectionCallback());
    new StreamCopier(new TransferStatus(), new TransferStatus()).transfer(new ByteArrayInputStream(content), out);
    out.close();
    final CountingInputStream in = new CountingInputStream(new GoogleStorageReadFeature(session).read(file, status, new DisabledConnectionCallback()));
    in.close();
    assertEquals(0L, in.getByteCount(), 0L);
    new GoogleStorageDeleteFeature(session).delete(Collections.singletonList(file), new DisabledLoginCallback(), new Delete.DisabledCallback());
}
 
源代码5 项目: cyberduck   文件: GoogleStorageReadFeatureTest.java
@Test
public void testReadWhitespace() throws Exception {
    final int length = 47;
    final byte[] content = RandomUtils.nextBytes(length);
    final Path container = new Path("test.cyberduck.ch", EnumSet.of(Path.Type.directory, Path.Type.volume));
    final Path file = new Path(container, String.format("t %s", new AlphanumericRandomStringService().random()), EnumSet.of(Path.Type.file));
    final TransferStatus status = new TransferStatus().length(content.length);
    status.setChecksum(new SHA256ChecksumCompute().compute(new ByteArrayInputStream(content), status));
    final OutputStream out = new GoogleStorageWriteFeature(session).write(file, status, new DisabledConnectionCallback());
    new StreamCopier(new TransferStatus(), new TransferStatus()).transfer(new ByteArrayInputStream(content), out);
    out.close();
    assertEquals(length, new GoogleStorageAttributesFinderFeature(session).find(file).getSize());
    final CountingInputStream in = new CountingInputStream(new GoogleStorageReadFeature(session).read(file, new TransferStatus(), new DisabledConnectionCallback()));
    in.close();
    assertEquals(0L, in.getByteCount(), 0L);
    new GoogleStorageDeleteFeature(session).delete(Collections.singletonList(file), new DisabledLoginCallback(), new Delete.DisabledCallback());
}
 
@Override
public long getSize() {
  // https://github.com/Cosium/git-code-format-maven-plugin/issues/42: It is very important to
  // return the exact transformed content size
  if (cachedSize != null) {
    return cachedSize;
  }
  try (CountingInputStream countingInputStream = new CountingInputStream(openStream())) {
    while (countingInputStream.read() != -1) {
      // Do nothing in the while, we are just moving bytes through CountingInputstream to retrieve
      // the total stream size
    }
    cachedSize = countingInputStream.getByteCount();
  } catch (IOException e) {
    throw new RuntimeException(e);
  }
  return cachedSize;
}
 
源代码7 项目: phoenicis   文件: PEReader.java
private RsrcSection readResourceSection(CountingInputStream executableInputStream, SectionHeader[] sectionHeaders)
        throws IOException {
    SectionHeader rsrcSectionHeader = null;
    for (SectionHeader sectionHeader : sectionHeaders) {
        if (".rsrc\u0000\u0000\u0000".equals(new String(sectionHeader.name))) {
            rsrcSectionHeader = sectionHeader;
        }
    }

    if (rsrcSectionHeader == null) {
        return null;
    }

    long numberToSkip = rsrcSectionHeader.pointerToRawData.getUnsignedValue() - executableInputStream.getCount();
    executableInputStream.skip(numberToSkip);
    byte[] rsrcSection = new byte[(int) rsrcSectionHeader.sizeOfRawData.getUnsignedValue()];
    executableInputStream.read(rsrcSection);

    return new RsrcSection(rsrcSection);
}
 
源代码8 项目: Baffle   文件: ArscData.java
private static ArscData readTable(File file , CountingInputStream countIn, ExtDataInput in )
        throws IOException {
    ArscData arscData = new ArscData();
    arscData.mFile = file;
    arscData.mHeader = Header.read(in);
    int packageCount = in.readInt();
    if (packageCount != 1) {
        throw new UnsupportedOperationException("not support more then 1 package");
    }
    arscData.mTableStrings = StringBlock.read(in);
    arscData.mPkgHeaderIndex = (int) countIn.getByteCount();
    arscData.mPkgHeader = PackageHeader.read(in);
    arscData.mTypeStrStart = (int) countIn.getByteCount();
    arscData.mTypeNames = StringBlock.read(in);
    arscData.mTypeStrEnd =  (int) countIn.getByteCount();
    arscData.mSpecNames = StringBlock.read(in);
    arscData.mResIndex =  (int) countIn.getByteCount();
    return arscData;
}
 
private void receiveStream(IProgressMonitor monitor, int fileCount)
    throws SarosCancellationException, IOException {
  String message = "Receiving files from " + getPeer().getName() + "...";
  monitor.beginTask(message, fileCount);

  monitor.subTask("Waiting for Host to start...");
  monitor.waitForCompletion(expectedTransfer);
  monitor.subTask("Host is starting to send...");
  log.debug(this + ": Host is starting to send...");

  try (InputStream transmissionStream = expectedTransfer.get().acceptStream();
      CountingInputStream countStream = new CountingInputStream(transmissionStream);
      IncomingStreamProtocol isp = new IncomingStreamProtocol(countStream, session, monitor)) {
    isp.receiveStream();
    log.debug("stream bytes received: " + countStream.getByteCount());
  } catch (InterruptedException | ExecutionException e) {
    throw new LocalCancellationException(e.getMessage(), CancelOption.NOTIFY_PEER);
  }

  log.debug(this + ": stream transmission done");
  monitor.done();
}
 
public DoubleMatrixDatasetRandomAccessReader(String filename) throws IOException {

		this.path = new File(filename + ".dat");
		channel = new RandomAccessFile(path, "r").getChannel();
		filesize = channel.size();
		counter = new CountingInputStream(new BufferedInputStream(Channels.newInputStream(channel), buffersize));
		is = new DataInputStream(counter);

		nrRows = is.readInt();
		nrCols = is.readInt();

		hashRows = (LinkedHashMap<R, Integer>) DoubleMatrixDataset.loadIdentifiers(filename + ".rows.txt");
		hashCols = (LinkedHashMap<C, Integer>) DoubleMatrixDataset.loadIdentifiers(filename + ".cols.txt");

		headerLen = 8;
		bytesPerRow = 8 * nrCols;
		buffersize = bytesPerRow * 10;
		currentPos = headerLen;
		System.out.println(filename + " is " + nrRows + " rows and " + nrCols + " cols; bytes per row: " + bytesPerRow);
	}
 
public void open(String loc) throws IOException {
	channel = new RandomAccessFile(loc + ".dat", "rw").getChannel();
	CountingInputStream countertmp = new CountingInputStream(new BufferedInputStream(Channels.newInputStream(channel), buffersize));
	DataInputStream is = new DataInputStream(countertmp);
	nrRows = is.readInt();
	nrCols = is.readInt();
	hashRows = DoubleMatrixDataset.loadIdentifiers(loc + ".rows.txt");
	hashCols = DoubleMatrixDataset.loadIdentifiers(loc + ".cols.txt");

	headerLen = 8;
	currentPos = headerLen;
	bytesPerRow = 8 * nrCols;
	buffersize = bytesPerRow * 10;
	channel.position(currentPos);
	counter = new CountingOutputStream(new BufferedOutputStream(Channels.newOutputStream(channel), buffersize));
	os = new DataOutputStream(counter);

	System.out.println("Read header. current pos: " + channel.position());
	System.out.println("Header: " + headerLen);
}
 
源代码12 项目: ratel   文件: ARSCDecoder.java
private ARSCDecoder(InputStream arscStream, ResTable resTable, boolean storeFlagsOffsets, boolean keepBroken) {
    arscStream = mCountIn = new CountingInputStream(arscStream);
    if (storeFlagsOffsets) {
        mFlagsOffsets = new ArrayList<FlagsOffset>();
    } else {
        mFlagsOffsets = null;
    }
    // We need to explicitly cast to DataInput as otherwise the constructor is ambiguous.
    // We choose DataInput instead of InputStream as ExtDataInput wraps an InputStream in
    // a DataInputStream which is big-endian and ignores the little-endian behavior.
    mIn = new ExtDataInput((DataInput) new LittleEndianDataInputStream(arscStream));
    mResTable = resTable;
    mKeepBroken = keepBroken;
}
 
源代码13 项目: ratel   文件: ARSCDecoder.java
public static Header read(ExtDataInput in, CountingInputStream countIn) throws IOException {
    short type;
    int start = countIn.getCount();
    try {
        type = in.readShort();
    } catch (EOFException ex) {
        return new Header(TYPE_NONE, 0, 0, countIn.getCount());
    }
    return new Header(type, in.readShort(), in.readInt(), start);
}
 
源代码14 项目: cyberduck   文件: SwiftReadFeatureTest.java
@Test
public void testReadCloseReleaseEntity() throws Exception {
    final TransferStatus status = new TransferStatus();
    final Path container = new Path(".ACCESS_LOGS", EnumSet.of(Path.Type.directory, Path.Type.volume));
    container.attributes().setRegion("DFW");
    final SwiftRegionService regionService = new SwiftRegionService(session);
    final CountingInputStream in = new CountingInputStream(new SwiftReadFeature(session, regionService).read(new Path(container,
        "/cdn.cyberduck.ch/2015/03/01/10/3b1d6998c430d58dace0c16e58aaf925.log.gz",
        EnumSet.of(Path.Type.file)), status, new DisabledConnectionCallback()));
    in.close();
    assertEquals(0L, in.getByteCount(), 0L);
}
 
源代码15 项目: cyberduck   文件: DAVReadFeatureTest.java
@Test
public void testReadCloseReleaseEntity() throws Exception {
    final Host host = new Host(new DAVSSLProtocol(), "svn.cyberduck.ch", new Credentials(
        PreferencesFactory.get().getProperty("connection.login.anon.name"), null
    ));
    final DAVSession session = new DAVSession(host, new DisabledX509TrustManager(), new DefaultX509KeyManager());
    session.open(Proxy.DIRECT, new DisabledHostKeyCallback(), new DisabledLoginCallback());
    session.login(Proxy.DIRECT, new DisabledLoginCallback(), new DisabledCancelCallback());
    final TransferStatus status = new TransferStatus();
    final Path test = new Path("/trunk/LICENSE.txt", EnumSet.of(Path.Type.file));
    final CountingInputStream in = new CountingInputStream(new DAVReadFeature(session).read(test, status, new DisabledConnectionCallback()));
    in.close();
    assertEquals(0L, in.getByteCount(), 0L);
    session.close();
}
 
源代码16 项目: cyberduck   文件: DriveReadFeatureTest.java
@Test
public void testReadWhitespace() throws Exception {
    final DriveFileidProvider fileid = new DriveFileidProvider(session).withCache(cache);
    final Path file = new DriveTouchFeature(session, fileid).touch(new Path(DriveHomeFinderService.MYDRIVE_FOLDER, String.format("t %s", new AlphanumericRandomStringService().random()), EnumSet.of(Path.Type.file)), new TransferStatus());
    assertEquals(0, new DriveAttributesFinderFeature(session, fileid).find(file).getSize());
    final CountingInputStream in = new CountingInputStream(new DriveReadFeature(session, fileid).read(file, new TransferStatus(), new DisabledConnectionCallback()));
    in.close();
    assertEquals(0L, in.getByteCount(), 0L);
    new DriveDeleteFeature(session, fileid).delete(Collections.singletonList(file), new DisabledLoginCallback(), new Delete.DisabledCallback());
}
 
源代码17 项目: cyberduck   文件: DriveReadFeatureTest.java
@Test
public void testReadPath() throws Exception {
    final DriveFileidProvider fileid = new DriveFileidProvider(session).withCache(cache);
    final Path directory = new DriveDirectoryFeature(session, fileid).mkdir(new Path(DriveHomeFinderService.MYDRIVE_FOLDER, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.directory)), null, new TransferStatus());
    final Path file = new DriveTouchFeature(session, fileid).touch(new Path(directory, String.format("t %s", new AlphanumericRandomStringService().random()), EnumSet.of(Path.Type.file)), new TransferStatus());
    assertEquals(0, new DriveAttributesFinderFeature(session, fileid).find(file).getSize());
    final CountingInputStream in = new CountingInputStream(new DriveReadFeature(session, fileid).read(file, new TransferStatus(), new DisabledConnectionCallback()));
    in.close();
    assertEquals(0L, in.getByteCount(), 0L);
    new DriveDeleteFeature(session, fileid).delete(Arrays.asList(file, directory), new DisabledLoginCallback(), new Delete.DisabledCallback());
}
 
源代码18 项目: cyberduck   文件: DriveReadFeatureTest.java
@Test
public void testReadEmpty() throws Exception {
    final DriveFileidProvider fileid = new DriveFileidProvider(session).withCache(cache);
    final Path directory = new DriveDirectoryFeature(session, fileid).mkdir(new Path(DriveHomeFinderService.MYDRIVE_FOLDER, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.directory)), null, new TransferStatus());
    final Path file = new DriveTouchFeature(session, fileid).touch(new Path(directory, String.format("t %s", new AlphanumericRandomStringService().random()), EnumSet.of(Path.Type.file)), new TransferStatus());
    assertEquals(0, new DriveAttributesFinderFeature(session, fileid).find(file).getSize());
    final CountingInputStream in = new CountingInputStream(new DriveReadFeature(session, fileid).read(file, new TransferStatus(), new DisabledConnectionCallback()));
    in.close();
    assertEquals(0L, in.getByteCount(), 0L);
    new DriveDeleteFeature(session, fileid).delete(Arrays.asList(file, directory), new DisabledLoginCallback(), new Delete.DisabledCallback());
}
 
public FixedLengthInputStream(InputStream stream, long maxLen) {
  super(new CountingInputStream(new CloseShieldInputStream(stream)));

  // Save a correctly-typed reference to the underlying stream.
  this.countingIn = (CountingInputStream) this.in;
  this.maxBytes = maxLen;
}
 
源代码20 项目: tus-java-server   文件: TusServletRequest.java
public InputStream getContentInputStream() throws IOException {
    if (contentInputStream == null) {
        contentInputStream = super.getInputStream();

        //If we're dealing with chunked transfer encoding,
        //abstract it so that the rest of our code doesn't need to care
        boolean isChunked = hasChunkedTransferEncoding();
        if (isChunked && isChunkedTransferDecodingEnabled) {
            contentInputStream = new HttpChunkedEncodingInputStream(contentInputStream, trailerHeaders);
        }

        countingInputStream = new CountingInputStream(contentInputStream);
        contentInputStream = countingInputStream;

        ChecksumAlgorithm checksumAlgorithm = ChecksumAlgorithm.forUploadChecksumHeader(
                getHeader(HttpHeader.UPLOAD_CHECKSUM));

        List<ChecksumAlgorithm> algorithms;

        if (isChunked) {
            //Since the Checksum header can still come at the end, keep track of all checksums
            algorithms = Arrays.asList(ChecksumAlgorithm.values());
        } else if (checksumAlgorithm != null) {
            algorithms = Collections.singletonList(checksumAlgorithm);
        } else {
            algorithms = Collections.emptyList();
        }

        for (ChecksumAlgorithm algorithm : algorithms) {
            DigestInputStream is = new DigestInputStream(contentInputStream, algorithm.getMessageDigest());
            digestInputStreamMap.put(algorithm, is);

            contentInputStream = is;
        }
    }

    return contentInputStream;
}
 
源代码21 项目: BUbiNG   文件: BoundSessionInputBuffer.java
/**
 * Creates a new {@link SessionInputBuffer} bounded to a given maximum length.
 *
 * @param buffer the buffer to wrap
 * @param length the maximum number of bytes to read (from the buffered stream).
 */
public BoundSessionInputBuffer(final SessionInputBuffer buffer, final long length) {
	super(new HttpTransportMetricsImpl(), BUFFER_SIZE, 0, null, null);
	this.bounded = new ContentLengthInputStream(buffer, length);
	this.input = new CountingInputStream(this.bounded);
	super.bind(this.input);
	this.length = length;
}
 
源代码22 项目: lavaplayer   文件: RemoteNodeProcessor.java
private boolean handleResponseBody(InputStream inputStream, TickBuilder tickBuilder) {
  CountingInputStream countingStream = new CountingInputStream(inputStream);
  DataInputStream input = new DataInputStream(countingStream);
  RemoteMessage message;

  try {
    while ((message = mapper.decode(input)) != null) {
      if (message instanceof TrackStartResponseMessage) {
        handleTrackStartResponse((TrackStartResponseMessage) message);
      } else if (message instanceof TrackFrameDataMessage) {
        handleTrackFrameData((TrackFrameDataMessage) message);
      } else if (message instanceof TrackExceptionMessage) {
        handleTrackException((TrackExceptionMessage) message);
      } else if (message instanceof NodeStatisticsMessage) {
        handleNodeStatistics((NodeStatisticsMessage) message);
      }
    }
  } catch (InterruptedException interruption) {
    log.error("Node {} processing thread was interrupted.", nodeAddress);
    Thread.currentThread().interrupt();
    return false;
  } catch (Throwable e) {
    log.error("Error when processing response from node {}.", nodeAddress, e);
    ExceptionTools.rethrowErrors(e);
  } finally {
    tickBuilder.responseSize = countingStream.getCount();
  }

  return true;
}
 
源代码23 项目: rdf-delta   文件: LogOp.java
private static RDFPatch readPatch(DeltaAction action) throws IOException {
    HttpServletRequest request = action.request;
    long byteLength = request.getContentLengthLong();
    try ( CountingInputStream in = new CountingInputStream(request.getInputStream()); ) {
        RDFPatch patch = RDFPatchOps.read(in);
        if ( byteLength != -1L ) {
            if ( in.getByteCount() != byteLength )
                FmtLog.warn(LOG, "[%d] Length mismatch: Read: %d : Content-Length: %d", action.id, in.getByteCount(),  byteLength);
        }
        return patch;
    }
}
 
源代码24 项目: AndResGuard   文件: RawARSCDecoder.java
public static Header read(ExtDataInput in, CountingInputStream countIn) throws IOException {
  short type;
  int start = countIn.getCount();
  try {
    type = in.readShort();
  } catch (EOFException ex) {
    return new Header(TYPE_NONE, 0, 0, countIn.getCount());
  }
  return new Header(type, in.readShort(), in.readInt(), start);
}
 
源代码25 项目: phoenicis   文件: PEReader.java
public PEFile parseExecutable(InputStream inputStream) throws IOException {
    try (CountingInputStream executableInputStream = new CountingInputStream(inputStream)) {
        final ImageDOSHeader imageDOSHeader = readDosHeader(executableInputStream);
        final byte[] realModeStubProgram = readRealModeStubProgram(executableInputStream, imageDOSHeader);
        final ImageNTHeaders imageNTHeaders = readImageNTHeaders(executableInputStream);
        final SectionHeader[] sectionHeaders = readSectionHeaders(executableInputStream, imageNTHeaders);
        final RsrcSection resourceSection = readResourceSection(executableInputStream, sectionHeaders);
        return new PEFile(imageDOSHeader, realModeStubProgram, imageNTHeaders, sectionHeaders, resourceSection);
    }
}
 
源代码26 项目: phoenicis   文件: PEReader.java
private SectionHeader[] readSectionHeaders(CountingInputStream executableInputStream, ImageNTHeaders imageNTHeaders)
        throws IOException {
    final int numberOfSectionHeaders = imageNTHeaders.fileHeader.numberOfSections.getUnsignedValue();
    final SectionHeader[] sectionHeaders = new SectionHeader[numberOfSectionHeaders];
    for (int i = 0; i < numberOfSectionHeaders; i++) {
        byte[] sectionHeaderBytes = new byte[SectionHeader.SECTION_HEADER_SIZE];
        executableInputStream.read(sectionHeaderBytes);
        sectionHeaders[i] = new SectionHeader(sectionHeaderBytes);
    }
    return sectionHeaders;
}
 
源代码27 项目: InflatableDonkey   文件: ChunkListDecrypter.java
/**
 *
 * @param container
 * @param inputStream closed on exit
 * @param store
 * @throws IOException
 * @throws ArithmeticException on input streams over 2 Gb.
 * @throws IllegalArgumentException on non 0x01 chunk keys
 */
public void apply(StorageHostChunkList container, InputStream inputStream, ChunkStore store) throws IOException {
    logger.trace("<< apply() - input: {}", inputStream);
    // Ensure our chunk offsets are sequentially ordered.
    List<ChunkInfo> list = container.getChunkInfoList()
            .stream()
            .sorted(CHUNK_OFFSET_COMPARATOR)
            .collect(toList());

    try (CountingInputStream countingInputStream = new CountingInputStream(inputStream)) {
        streamChunks(list, countingInputStream, store);
    } catch (UncheckedIOException ex) {
        throw ex.getCause();
    }

    if (logger.isDebugEnabled()) {
        // Sanity check. Has a minor IO cost with a disk based chunk store.
        String missingChunks = list.stream()
                .map(ci -> ci.getChunkChecksum().toByteArray())
                .filter(c -> !store.contains(c))
                .map(c -> "0x" + Hex.toHexString(c))
                .collect(joining(" "));
        if (missingChunks.isEmpty()) {
            logger.debug("-- apply() - all chunks have been stored");
        } else {
            logger.warn("-- apply() - missing chunks: {}", missingChunks);
        }
    }
    logger.trace(">> apply()");
}
 
源代码28 项目: InflatableDonkey   文件: ChunkListDecrypter.java
void streamChunks(List<ChunkInfo> chunkInfos, CountingInputStream inputStream, ChunkStore store) {
    logger.debug("-- streamChunks() - chunk count: {}", chunkInfos.size());
    chunkInfos.stream()
            .peek(ci -> logger.debug("-- streamChunks() - chunk info: {}", ci))
            .filter(u -> isChunkMissing(u, store))
            .forEach(u -> streamChunk(inputStream, inputStream.getCount(), u, store));
}
 
源代码29 项目: webarchive-commons   文件: HTTPURLConnSLR.java
@Override
protected InputStream doSeekLoad(long offset, int maxLength)
		throws IOException {
	
	URL theUrl = new URL(url);		
	
       URLConnection connection = theUrl.openConnection();
       
       httpUrlConn = (HttpURLConnection)connection;
       
       connection.setConnectTimeout(connTimeout);
       connection.setReadTimeout(readTimeout);
       
       String rangeHeader = makeRangeHeader(offset, maxLength);
       
       if (rangeHeader != null) {
       	httpUrlConn.addRequestProperty("Range", rangeHeader);
       }
       
	if (this.isNoKeepAlive()) {
		httpUrlConn.addRequestProperty("Connection", "close");
	}
	
	if (this.getCookie() != null) {
		httpUrlConn.addRequestProperty("Cookie", cookie);
	}
	
	httpUrlConn.connect();
	
	int code = httpUrlConn.getResponseCode();
	connectedUrl =  httpUrlConn.getURL().toString();
	
	if ((code != 206) && (code != 200)) {
		throw new BadHttpStatusException(code, connectedUrl + " " + rangeHeader);
	}
	
	InputStream is = httpUrlConn.getInputStream();
	cin = new CountingInputStream(is);
	return cin;
}
 
源代码30 项目: arx   文件: ImportAdapterCSV.java
/**
 * Creates a new instance of this object with given configuration.
 *
 * @param config {@link #config}
 * @throws IOException In case file doesn't contain actual data
 */
protected ImportAdapterCSV(ImportConfigurationCSV config) throws IOException {

    super(config);
    this.config = config;
    this.bytesTotal = new File(config.getFileLocation()).length();

    /* Used to keep track of progress */
    cin = new CountingInputStream(new FileInputStream(new File(config.getFileLocation())));

    /* Determine length*/
    if (config.isOptimizedLoading()) {
        records = getLength(new FileInputStream(new File(config.getFileLocation())), config.getCharset(), config.getDelimiter(), config.getQuote(), config.getEscape(), config.getLinebreak(), config.getMaxColumns());
    }
    
    /* Get CSV iterator */
    in = new CSVDataInput(cin, config.getCharset(), config.getDelimiter(), config.getQuote(), config.getEscape(), config.getLinebreak(), new CSVOptions(config.getMaxColumns()));
    it = in.iterator(config.getContainsHeader());

    /* Check whether there is actual data within the CSV file */
    if (it.hasNext()) {
        row = it.next();
        if (config.getContainsHeader()) {
            if (!it.hasNext()) {
                throw new IOException("CSV contains nothing but header");
            }
        }
    } else {
        throw new IOException("CSV file contains no data");
    }

    // Create header
    header = createHeader();
}
 
 类所在包
 类方法
 同包方法