当前位置: 首页>>代码示例>>Java>>正文


Java PushbackInputStream.read方法代码示例

本文整理汇总了Java中java.io.PushbackInputStream.read方法的典型用法代码示例。如果您正苦于以下问题:Java PushbackInputStream.read方法的具体用法?Java PushbackInputStream.read怎么用?Java PushbackInputStream.read使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.io.PushbackInputStream的用法示例。


在下文中一共展示了PushbackInputStream.read方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: 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

示例4: 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

示例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:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:27,代码来源:UUDecoder.java

示例6: readLine

import java.io.PushbackInputStream; //导入方法依赖的package包/类
public static String readLine(PushbackInputStream in) throws IOException {
           char buf[] = new char[128];
           int room = buf.length;
           int offset = 0;
           int c;
loop:       while (true) {
               switch (c = in.read()) {
                   case -1:
                   case '\n':
                       break loop;
                   case '\r':
                       int c2 = in.read();
                       if ((c2 != '\n') && (c2 != -1)) in.unread(c2);
                       break loop;
                   default:
                       if (--room < 0) {
                           char[] lineBuffer = buf;
                           buf = new char[offset + 128];
                           room = buf.length - offset - 1;
                           System.arraycopy((Object)lineBuffer, 0, (Object)buf, 0, offset);  

                       }
                       buf[offset++] = (char) c;
                       break;
               }
           }
           if ((c == -1) && (offset == 0)) return null;
           return String.copyValueOf(buf, 0, offset);
   }
 
开发者ID:quanzhuo,项目名称:prada,代码行数:30,代码来源:StreamTool.java

示例7: stream2reader

import java.io.PushbackInputStream; //导入方法依赖的package包/类
/**
 * Converts a stream to a reader while detecting the encoding.
 *
 * @param stream    the input for the XML data.
 * @param charsRead buffer where to put characters that have been read
 *
 * @throws java.io.IOException
 *     if an I/O error occurred
 */
protected Reader stream2reader(InputStream  stream,
                               StringBuffer charsRead)
   throws IOException
{
   PushbackInputStream pbstream = new PushbackInputStream(stream);
   int b = pbstream.read();

   switch (b) {
      case 0x00:
      case 0xFE:
      case 0xFF:
         pbstream.unread(b);
         return new InputStreamReader(pbstream, "UTF-16");

      case 0xEF:
         for (int i = 0; i < 2; i++) {
            pbstream.read();
         }

         return new InputStreamReader(pbstream, "UTF-8");

      case 0x3C:
         b = pbstream.read();
         charsRead.append('<');

         while ((b > 0) && (b != 0x3E)) {
            charsRead.append((char) b);
            b = pbstream.read();
         }

         if (b > 0) {
            charsRead.append((char) b);
         }

         String encoding = this.getEncoding(charsRead.toString());

         if (encoding == null) {
            return new InputStreamReader(pbstream, "UTF-8");
         }

         charsRead.setLength(0);

         try {
            return new InputStreamReader(pbstream, encoding);
         } catch (UnsupportedEncodingException e) {
            return new InputStreamReader(pbstream, "UTF-8");
         }

         default:
            charsRead.append((char) b);
            return new InputStreamReader(pbstream, "UTF-8");
   }
}
 
开发者ID:the-im,项目名称:enhanced-vnc-thumbnail-viewer,代码行数:63,代码来源:StdXMLReader.java

示例8: decodeAtom

import java.io.PushbackInputStream; //导入方法依赖的package包/类
@Override
protected void decodeAtom(PushbackInputStream pushbackinputstream, OutputStream outputstream, int i)
        throws IOException {

    byte byte0 = -1;
    byte byte1 = -1;
    byte byte2 = -1;
    byte byte3 = -1;
    if (i < 2)
        throw new CEFormatException("BASE64Decoder: Not enough bytes for an atom.");
    int j;
    do {
        j = pushbackinputstream.read();
        if (j == -1)
            throw new CEStreamExhausted();
    }
    while (j == 10 || j == 13);
    decode_buffer[0] = (byte) j;
    j = readFully(pushbackinputstream, decode_buffer, 1, i - 1);
    if (j == -1)
        throw new CEStreamExhausted();
    if (i > 3 && decode_buffer[3] == 61)
        i = 3;
    if (i > 2 && decode_buffer[2] == 61)
        i = 2;
    switch (i) {
        case 4: // '\004'
            byte3 = pem_convert_array[decode_buffer[3] & 255];
            // fall through

        case 3: // '\003'
            byte2 = pem_convert_array[decode_buffer[2] & 255];
            // fall through

        case 2: // '\002'
            byte1 = pem_convert_array[decode_buffer[1] & 255];
            byte0 = pem_convert_array[decode_buffer[0] & 255];
            // fall through

        default:
            switch (i) {
                case 2: // '\002'
                    outputstream.write((byte) (byte0 << 2 & 252 | byte1 >>> 4 & 3));
                    break;

                case 3: // '\003'
                    outputstream.write((byte) (byte0 << 2 & 252 | byte1 >>> 4 & 3));
                    outputstream.write((byte) (byte1 << 4 & 240 | byte2 >>> 2 & 15));
                    break;

                case 4: // '\004'
                    outputstream.write((byte) (byte0 << 2 & 252 | byte1 >>> 4 & 3));
                    outputstream.write((byte) (byte1 << 4 & 240 | byte2 >>> 2 & 15));
                    outputstream.write((byte) (byte2 << 6 & 192 | byte3 & 63));
                    break;
            }
            break;
    }
}
 
开发者ID:uavorg,项目名称:uavstack,代码行数:60,代码来源:BASE64DecoderUrl.java

示例9: decodeAtom

import java.io.PushbackInputStream; //导入方法依赖的package包/类
/**
103        * Decode one BASE64 atom into 1, 2, or 3 bytes of data.
104        */
protected void decodeAtom(PushbackInputStream inStream, OutputStream outStream, int rem)
    throws java.io.IOException {
    int i;
    byte a = -1, b = -1, c = -1, d = -1;

    if (rem < 2) {
        throw new RuntimeException("BASE64Decoder: Not enough bytes for an atom.");
    }
    do {
        i = inStream.read();
        if (i == -1) {
            throw new RuntimeException();
        }
    } while (i == '\n' || i == '\r');
    decode_buffer[0] = (byte)i;

    i = readFully(inStream, decode_buffer, 1, rem - 1);
    if (i == -1) {
        throw new RuntimeException();
    }

    if (rem > 3 && decode_buffer[3] == '=') {
        rem = 3;
    }
    if (rem > 2 && decode_buffer[2] == '=') {
        rem = 2;
    }
    switch (rem) {
    case 4:
        d = pem_convert_array[decode_buffer[3] & 0xff];
        // NOBREAK
    case 3:
        c = pem_convert_array[decode_buffer[2] & 0xff];
        // NOBREAK
    case 2:
        b = pem_convert_array[decode_buffer[1] & 0xff];
        a = pem_convert_array[decode_buffer[0] & 0xff];
        break;
    }

    switch (rem) {
    case 2:
        outStream.write((byte)(((a << 2) & 0xfc) | ((b >>> 4) & 3)));
        break;
    case 3:
        outStream.write((byte)(((a << 2) & 0xfc) | ((b >>> 4) & 3)));
        outStream.write((byte)(((b << 4) & 0xf0) | ((c >>> 2) & 0xf)));
        break;
    case 4:
        outStream.write((byte)(((a << 2) & 0xfc) | ((b >>> 4) & 3)));
        outStream.write((byte)(((b << 4) & 0xf0) | ((c >>> 2) & 0xf)));
        outStream.write((byte)(((c << 6) & 0xc0) | (d & 0x3f)));
        break;
    }
    return;
}
 
开发者ID:guokezheng,项目名称:automat,代码行数:60,代码来源:BASE64Decoder.java

示例10: UnicodeInputStreamReader

import java.io.PushbackInputStream; //导入方法依赖的package包/类
public UnicodeInputStreamReader(InputStream source, String encoding) throws IOException
{
    defaultEnc = encoding;
    String enc = encoding;
    byte[] data = new byte[4];

    PushbackInputStream pbStream = new PushbackInputStream(source, data.length);
    int read = pbStream.read(data, 0, data.length);
    int size = 0;

    int bom16 = (data[0] & 0xFF) << 8 | (data[1] & 0xFF);
    int bom24 = bom16 << 8 | (data[2] & 0xFF);
    int bom32 = bom24 << 8 | (data[3] & 0xFF);

    if (bom24 == 0xEFBBBF)
    {
        enc = "UTF-8";
        size = 3;
    }
    else if (bom16 == 0xFEFF)
    {
        enc = "UTF-16BE";
        size = 2;
    }
    else if (bom16 == 0xFFFE)
    {
        enc = "UTF-16LE";
        size = 2;
    }
    else if (bom32 == 0x0000FEFF)
    {
        enc = "UTF-32BE";
        size = 4;
    }
    else if (bom32 == 0xFFFE0000) //This will never happen as it'll be caught by UTF-16LE,
    {                             //but if anyone ever runs across a 32LE file, i'd like to dissect it.
        enc = "UTF-32LE";
        size = 4;
    }

    if (size < read)
    {
        pbStream.unread(data, size, read - size);
    }

    this.input = new InputStreamReader(pbStream, enc);
}
 
开发者ID:F1r3w477,项目名称:CustomWorldGen,代码行数:48,代码来源:Configuration.java

示例11: decodeAtom

import java.io.PushbackInputStream; //导入方法依赖的package包/类
/**
 * Decode one atom - reads the characters from the input stream, decodes
 * them, and checks for valid parity.
 */
protected void decodeAtom(PushbackInputStream inStream, OutputStream outStream, int l) throws IOException {
    int i, p1, p2, np1, np2;
    byte a = -1, b = -1, c = -1;
    byte high_byte, low_byte;
    byte tmp[] = new byte[3];

    i = inStream.read(tmp);
    if (i != 3) {
            throw new CEStreamExhausted();
    }
    for (i = 0; (i < 64) && ((a == -1) || (b == -1) || (c == -1)); i++) {
        if (tmp[0] == map_array[i]) {
            a = (byte) i;
        }
        if (tmp[1] == map_array[i]) {
            b = (byte) i;
        }
        if (tmp[2] == map_array[i]) {
            c = (byte) i;
        }
    }
    high_byte = (byte) (((a & 0x38) << 2) + (b & 0x1f));
    low_byte = (byte) (((a & 0x7) << 5) + (c & 0x1f));
    p1 = 0;
    p2 = 0;
    for (i = 1; i < 256; i = i * 2) {
        if ((high_byte & i) != 0)
            p1++;
        if ((low_byte & i) != 0)
            p2++;
    }
    np1 = (b & 32) / 32;
    np2 = (c & 32) / 32;
    if ((p1 & 1) != np1) {
        throw new CEFormatException("UCDecoder: High byte parity error.");
    }
    if ((p2 & 1) != np2) {
        throw new CEFormatException("UCDecoder: Low byte parity error.");
    }
    outStream.write(high_byte);
    crc.update(high_byte);
    if (l == 2) {
        outStream.write(low_byte);
        crc.update(low_byte);
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:51,代码来源:UCDecoder.java

示例12: decodeAtom

import java.io.PushbackInputStream; //导入方法依赖的package包/类
private void decodeAtom(PushbackInputStream paramPushbackInputStream, OutputStream paramOutputStream, int paramInt)
    throws IOException {
    int i;
    int j = -1;
    int k = -1;
    int m = -1;
    int n = -1;

    if (paramInt < 2) {
        throw new java.lang.ArrayStoreException("BASE64Decoder: Not enough bytes for an atom.");
    }
    do {
        i = paramPushbackInputStream.read();
        if (i == -1) {
            throw new RuntimeException();
        }
    } while ((i == 10) || (i == 13));
    this.decode_buffer[0] = (byte)i;

    i = readFully(paramPushbackInputStream, this.decode_buffer, 1, paramInt - 1);
    if (i == -1) {
        throw new RuntimeException();
    }

    if ((paramInt > 3) && (this.decode_buffer[3] == 61)) {
        paramInt = 3;
    }
    if ((paramInt > 2) && (this.decode_buffer[2] == 61)) {
        paramInt = 2;
    }
    switch (paramInt) {
    case 4:
        n = pem_convert_array[(this.decode_buffer[3] & 0xFF)];
    case 3:
        m = pem_convert_array[(this.decode_buffer[2] & 0xFF)];
    case 2:
        k = pem_convert_array[(this.decode_buffer[1] & 0xFF)];
        j = pem_convert_array[(this.decode_buffer[0] & 0xFF)];
    }

    switch (paramInt) {
    case 2:
        paramOutputStream.write((byte)(j << 2 & 0xFC | k >>> 4 & 0x3));
        break;
    case 3:
        paramOutputStream.write((byte)(j << 2 & 0xFC | k >>> 4 & 0x3));
        paramOutputStream.write((byte)(k << 4 & 0xF0 | m >>> 2 & 0xF));
        break;
    case 4:
        paramOutputStream.write((byte)(j << 2 & 0xFC | k >>> 4 & 0x3));
        paramOutputStream.write((byte)(k << 4 & 0xF0 | m >>> 2 & 0xF));
        paramOutputStream.write((byte)(m << 6 & 0xC0 | n & 0x3F));
    }
}
 
开发者ID:youngMen1,项目名称:JAVA-,代码行数:55,代码来源:BASE64Encoder.java

示例13: decodeAtom

import java.io.PushbackInputStream; //导入方法依赖的package包/类
/**
 * Decode one BASE64 atom into 1, 2, or 3 bytes of data.
 */
protected void decodeAtom(PushbackInputStream inStream, OutputStream outStream, int rem)
    throws java.io.IOException
{
    int     i;
    byte    a = -1, b = -1, c = -1, d = -1;

    if (rem < 2) {
        throw new CEFormatException("BASE64Decoder: Not enough bytes for an atom.");
    }
    do {
        i = inStream.read();
        if (i == -1) {
            throw new CEStreamExhausted();
        }
    } while (i == '\n' || i == '\r');
    decode_buffer[0] = (byte) i;

    i = readFully(inStream, decode_buffer, 1, rem-1);
    if (i == -1) {
        throw new CEStreamExhausted();
    }

    if (rem > 3 && decode_buffer[3] == '=') {
        rem = 3;
    }
    if (rem > 2 && decode_buffer[2] == '=') {
        rem = 2;
    }
    switch (rem) {
    case 4:
        d = pem_convert_array[decode_buffer[3] & 0xff];
        // NOBREAK
    case 3:
        c = pem_convert_array[decode_buffer[2] & 0xff];
        // NOBREAK
    case 2:
        b = pem_convert_array[decode_buffer[1] & 0xff];
        a = pem_convert_array[decode_buffer[0] & 0xff];
        break;
    }

    switch (rem) {
    case 2:
        outStream.write( (byte)(((a << 2) & 0xfc) | ((b >>> 4) & 3)) );
        break;
    case 3:
        outStream.write( (byte) (((a << 2) & 0xfc) | ((b >>> 4) & 3)) );
        outStream.write( (byte) (((b << 4) & 0xf0) | ((c >>> 2) & 0xf)) );
        break;
    case 4:
        outStream.write( (byte) (((a << 2) & 0xfc) | ((b >>> 4) & 3)) );
        outStream.write( (byte) (((b << 4) & 0xf0) | ((c >>> 2) & 0xf)) );
        outStream.write( (byte) (((c << 6) & 0xc0) | (d  & 0x3f)) );
        break;
    }
    return;
}
 
开发者ID:tranleduy2000,项目名称:javaide,代码行数:61,代码来源:BASE64Decoder.java

示例14: decodeBufferPrefix

import java.io.PushbackInputStream; //导入方法依赖的package包/类
/**
 * For uuencoded buffers, the data begins with a line of the form:
 *          begin MODE FILENAME
 * This line always starts in column 1.
 */
protected void decodeBufferPrefix(PushbackInputStream inStream, OutputStream outStream) throws IOException {
    int     c;
    StringBuffer q = new StringBuffer(32);
    String r;
    boolean sawNewLine;

    /*
     * This works by ripping through the buffer until it finds a 'begin'
     * line or the end of the buffer.
     */
    sawNewLine = true;
    while (true) {
        c = inStream.read();
        if (c == -1) {
            throw new CEFormatException("UUDecoder: No begin line.");
        }
        if ((c == 'b')  && sawNewLine){
            c = inStream.read();
            if (c == 'e') {
                break;
            }
        }
        sawNewLine = (c == '\n') || (c == '\r');
    }

    /*
     * Now we think its begin, (we've seen ^be) so verify it here.
     */
    while ((c != '\n') && (c != '\r')) {
        c = inStream.read();
        if (c == -1) {
            throw new CEFormatException("UUDecoder: No begin line.");
        }
        if ((c != '\n') && (c != '\r')) {
            q.append((char)c);
        }
    }
    r = q.toString();
    if (r.indexOf(' ') != 3) {
            throw new CEFormatException("UUDecoder: Malformed begin line.");
    }
    mode = Integer.parseInt(r.substring(4,7));
    bufferName = r.substring(r.indexOf(' ',6)+1);
    /*
     * Check for \n after \r
     */
    if (c == '\r') {
        c = inStream.read ();
        if ((c != '\n') && (c != -1))
            inStream.unread (c);
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:58,代码来源:UUDecoder.java


注:本文中的java.io.PushbackInputStream.read方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。