本文整理汇总了Java中java.io.PushbackInputStream类的典型用法代码示例。如果您正苦于以下问题:Java PushbackInputStream类的具体用法?Java PushbackInputStream怎么用?Java PushbackInputStream使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
PushbackInputStream类属于java.io包,在下文中一共展示了PushbackInputStream类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: isInputStreamGZIPCompressed
import java.io.PushbackInputStream; //导入依赖的package包/类
/**
* Checks the InputStream if it contains GZIP compressed data
*
* @param inputStream InputStream to be checked
* @return true or false if the stream contains GZIP compressed data
* @throws java.io.IOException if read from inputStream fails
*/
public static boolean isInputStreamGZIPCompressed(final PushbackInputStream inputStream) throws IOException {
if (inputStream == null)
return false;
byte[] signature = new byte[2];
int count = 0;
try {
while (count < 2) {
int readCount = inputStream.read(signature, count, 2 - count);
if (readCount < 0) return false;
count = count + readCount;
}
} finally {
inputStream.unread(signature, 0, count);
}
int streamHeader = ((int) signature[0] & 0xff) | ((signature[1] << 8) & 0xff00);
return GZIPInputStream.GZIP_MAGIC == streamHeader;
}
示例2: isSerialized
import java.io.PushbackInputStream; //导入依赖的package包/类
/** Tests whether InputStream contains serialized data
* @param pbStream is pushback input stream; tests 4 bytes and then returns them back
* @return true if the file has serialized form
*/
static private final boolean isSerialized(PushbackInputStream pbStream)
throws IOException {
int[] serialPattern = { '\u00AC', '\u00ED', '\u0000', '\u0005' }; //NOI18N patern for serialized objects
byte[] checkedArray = new byte[serialPattern.length];
int unsignedConv = 0;
pbStream.read(checkedArray, 0, checkedArray.length);
pbStream.unread(checkedArray);
for (int i = 0; i < checkedArray.length; i++) {
unsignedConv = (checkedArray[i] < 0) ? (checkedArray[i] + 256) : checkedArray[i];
if (serialPattern[i] != unsignedConv) {
return false;
}
}
return true;
}
示例3: DeobfuscatingInputStream
import java.io.PushbackInputStream; //导入依赖的package包/类
/**
* @param in the stream to wrap
* @throws IOException
*/
public DeobfuscatingInputStream(InputStream in) throws IOException {
super(null);
final byte[] header = new byte[ObfuscatingOutputStream.HEADER.length()];
readFully(in, header, 0, header.length);
if (new String(header, "UTF-8").equals(ObfuscatingOutputStream.HEADER)) {
this.in = new DeobfuscatingInputStreamImpl(in);
}
else {
final PushbackInputStream pin =
new PushbackInputStream(in, header.length);
pin.unread(header);
this.in = pin;
}
}
示例4: readAhead
import java.io.PushbackInputStream; //导入依赖的package包/类
/**
* Fills {@code buf} with data from the given input stream and
* returns an input stream from which you can still read all data,
* including the data in buf.
*
* @param in The stream to read from.
* @param buf The buffer to fill entirely with data.
* @return A stream which holds all the data {@code in} did.
* @throws EOFException on unexpected end-of-file.
* @throws IOException on any I/O error.
*/
private static InputStream readAhead(
final @WillNotClose InputStream in,
final byte[] buf)
throws EOFException, IOException {
if (in.markSupported()) {
in.mark(buf.length);
new DataInputStream(in).readFully(buf);
in.reset();
return in;
} else {
final PushbackInputStream
pin = new PushbackInputStream(in, buf.length);
new DataInputStream(pin).readFully(buf);
pin.unread(buf);
return pin;
}
}
示例5: decodeLinePrefix
import java.io.PushbackInputStream; //导入依赖的package包/类
/**
* In uuencoded buffers, encoded lines start with a character that
* represents the number of bytes encoded in this line. The last
* line of input is always a line that starts with a single space
* character, which would be a zero length line.
*/
protected int decodeLinePrefix(PushbackInputStream inStream, OutputStream outStream) throws IOException {
int c;
c = inStream.read();
if (c == ' ') {
c = inStream.read(); /* discard the (first)trailing CR or LF */
c = inStream.read(); /* check for a second one */
if ((c != '\n') && (c != -1))
inStream.unread (c);
throw new CEStreamExhausted();
} else if (c == -1) {
throw new CEFormatException("UUDecoder: Short Buffer.");
}
c = (c - ' ') & 0x3f;
if (c > bytesPerLine()) {
throw new CEFormatException("UUDecoder: Bad Line Length.");
}
return (c);
}
示例6: decodeLineSuffix
import java.io.PushbackInputStream; //导入依赖的package包/类
/**
* Find the end of the line for the next operation.
* The following sequences are recognized as end-of-line
* CR, CR LF, or LF
*/
protected void decodeLineSuffix(PushbackInputStream inStream, OutputStream outStream) throws IOException {
int c;
while (true) {
c = inStream.read();
if (c == -1) {
throw new CEStreamExhausted();
}
if (c == '\n') {
break;
}
if (c == '\r') {
c = inStream.read();
if ((c != '\n') && (c != -1)) {
inStream.unread (c);
}
break;
}
}
}
示例7: startSession
import java.io.PushbackInputStream; //导入依赖的package包/类
/**
* Grants access to everyone.Removes authentication related bytes from the
* stream, when a SOCKS5 connection is being made, selects an authentication
* NONE.
*/
public ServerAuthenticator startSession(Socket s) throws IOException {
final PushbackInputStream in = new PushbackInputStream(s
.getInputStream());
final OutputStream out = s.getOutputStream();
final int version = in.read();
if (version == 5) {
if (!selectSocks5Authentication(in, out, 0)) {
return null;
}
} else if (version == 4) {
// Else it is the request message already, version 4
in.unread(version);
} else {
return null;
}
return new ServerAuthenticatorNone(in, out);
}
示例8: decodeAtom
import java.io.PushbackInputStream; //导入依赖的package包/类
/**
* Decode a UU atom. Note that if l is less than 3 we don't write
* the extra bits, however the encoder always encodes 4 character
* groups even when they are not needed.
*/
protected void decodeAtom(PushbackInputStream inStream, OutputStream outStream, int l)
throws IOException {
int i, c1, c2, c3, c4;
int a, b, c;
StringBuffer x = new StringBuffer();
for (i = 0; i < 4; i++) {
c1 = inStream.read();
if (c1 == -1) {
throw new CEStreamExhausted();
}
x.append((char)c1);
decoderBuffer[i] = (byte) ((c1 - ' ') & 0x3f);
}
a = ((decoderBuffer[0] << 2) & 0xfc) | ((decoderBuffer[1] >>> 4) & 3);
b = ((decoderBuffer[1] << 4) & 0xf0) | ((decoderBuffer[2] >>> 2) & 0xf);
c = ((decoderBuffer[2] << 6) & 0xc0) | (decoderBuffer[3] & 0x3f);
outStream.write((byte)(a & 0xff));
if (l > 1) {
outStream.write((byte)( b & 0xff));
}
if (l > 2) {
outStream.write((byte)(c&0xff));
}
}
示例9: isInputStreamGZIPCompressed
import java.io.PushbackInputStream; //导入依赖的package包/类
public static boolean isInputStreamGZIPCompressed(PushbackInputStream inputStream) throws
IOException {
boolean z = true;
if (inputStream == null) {
return false;
}
byte[] signature = new byte[2];
int readStatus = inputStream.read(signature);
inputStream.unread(signature);
int streamHeader = (signature[0] & 255) | ((signature[1] << 8) & MotionEventCompat
.ACTION_POINTER_INDEX_MASK);
if (!(readStatus == 2 && 35615 == streamHeader)) {
z = false;
}
return z;
}
示例10: getContent
import java.io.PushbackInputStream; //导入依赖的package包/类
@Override
public InputStream getContent() throws IOException {
wrappedStream = wrappedEntity.getContent();
pushbackStream = new PushbackInputStream(wrappedStream, 2);
if (isInputStreamGZIPCompressed(pushbackStream)) {
gzippedStream = new GZIPInputStream(pushbackStream);
return gzippedStream;
} else {
return pushbackStream;
}
}
示例11: ZipInputStream
import java.io.PushbackInputStream; //导入依赖的package包/类
/**
* Creates a new ZIP input stream.
*
* @param in the actual input stream
*/
public ZipInputStream(InputStream in) {
super(new PushbackInputStream(in, 512), new Inflater(true), 512);
usesDefaultInflater = true;
if (in == null) {
throw new NullPointerException("in is null");
}
}
示例12: readEnd
import java.io.PushbackInputStream; //导入依赖的package包/类
private void readEnd(ZipEntry e) throws IOException {
int n = inf.getRemaining();
if (n > 0) {
((PushbackInputStream) in).unread(buf, len - n, n);
}
if ((flag & 8) == 8) {
/* "Data Descriptor" present */
readFully(tmpbuf, 0, EXTHDR);
long sig = get32(tmpbuf, 0);
if (sig != EXTSIG) { // no EXTSIG present
e.crc = sig;
e.csize = get32(tmpbuf, EXTSIZ - EXTCRC);
e.size = get32(tmpbuf, EXTLEN - EXTCRC);
((PushbackInputStream) in).unread(tmpbuf, EXTHDR - EXTCRC - 1, EXTCRC);
} else {
e.crc = get32(tmpbuf, EXTCRC);
e.csize = get32(tmpbuf, EXTSIZ);
e.size = get32(tmpbuf, EXTLEN);
}
}
if (e.size != inf.getBytesWritten()) {
throw new ZipException("invalid entry size (expected " + e.size + " but got " + inf.getBytesWritten() + " bytes)");
}
if (e.csize != inf.getBytesRead()) {
throw new ZipException("invalid entry compressed size (expected " + e.csize + " but got " + inf.getBytesRead() + " bytes)");
}
if (e.crc != crc.getValue()) {
throw new ZipException("invalid entry CRC (expected 0x" + Long.toHexString(e.crc) + " but got 0x" + Long.toHexString(crc.getValue()) + ")");
}
}
示例13: HTTPSession
import java.io.PushbackInputStream; //导入依赖的package包/类
public HTTPSession(TempFileManager tempFileManager, InputStream inputStream, OutputStream outputStream, InetAddress inetAddress) {
this.tempFileManager = tempFileManager;
this.inputStream = new PushbackInputStream(inputStream, BUFSIZE);
this.outputStream = outputStream;
String remoteIp = inetAddress.isLoopbackAddress() || inetAddress.isAnyLocalAddress() ? "127.0.0.1" : inetAddress.getHostAddress().toString();
headers = new HashMap<String, String>();
headers.put("remote-addr", remoteIp);
headers.put("http-client-ip", remoteIp);
}
示例14: decodeBuffer
import java.io.PushbackInputStream; //导入依赖的package包/类
/**
* Decode the text from the InputStream and write the decoded
* octets to the OutputStream. This method runs until the stream
* is exhausted.
* @exception CEFormatException An error has occurred while decoding
* @exception CEStreamExhausted The input stream is unexpectedly out of data
*/
public void decodeBuffer(InputStream aStream, OutputStream bStream) throws IOException {
int i;
int totalBytes = 0;
PushbackInputStream ps = new PushbackInputStream (aStream);
decodeBufferPrefix(ps, bStream);
while (true) {
int length;
try {
length = decodeLinePrefix(ps, bStream);
for (i = 0; (i+bytesPerAtom()) < length; i += bytesPerAtom()) {
decodeAtom(ps, bStream, bytesPerAtom());
totalBytes += bytesPerAtom();
}
if ((i + bytesPerAtom()) == length) {
decodeAtom(ps, bStream, bytesPerAtom());
totalBytes += bytesPerAtom();
} else {
decodeAtom(ps, bStream, length - i);
totalBytes += (length - i);
}
decodeLineSuffix(ps, bStream);
} catch (CEStreamExhausted e) {
break;
}
}
decodeBufferSuffix(ps, bStream);
}
示例15: getInputStream
import java.io.PushbackInputStream; //导入依赖的package包/类
public PushbackInputStream getInputStream() throws IOException {
if (input == null) {
throw new IOException(
"login session isn't opened or is already closed.");
}
return input;
}