當前位置: 首頁>>代碼示例>>Java>>正文


Java PushbackInputStream類代碼示例

本文整理匯總了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;
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:26,代碼來源:AsyncHttpClient.java

示例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;
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:24,代碼來源:DefaultAttributes.java

示例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;
  }
}
 
開發者ID:ajmath,項目名稱:VASSAL-src,代碼行數:20,代碼來源:DeobfuscatingInputStream.java

示例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;
    }
}
 
開發者ID:christian-schlichtherle,項目名稱:truevfs,代碼行數:29,代碼來源:TarInputService.java

示例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);
}
 
開發者ID:tranleduy2000,項目名稱:javaide,代碼行數:27,代碼來源:UUDecoder.java

示例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;
        }
    }
}
 
開發者ID:tranleduy2000,項目名稱:javaide,代碼行數:25,代碼來源:UUDecoder.java

示例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);
}
 
開發者ID:PanagiotisDrakatos,項目名稱:T0rlib4Android,代碼行數:26,代碼來源:ServerAuthenticatorBase.java

示例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));
    }
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:31,代碼來源:UUDecoder.java

示例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;
}
 
開發者ID:JackChan1999,項目名稱:boohee_v5.6,代碼行數:17,代碼來源:AsyncHttpClient.java

示例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;
    }
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:12,代碼來源:AsyncHttpClient.java

示例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");
	}
}
 
開發者ID:funtl,項目名稱:framework,代碼行數:13,代碼來源:ZipInputStream.java

示例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()) + ")");
	}
}
 
開發者ID:funtl,項目名稱:framework,代碼行數:31,代碼來源:ZipInputStream.java

示例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);
}
 
開發者ID:uhuru-mobile,項目名稱:mobile-store,代碼行數:11,代碼來源:NanoHTTPD.java

示例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);
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:37,代碼來源:CharacterDecoder.java

示例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;
}
 
開發者ID:openNaEF,項目名稱:openNaEF,代碼行數:8,代碼來源:RealSsh2Socket.java


注:本文中的java.io.PushbackInputStream類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。