本文整理汇总了Java中org.apache.commons.io.input.CountingInputStream类的典型用法代码示例。如果您正苦于以下问题:Java CountingInputStream类的具体用法?Java CountingInputStream怎么用?Java CountingInputStream使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
CountingInputStream类属于org.apache.commons.io.input包,在下文中一共展示了CountingInputStream类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testReadCloseReleaseEntity
import org.apache.commons.io.input.CountingInputStream; //导入依赖的package包/类
@Test
public void testReadCloseReleaseEntity() throws Exception {
final Host host = new Host(new SwiftProtocol(), "identity.api.rackspacecloud.com", new Credentials(
System.getProperties().getProperty("rackspace.key"), System.getProperties().getProperty("rackspace.secret")
));
final SwiftSession session = new SwiftSession(host);
session.open(new DisabledHostKeyCallback(), new DisabledLoginCallback());
session.login(new DisabledPasswordStore(), new DisabledLoginCallback(), new DisabledCancelCallback());
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);
session.close();
}
示例2: testReadCloseReleaseEntity
import org.apache.commons.io.input.CountingInputStream; //导入依赖的package包/类
@Test
public void testReadCloseReleaseEntity() throws Exception {
final Host host = new Host(new SDSProtocol(), "duck.ssp-europe.eu", new Credentials(
System.getProperties().getProperty("sds.user"), System.getProperties().getProperty("sds.key")
));
final SDSSession session = new SDSSession(host, new DisabledX509TrustManager(), new DefaultX509KeyManager());
session.open(new DisabledHostKeyCallback(), new DisabledLoginCallback());
session.login(new DisabledPasswordStore(), new DisabledLoginCallback(), new DisabledCancelCallback());
final TransferStatus status = new TransferStatus();
final byte[] content = RandomUtils.nextBytes(32769);
final TransferStatus writeStatus = new TransferStatus();
writeStatus.setLength(content.length);
final Path room = new SDSDirectoryFeature(session).mkdir(
new Path(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 SDSWriteFeature writer = new SDSWriteFeature(session);
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).read(test, status, new DisabledConnectionCallback()));
in.close();
assertEquals(0L, in.getByteCount(), 0L);
new SDSDeleteFeature(session).delete(Collections.singletonList(room), new DisabledLoginCallback(), new Delete.DisabledCallback());
session.close();
}
示例3: testReadCloseReleaseEntity
import org.apache.commons.io.input.CountingInputStream; //导入依赖的package包/类
@Test
public void testReadCloseReleaseEntity() throws Exception {
final Host host = new Host(new S3Protocol(), new S3Protocol().getDefaultHostname(), new Credentials(
System.getProperties().getProperty("s3.key"), System.getProperties().getProperty("s3.secret")
));
final S3Session session = new S3Session(host);
session.open(new DisabledHostKeyCallback(), new DisabledLoginCallback());
session.login(new DisabledPasswordStore(), new DisabledLoginCallback(), new DisabledCancelCallback());
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());
session.close();
}
示例4: readTable
import org.apache.commons.io.input.CountingInputStream; //导入依赖的package包/类
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;
}
示例5: MonitoredFileReader
import org.apache.commons.io.input.CountingInputStream; //导入依赖的package包/类
public MonitoredFileReader(String fileName, InputStream is, long length, String encoding, double reportProgressAfter) throws IOException {
InputStream in = countingIn = new CountingInputStream(is);
if (fileName.endsWith(".gz")) {
try {
@SuppressWarnings("resource")
InputStream gzIn = new GZIPInputStream(in);
log.info("[" + fileName + "] GZipped file detected. Reading using decompressor.");
in = gzIn;
} catch (ZipException e) {
// proceed like nothing happened (gzIn has not been assigned to in)
log.error("[" + fileName + "] Warning: Unsuccessfully tried top uncompress file ending with .gz, reading file without decompression.", e);
}
}
inReader = new InputStreamReader(in, encoding);
monitor = new ProgressMonitor(fileName, "bytes", length, reportProgressAfter);
}
示例6: readResourceSection
import org.apache.commons.io.input.CountingInputStream; //导入依赖的package包/类
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);
}
示例7: create_socket_and_listen
import org.apache.commons.io.input.CountingInputStream; //导入依赖的package包/类
/**
* Establish socket connection with client
*/
private void create_socket_and_listen() throws Exception {
sock = new ServerSocket(EstimateNConfig.socketPort); // create socket and bind to port
System.out.println("waiting for client to connect");
clientSocket = sock.accept(); // wait for client to connect
System.out.println("client has connected");
CountingOutputStream cos = new CountingOutputStream(clientSocket.getOutputStream());
CountingInputStream cis = new CountingInputStream(clientSocket.getInputStream());
ProgCommon.oos = new ObjectOutputStream(cos);
ProgCommon.ois = new ObjectInputStream(cis);
StopWatch.cos = cos;
StopWatch.cis = cis;
}
示例8: processSha1SyncResponse
import org.apache.commons.io.input.CountingInputStream; //导入依赖的package包/类
private boolean processSha1SyncResponse(Response response) throws IOException {
int expected = m_server.level() + 1;
CountingInputStream counter = new CountingInputStream(response.getResultStream());
InputStreamReader reader = new InputStreamReader(new BufferedInputStream(counter), UTF8.UTF8);
try {
m_server = new Gson().fromJson(reader, Sha1SyncJson.class);
if (expected != m_server.level()) {
throw new IllegalStateException("Level warp! expected("+expected+"), actual("+m_server.level()+")");
}
if (!versionFeatures.getToken().equals(m_server.version())) {
throw new IllegalStateException("Version warp! expected("+versionFeatures.getToken()+"), actual("+m_server.version()+")");
}
if (isServerEmpty()) {
clearLocal();
return true;
}
if (isServerHashesEmpty()) {
return true;
}
return false;
} finally {
m_rxBytes += counter.getByteCount();
reader.close();
}
}
示例9: invoke
import org.apache.commons.io.input.CountingInputStream; //导入依赖的package包/类
public Void invoke(File dir, VirtualChannel channel) throws IOException, InterruptedException {
URLConnection con = archive.openConnection();
// Jira Bug JENKINS-21033: Changing the User-Agent from "Java/<Java version #>" to "Jenkins/<Jenkins version #>"
con.setRequestProperty("User-Agent", "Jenkins/" + Jenkins.getVersion().toString());
InputStream in = con.getInputStream();
try {
CountingInputStream cis = new CountingInputStream(in);
try {
LOGGER.log(Level.INFO, "Invoke called for Unpack class to unpack to " + dir.getAbsolutePath());
if (archive.toExternalForm().endsWith(".zip")) {
LOGGER.log(Level.INFO, "Archive unzipped as it ends with '.zip'. Starting unzip.");
unzip(dir, cis);
}
} catch (IOException x) {
throw new IOException(String.format("Failed to unpack %s (%d bytes read)", archive, cis.getByteCount()), x);
}
} finally {
in.close();
}
return null;
}
示例10: ARSCDecoder
import org.apache.commons.io.input.CountingInputStream; //导入依赖的package包/类
private ARSCDecoder(InputStream arscStream, ResTable resTable, boolean storeFlagsOffsets, boolean keepBroken) {
arscStream = mCountIn = new CountingInputStream(arscStream);
if (storeFlagsOffsets) {
mFlagsOffsets = new ArrayList<FlagsOffset>();
} else {
mFlagsOffsets = null;
}
mIn = new ExtDataInput(new LittleEndianDataInputStream(arscStream));
mResTable = resTable;
mKeepBroken = keepBroken;
}
示例11: read
import org.apache.commons.io.input.CountingInputStream; //导入依赖的package包/类
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);
}
示例12: testReadCloseReleaseEntity
import org.apache.commons.io.input.CountingInputStream; //导入依赖的package包/类
@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);
session.open(new DisabledHostKeyCallback(), new DisabledLoginCallback());
session.login(new DisabledPasswordStore(), 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();
}
示例13: FixedLengthInputStream
import org.apache.commons.io.input.CountingInputStream; //导入依赖的package包/类
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;
}
示例14: BoundSessionInputBuffer
import org.apache.commons.io.input.CountingInputStream; //导入依赖的package包/类
/**
* 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;
}
示例15: saveDocument
import org.apache.commons.io.input.CountingInputStream; //导入依赖的package包/类
private void saveDocument(DownloadableDocument document, Path target) throws IOException {
Page downloadPage = browser.getPage(document.getDownloadLink());
WebResponse response = downloadPage.getWebResponse();
document.setSize(response.getContentLength());
try (CountingInputStream in = new CountingInputStream(response.getContentAsStream())) {
copy(in, target, document);
}
}