本文整理汇总了Java中libcore.io.Streams类的典型用法代码示例。如果您正苦于以下问题:Java Streams类的具体用法?Java Streams怎么用?Java Streams使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Streams类属于libcore.io包,在下文中一共展示了Streams类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: readAndVerifyDataDescriptor
import libcore.io.Streams; //导入依赖的package包/类
private void readAndVerifyDataDescriptor(int inB, int out) throws IOException {
if (hasDD) {
Streams.readFully(in, hdrBuf, 0, EXTHDR);
int sig = Memory.peekInt(hdrBuf, 0, true);
if (sig != (int) EXTSIG) {
throw new ZipException(String.format("unknown format (EXTSIG=%x)", sig));
}
currentEntry.crc = ((long) Memory.peekInt(hdrBuf, EXTCRC, true)) & 0xffffffffL;
currentEntry.compressedSize = ((long) Memory.peekInt(hdrBuf, EXTSIZ, true)) & 0xffffffffL;
currentEntry.size = ((long) Memory.peekInt(hdrBuf, EXTLEN, true)) & 0xffffffffL;
}
if (currentEntry.crc != crc.getValue()) {
throw new ZipException("CRC mismatch");
}
if (currentEntry.compressedSize != inB || currentEntry.size != out) {
throw new ZipException("Size mismatch");
}
}
开发者ID:jtransc,项目名称:jtransc,代码行数:19,代码来源:ZipInputStream.java
示例2: read
import libcore.io.Streams; //导入依赖的package包/类
/**
* Merges name/attribute pairs read from the input stream {@code is} into this manifest.
*
* @param is
* The {@code InputStream} to read from.
* @throws IOException
* If an error occurs reading the manifest.
*/
public void read(InputStream is) throws IOException {
byte[] buf;
if (is instanceof ByteArrayInputStream) {
buf = exposeByteArrayInputStreamBytes((ByteArrayInputStream) is);
} else {
buf = Streams.readFullyNoClose(is);
}
if (buf.length == 0) {
return;
}
// a workaround for HARMONY-5662
// replace EOF and NUL with another new line
// which does not trigger an error
byte b = buf[buf.length - 1];
if (b == 0 || b == 26) {
buf[buf.length - 1] = '\n';
}
ManifestReader im = new ManifestReader(buf, mainAttributes);
mainEnd = im.getEndOfMainSection();
im.readEntries(entries, chunks);
}
开发者ID:jtransc,项目名称:jtransc,代码行数:33,代码来源:Manifest.java
示例3: readAndVerifyDataDescriptor
import libcore.io.Streams; //导入依赖的package包/类
private void readAndVerifyDataDescriptor(int inB, int out) throws IOException {
if (hasDD) {
Streams.readFully(in, hdrBuf, 0, EXTHDR);
int sig = Memory.peekInt(hdrBuf, 0, ByteOrder.LITTLE_ENDIAN);
if (sig != (int) EXTSIG) {
throw new ZipException(String.format("unknown format (EXTSIG=%x)", sig));
}
currentEntry.crc = ((long) Memory.peekInt(hdrBuf, EXTCRC, ByteOrder.LITTLE_ENDIAN)) & 0xffffffffL;
currentEntry.compressedSize = ((long) Memory.peekInt(hdrBuf, EXTSIZ, ByteOrder.LITTLE_ENDIAN)) & 0xffffffffL;
currentEntry.size = ((long) Memory.peekInt(hdrBuf, EXTLEN, ByteOrder.LITTLE_ENDIAN)) & 0xffffffffL;
}
if (currentEntry.crc != crc.getValue()) {
throw new ZipException("CRC mismatch");
}
if (currentEntry.compressedSize != inB || currentEntry.size != out) {
throw new ZipException("Size mismatch");
}
}
开发者ID:Sellegit,项目名称:j2objc,代码行数:19,代码来源:ZipInputStream.java
示例4: verifyCrc
import libcore.io.Streams; //导入依赖的package包/类
private void verifyCrc() throws IOException {
// Get non-compressed bytes read by fill
int size = inf.getRemaining();
final int trailerSize = 8; // crc (4 bytes) + total out (4 bytes)
byte[] b = new byte[trailerSize];
int copySize = (size > trailerSize) ? trailerSize : size;
System.arraycopy(buf, len - size, b, 0, copySize);
Streams.readFully(in, b, copySize, trailerSize - copySize);
if (Memory.peekInt(b, 0, ByteOrder.LITTLE_ENDIAN) != (int) crc.getValue()) {
throw new IOException("CRC mismatch");
}
if (Memory.peekInt(b, 4, ByteOrder.LITTLE_ENDIAN) != inf.getTotalOut()) {
throw new IOException("Size mismatch");
}
}
开发者ID:Sellegit,项目名称:j2objc,代码行数:18,代码来源:GZIPInputStream.java
示例5: readChunkSize
import libcore.io.Streams; //导入依赖的package包/类
private void readChunkSize() throws IOException {
// read the suffix of the previous chunk
if (bytesRemainingInChunk != NO_CHUNK_YET) {
Streams.readAsciiLine(in);
}
String chunkSizeString = Streams.readAsciiLine(in);
int index = chunkSizeString.indexOf(";");
if (index != -1) {
chunkSizeString = chunkSizeString.substring(0, index);
}
try {
bytesRemainingInChunk = Integer.parseInt(chunkSizeString.trim(), 16);
} catch (NumberFormatException e) {
throw new IOException("Expected a hex chunk size, but was " + chunkSizeString);
}
if (bytesRemainingInChunk == 0) {
hasMoreChunks = false;
httpEngine.readTrailers();
endOfInput(true);
}
}
开发者ID:Mobideck,项目名称:appdeck-android,代码行数:22,代码来源:ChunkedInputStream.java
示例6: readCertArray
import libcore.io.Streams; //导入依赖的package包/类
private Certificate[] readCertArray(InputStream in) throws IOException {
int length = readInt(in);
if (length == -1) {
return null;
}
try {
CertificateFactory certificateFactory = CertificateFactory.getInstance("X.509");
Certificate[] result = new Certificate[length];
for (int i = 0; i < result.length; i++) {
String line = Streams.readAsciiLine(in);
byte[] bytes = Base64.decode(Strings.getBytes(line,Charsets.US_ASCII));
result[i] = certificateFactory.generateCertificate(
new ByteArrayInputStream(bytes));
}
return result;
} catch (CertificateException e) {
throw new IOException(e.toString());
}
}
开发者ID:Mobideck,项目名称:appdeck-android,代码行数:20,代码来源:HttpResponseCache.java
示例7: transferIncrementalRestoreData
import libcore.io.Streams; //导入依赖的package包/类
private int transferIncrementalRestoreData(String packageName, ParcelFileDescriptor outputFileDescriptor)
throws IOException, InvalidAlgorithmParameterException, InvalidKeyException {
ParcelFileDescriptor inputFileDescriptor = buildInputFileDescriptor();
ZipInputStream inputStream = buildInputStream(inputFileDescriptor);
BackupDataOutput backupDataOutput = new BackupDataOutput(outputFileDescriptor.getFileDescriptor());
Optional<ZipEntry> zipEntryOptional = seekToEntry(inputStream,
configuration.getIncrementalBackupDirectory() + packageName);
while (zipEntryOptional.isPresent()) {
String fileName = new File(zipEntryOptional.get().getName()).getName();
String blobKey = new String(Base64.decode(fileName, Base64.DEFAULT));
byte[] backupData = Streams.readFullyNoClose(inputStream);
backupDataOutput.writeEntityHeader(blobKey, backupData.length);
backupDataOutput.writeEntityData(backupData, backupData.length);
inputStream.closeEntry();
zipEntryOptional = seekToEntry(inputStream, configuration.getIncrementalBackupDirectory() + packageName);
}
IoUtils.closeQuietly(inputFileDescriptor);
IoUtils.closeQuietly(outputFileDescriptor);
return TRANSPORT_OK;
}
开发者ID:stevesoltys,项目名称:backup,代码行数:26,代码来源:ContentProviderRestoreComponent.java
示例8: readResponseHeaders
import libcore.io.Streams; //导入依赖的package包/类
private void readResponseHeaders() throws IOException {
RawHeaders headers;
do {
headers = new RawHeaders();
headers.setStatusLine(Streams.readAsciiLine(socketIn));
readHeaders(headers);
} while (headers.getResponseCode() == HTTP_CONTINUE);
setResponse(new ResponseHeaders(uri, headers), null);
}
开发者ID:Mobideck,项目名称:appdeck-android,代码行数:10,代码来源:HttpEngine.java
示例9: readHeaders
import libcore.io.Streams; //导入依赖的package包/类
private void readHeaders(RawHeaders headers) throws IOException {
// parse the result headers until the first blank line
String line;
while (!Strings.isEmpty(line = Streams.readAsciiLine(socketIn))) {
headers.addLine(line);
}
CookieHandler cookieHandler = CookieHandler.getDefault();
if (cookieHandler != null) {
cookieHandler.put(uri, headers.toMultimap());
}
}
开发者ID:Mobideck,项目名称:appdeck-android,代码行数:13,代码来源:HttpEngine.java
示例10: Entry
import libcore.io.Streams; //导入依赖的package包/类
public Entry(InputStream in) throws IOException {
try {
uri = Streams.readAsciiLine(in);
requestMethod = Streams.readAsciiLine(in);
varyHeaders = new RawHeaders();
int varyRequestHeaderLineCount = readInt(in);
for (int i = 0; i < varyRequestHeaderLineCount; i++) {
varyHeaders.addLine(Streams.readAsciiLine(in));
}
responseHeaders = new RawHeaders();
responseHeaders.setStatusLine(Streams.readAsciiLine(in));
int responseHeaderLineCount = readInt(in);
for (int i = 0; i < responseHeaderLineCount; i++) {
responseHeaders.addLine(Streams.readAsciiLine(in));
}
if (isHttps()) {
String blank = Streams.readAsciiLine(in);
if (!Strings.isEmpty(blank)) {
throw new IOException("expected \"\" but was \"" + blank + "\"");
}
cipherSuite = Streams.readAsciiLine(in);
peerCertificates = readCertArray(in);
localCertificates = readCertArray(in);
} else {
cipherSuite = null;
peerCertificates = null;
localCertificates = null;
}
} finally {
in.close();
}
}
开发者ID:Mobideck,项目名称:appdeck-android,代码行数:35,代码来源:HttpResponseCache.java
示例11: readInt
import libcore.io.Streams; //导入依赖的package包/类
private int readInt(InputStream in) throws IOException {
String intString = Streams.readAsciiLine(in);
try {
return Integer.parseInt(intString);
} catch (NumberFormatException e) {
throw new IOException("expected an int but was \"" + intString + "\"");
}
}
开发者ID:Mobideck,项目名称:appdeck-android,代码行数:9,代码来源:HttpResponseCache.java
示例12: readTestFile
import libcore.io.Streams; //导入依赖的package包/类
public static byte[] readTestFile(String name) throws IOException {
return Streams.readFully(openTestFile(name));
}
开发者ID:google,项目名称:conscrypt,代码行数:4,代码来源:TestUtils.java
示例13: write
import libcore.io.Streams; //导入依赖的package包/类
@Override
public void write(int i) throws IOException {
Streams.writeSingleByte(this, i);
}
开发者ID:jtransc,项目名称:jtransc,代码行数:5,代码来源:DeflaterOutputStream.java
示例14: getNextEntry
import libcore.io.Streams; //导入依赖的package包/类
/**
* Returns the next entry from this {@code ZipInputStream} or {@code null} if
* no more entries are present.
*
* @throws IOException if an {@code IOException} occurs.
*/
public ZipEntry getNextEntry() throws IOException {
closeEntry();
if (entriesEnd) {
return null;
}
// Read the signature to see whether there's another local file header.
Streams.readFully(in, hdrBuf, 0, 4);
int hdr = Memory.peekInt(hdrBuf, 0, true);
if (hdr == CENSIG) {
entriesEnd = true;
return null;
}
if (hdr != LOCSIG) {
return null;
}
// Read the local file header.
Streams.readFully(in, hdrBuf, 0, (LOCHDR - LOCVER));
int version = peekShort(0) & 0xff;
if (version > ZIPLocalHeaderVersionNeeded) {
throw new ZipException("Cannot read local header version " + version);
}
int flags = peekShort(LOCFLG - LOCVER);
if ((flags & ZipFile.GPBF_UNSUPPORTED_MASK) != 0) {
throw new ZipException("Invalid General Purpose Bit Flag: " + flags);
}
hasDD = ((flags & ZipFile.GPBF_DATA_DESCRIPTOR_FLAG) != 0);
int ceLastModifiedTime = peekShort(LOCTIM - LOCVER);
int ceLastModifiedDate = peekShort(LOCTIM - LOCVER + 2);
int ceCompressionMethod = peekShort(LOCHOW - LOCVER);
long ceCrc = 0, ceCompressedSize = 0, ceSize = -1;
if (!hasDD) {
ceCrc = ((long) Memory.peekInt(hdrBuf, LOCCRC - LOCVER, true)) & 0xffffffffL;
ceCompressedSize = ((long) Memory.peekInt(hdrBuf, LOCSIZ - LOCVER, true)) & 0xffffffffL;
ceSize = ((long) Memory.peekInt(hdrBuf, LOCLEN - LOCVER, true)) & 0xffffffffL;
}
int nameLength = peekShort(LOCNAM - LOCVER);
if (nameLength == 0) {
throw new ZipException("Entry is not named");
}
int extraLength = peekShort(LOCEXT - LOCVER);
if (nameLength > nameBuf.length) {
nameBuf = new byte[nameLength];
// The bytes are modified UTF-8, so the number of chars will always be less than or
// equal to the number of bytes. It's fine if this buffer is too long.
}
Streams.readFully(in, nameBuf, 0, nameLength);
currentEntry = createZipEntry(ModifiedUtf8.decode(nameBuf, 0, nameLength));
currentEntry.time = ceLastModifiedTime;
currentEntry.modDate = ceLastModifiedDate;
currentEntry.setMethod(ceCompressionMethod);
if (ceSize != -1) {
currentEntry.setCrc(ceCrc);
currentEntry.setSize(ceSize);
currentEntry.setCompressedSize(ceCompressedSize);
}
if (extraLength > 0) {
byte[] extraData = new byte[extraLength];
Streams.readFully(in, extraData, 0, extraLength);
currentEntry.setExtra(extraData);
}
return currentEntry;
}
开发者ID:jtransc,项目名称:jtransc,代码行数:73,代码来源:ZipInputStream.java
示例15: ZipEntry
import libcore.io.Streams; //导入依赖的package包/类
ZipEntry(byte[] cdeHdrBuf, InputStream cdStream) throws IOException {
Streams.readFully(cdStream, cdeHdrBuf, 0, cdeHdrBuf.length);
BufferIterator it = HeapBufferIterator.iterator(cdeHdrBuf, 0, cdeHdrBuf.length,
ByteOrder.LITTLE_ENDIAN);
int sig = it.readInt();
if (sig != CENSIG) {
ZipFile.throwZipException("Central Directory Entry", sig);
}
it.seek(8);
int gpbf = it.readShort() & 0xffff;
if ((gpbf & ZipFile.GPBF_UNSUPPORTED_MASK) != 0) {
throw new ZipException("Invalid General Purpose Bit Flag: " + gpbf);
}
compressionMethod = it.readShort() & 0xffff;
time = it.readShort() & 0xffff;
modDate = it.readShort() & 0xffff;
// These are 32-bit values in the file, but 64-bit fields in this object.
crc = ((long) it.readInt()) & 0xffffffffL;
compressedSize = ((long) it.readInt()) & 0xffffffffL;
size = ((long) it.readInt()) & 0xffffffffL;
nameLength = it.readShort() & 0xffff;
int extraLength = it.readShort() & 0xffff;
int commentByteCount = it.readShort() & 0xffff;
// This is a 32-bit value in the file, but a 64-bit field in this object.
it.seek(42);
localHeaderRelOffset = ((long) it.readInt()) & 0xffffffffL;
byte[] nameBytes = new byte[nameLength];
Streams.readFully(cdStream, nameBytes, 0, nameBytes.length);
if (containsNulByte(nameBytes)) {
throw new ZipException("Filename contains NUL byte: " + Arrays.toString(nameBytes));
}
name = new String(nameBytes, 0, nameBytes.length, StandardCharsets.UTF_8);
if (extraLength > 0) {
extra = new byte[extraLength];
Streams.readFully(cdStream, extra, 0, extraLength);
}
// The RI has always assumed UTF-8. (If GPBF_UTF8_FLAG isn't set, the encoding is
// actually IBM-437.)
if (commentByteCount > 0) {
byte[] commentBytes = new byte[commentByteCount];
Streams.readFully(cdStream, commentBytes, 0, commentByteCount);
comment = new String(commentBytes, 0, commentBytes.length, StandardCharsets.UTF_8);
}
}
开发者ID:jtransc,项目名称:jtransc,代码行数:56,代码来源:ZipEntry.java
示例16: skip
import libcore.io.Streams; //导入依赖的package包/类
/**
* {@inheritDoc}
* <p>Note: if {@code n > Integer.MAX_VALUE}, this stream will only attempt to
* skip {@code Integer.MAX_VALUE} bytes.
*/
@Override
public long skip(long byteCount) throws IOException {
byteCount = Math.min(Integer.MAX_VALUE, byteCount);
return Streams.skipByReading(this, byteCount);
}
开发者ID:jtransc,项目名称:jtransc,代码行数:11,代码来源:DeflaterInputStream.java
示例17: write
import libcore.io.Streams; //导入依赖的package包/类
@Override public void write(int i) throws IOException {
Streams.writeSingleByte(this, i);
}
开发者ID:Sellegit,项目名称:j2objc,代码行数:4,代码来源:DeflaterOutputStream.java
示例18: getNextEntry
import libcore.io.Streams; //导入依赖的package包/类
/**
* Returns the next entry from this {@code ZipInputStream} or {@code null} if
* no more entries are present.
*
* @throws IOException if an {@code IOException} occurs.
*/
public ZipEntry getNextEntry() throws IOException {
closeEntry();
if (entriesEnd) {
return null;
}
// Read the signature to see whether there's another local file header.
Streams.readFully(in, hdrBuf, 0, 4);
int hdr = Memory.peekInt(hdrBuf, 0, ByteOrder.LITTLE_ENDIAN);
if (hdr == CENSIG) {
entriesEnd = true;
return null;
}
if (hdr != LOCSIG) {
return null;
}
// Read the local file header.
Streams.readFully(in, hdrBuf, 0, (LOCHDR - LOCVER));
int version = peekShort(0) & 0xff;
if (version > ZIPLocalHeaderVersionNeeded) {
throw new ZipException("Cannot read local header version " + version);
}
int flags = peekShort(LOCFLG - LOCVER);
if ((flags & ZipFile.GPBF_UNSUPPORTED_MASK) != 0) {
throw new ZipException("Invalid General Purpose Bit Flag: " + flags);
}
hasDD = ((flags & ZipFile.GPBF_DATA_DESCRIPTOR_FLAG) != 0);
int ceLastModifiedTime = peekShort(LOCTIM - LOCVER);
int ceLastModifiedDate = peekShort(LOCTIM - LOCVER + 2);
int ceCompressionMethod = peekShort(LOCHOW - LOCVER);
long ceCrc = 0, ceCompressedSize = 0, ceSize = -1;
if (!hasDD) {
ceCrc = ((long) Memory.peekInt(hdrBuf, LOCCRC - LOCVER, ByteOrder.LITTLE_ENDIAN)) & 0xffffffffL;
ceCompressedSize = ((long) Memory.peekInt(hdrBuf, LOCSIZ - LOCVER, ByteOrder.LITTLE_ENDIAN)) & 0xffffffffL;
ceSize = ((long) Memory.peekInt(hdrBuf, LOCLEN - LOCVER, ByteOrder.LITTLE_ENDIAN)) & 0xffffffffL;
}
int nameLength = peekShort(LOCNAM - LOCVER);
if (nameLength == 0) {
throw new ZipException("Entry is not named");
}
int extraLength = peekShort(LOCEXT - LOCVER);
if (nameLength > nameBuf.length) {
nameBuf = new byte[nameLength];
// The bytes are modified UTF-8, so the number of chars will always be less than or
// equal to the number of bytes. It's fine if this buffer is too long.
charBuf = new char[nameLength];
}
Streams.readFully(in, nameBuf, 0, nameLength);
currentEntry = createZipEntry(ModifiedUtf8.decode(nameBuf, charBuf, 0, nameLength));
currentEntry.time = ceLastModifiedTime;
currentEntry.modDate = ceLastModifiedDate;
currentEntry.setMethod(ceCompressionMethod);
if (ceSize != -1) {
currentEntry.setCrc(ceCrc);
currentEntry.setSize(ceSize);
currentEntry.setCompressedSize(ceCompressedSize);
}
if (extraLength > 0) {
byte[] extraData = new byte[extraLength];
Streams.readFully(in, extraData, 0, extraLength);
currentEntry.setExtra(extraData);
}
return currentEntry;
}
开发者ID:Sellegit,项目名称:j2objc,代码行数:74,代码来源:ZipInputStream.java
示例19: ZipEntry
import libcore.io.Streams; //导入依赖的package包/类
ZipEntry(byte[] hdrBuf, InputStream in) throws IOException {
Streams.readFully(in, hdrBuf, 0, hdrBuf.length);
BufferIterator it = HeapBufferIterator.iterator(hdrBuf, 0, hdrBuf.length, ByteOrder.LITTLE_ENDIAN);
int sig = it.readInt();
if (sig != CENSIG) {
throw new ZipException("Central Directory Entry not found");
}
it.seek(8);
int gpbf = it.readShort() & 0xffff;
if ((gpbf & ZipFile.GPBF_UNSUPPORTED_MASK) != 0) {
throw new ZipException("Invalid General Purpose Bit Flag: " + gpbf);
}
compressionMethod = it.readShort() & 0xffff;
time = it.readShort() & 0xffff;
modDate = it.readShort() & 0xffff;
// These are 32-bit values in the file, but 64-bit fields in this object.
crc = ((long) it.readInt()) & 0xffffffffL;
compressedSize = ((long) it.readInt()) & 0xffffffffL;
size = ((long) it.readInt()) & 0xffffffffL;
nameLength = it.readShort() & 0xffff;
int extraLength = it.readShort() & 0xffff;
int commentByteCount = it.readShort() & 0xffff;
// This is a 32-bit value in the file, but a 64-bit field in this object.
it.seek(42);
localHeaderRelOffset = ((long) it.readInt()) & 0xffffffffL;
byte[] nameBytes = new byte[nameLength];
Streams.readFully(in, nameBytes, 0, nameBytes.length);
if (containsNulByte(nameBytes)) {
throw new ZipException("Filename contains NUL byte: " + Arrays.toString(nameBytes));
}
name = new String(nameBytes, 0, nameBytes.length, StandardCharsets.UTF_8);
if (extraLength > 0) {
extra = new byte[extraLength];
Streams.readFully(in, extra, 0, extraLength);
}
// The RI has always assumed UTF-8. (If GPBF_UTF8_FLAG isn't set, the encoding is
// actually IBM-437.)
if (commentByteCount > 0) {
byte[] commentBytes = new byte[commentByteCount];
Streams.readFully(in, commentBytes, 0, commentByteCount);
comment = new String(commentBytes, 0, commentBytes.length, StandardCharsets.UTF_8);
}
}
开发者ID:Sellegit,项目名称:j2objc,代码行数:55,代码来源:ZipEntry.java
示例20: read
import libcore.io.Streams; //导入依赖的package包/类
@Override public int read() throws IOException {
return Streams.readSingleByte(this);
}
开发者ID:Sellegit,项目名称:j2objc,代码行数:4,代码来源:ZipFile.java
注:本文中的libcore.io.Streams类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论