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


Java DataInputStream.skipBytes方法代碼示例

本文整理匯總了Java中java.io.DataInputStream.skipBytes方法的典型用法代碼示例。如果您正苦於以下問題:Java DataInputStream.skipBytes方法的具體用法?Java DataInputStream.skipBytes怎麽用?Java DataInputStream.skipBytes使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.io.DataInputStream的用法示例。


在下文中一共展示了DataInputStream.skipBytes方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: deserializeFirstLastKey

import java.io.DataInputStream; //導入方法依賴的package包/類
/**
 * Deserializes the first and last key stored in the summary
 *
 * Only for use by offline tools like SSTableMetadataViewer, otherwise SSTable.first/last should be used.
 */
public Pair<DecoratedKey, DecoratedKey> deserializeFirstLastKey(DataInputStream in, IPartitioner partitioner, boolean haveSamplingLevel) throws IOException
{
    in.skipBytes(4); // minIndexInterval
    int offsetCount = in.readInt();
    long offheapSize = in.readLong();
    if (haveSamplingLevel)
        in.skipBytes(8); // samplingLevel, fullSamplingSummarySize

    in.skip(offsetCount * 4);
    in.skip(offheapSize - offsetCount * 4);

    DecoratedKey first = partitioner.decorateKey(ByteBufferUtil.readWithLength(in));
    DecoratedKey last = partitioner.decorateKey(ByteBufferUtil.readWithLength(in));
    return Pair.create(first, last);
}
 
開發者ID:Netflix,項目名稱:sstable-adaptor,代碼行數:21,代碼來源:IndexSummary.java

示例2: load

import java.io.DataInputStream; //導入方法依賴的package包/類
/**
 * Load a list of attributes
 */
public static BinaryAttribute load(DataInputStream in, BinaryConstantPool cpool, int mask) throws IOException {
    BinaryAttribute atts = null;
    int natt = in.readUnsignedShort();  // JVM 4.6 method_info.attrutes_count

    for (int i = 0 ; i < natt ; i++) {
        // id from JVM 4.7 attribute_info.attribute_name_index
        Identifier id = cpool.getIdentifier(in.readUnsignedShort());
        // id from JVM 4.7 attribute_info.attribute_length
        int len = in.readInt();

        if (id.equals(idCode) && ((mask & ATT_CODE) == 0)) {
            in.skipBytes(len);
        } else {
            byte data[] = new byte[len];
            in.readFully(data);
            atts = new BinaryAttribute(id, data, atts);
        }
    }
    return atts;
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:24,代碼來源:BinaryAttribute.java

示例3: readAnnotation

import java.io.DataInputStream; //導入方法依賴的package包/類
/**
 * Read annotation entry from classfile.
 */
private String readAnnotation(final DataInputStream inp, final Object[] constantPool) throws Exception {

    final String annotationFieldDescriptor = readRefdString(inp, constantPool);
    String annotationClassName;
    if (annotationFieldDescriptor.charAt(0) == 'L'
            && annotationFieldDescriptor.charAt(annotationFieldDescriptor.length() - 1) == ';') {
        // Lcom/xyz/Annotation; -> com.xyz.Annotation
        annotationClassName = annotationFieldDescriptor.substring(1, annotationFieldDescriptor.length() - 1)
                .replace('/', '.');
    }
    else {
        // Should not happen
        annotationClassName = annotationFieldDescriptor;
    }
    final int numElementValuePairs = inp.readUnsignedShort();
    for (int i = 0; i < numElementValuePairs; i++) {
        inp.skipBytes(2); // element_name_index
        readAnnotationElementValue(inp, constantPool);
    }
    return annotationClassName;
}
 
開發者ID:uavorg,項目名稱:uavstack,代碼行數:25,代碼來源:ClassGraphBuilder.java

示例4: getInputStream

import java.io.DataInputStream; //導入方法依賴的package包/類
public InputStream getInputStream(TinkerZipEntry entry) throws IOException {
    entry = getEntry(entry.getName());
    if (entry == null) {
        return null;
    }
    InputStream rafStream;
    RandomAccessFile localRaf = this.raf;
    synchronized (localRaf) {
        rafStream = new RAFStream(localRaf, entry.localHeaderRelOffset);
        DataInputStream is = new DataInputStream(rafStream);
        int localMagic = Integer.reverseBytes(is.readInt());
        if (((long) localMagic) != ZipConstants.LOCSIG) {
            throwZipException(this.filename, localRaf.length(), entry.getName(), entry
                    .localHeaderRelOffset, "Local File Header", localMagic);
        }
        is.skipBytes(2);
        int gpbf = Short.reverseBytes(is.readShort()) & 65535;
        if ((gpbf & 1) != 0) {
            throw new ZipException("Invalid General Purpose Bit Flag: " + gpbf);
        }
        is.skipBytes(18);
        int fileNameLength = Short.reverseBytes(is.readShort()) & 65535;
        int extraFieldLength = Short.reverseBytes(is.readShort()) & 65535;
        is.close();
        rafStream.skip((long) (fileNameLength + extraFieldLength));
        if (entry.compressionMethod == 0) {
            rafStream.endOffset = rafStream.offset + entry.size;
        } else {
            rafStream.endOffset = rafStream.offset + entry.compressedSize;
        }
    }
    return rafStream;
}
 
開發者ID:JackChan1999,項目名稱:boohee_v5.6,代碼行數:34,代碼來源:TinkerZipFile.java

示例5: processBlocks

import java.io.DataInputStream; //導入方法依賴的package包/類
/**
 * Process the blocks section of the fsimage.
 *
 * @param in Datastream to process
 * @param v Visitor to walk over inodes
 * @param skipBlocks Walk over each block?
 */
private void processBlocks(DataInputStream in, ImageVisitor v,
    int numBlocks, boolean skipBlocks) throws IOException {
  v.visitEnclosingElement(ImageElement.BLOCKS,
                          ImageElement.NUM_BLOCKS, numBlocks);
  
  // directory or symlink or reference node, no blocks to process    
  if(numBlocks < 0) { 
    v.leaveEnclosingElement(); // Blocks
    return;
  }
  
  if(skipBlocks) {
    int bytesToSkip = ((Long.SIZE * 3 /* fields */) / 8 /*bits*/) * numBlocks;
    if(in.skipBytes(bytesToSkip) != bytesToSkip)
      throw new IOException("Error skipping over blocks");
    
  } else {
    for(int j = 0; j < numBlocks; j++) {
      v.visitEnclosingElement(ImageElement.BLOCK);
      v.visit(ImageElement.BLOCK_ID, in.readLong());
      v.visit(ImageElement.NUM_BYTES, in.readLong());
      v.visit(ImageElement.GENERATION_STAMP, in.readLong());
      v.leaveEnclosingElement(); // Block
    }
  }
  v.leaveEnclosingElement(); // Blocks
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:35,代碼來源:ImageLoaderCurrent.java

示例6: getInputStream

import java.io.DataInputStream; //導入方法依賴的package包/類
/**
 * Returns an input stream on the data of the specified {@code ZipEntry}.
 *
 * @param entry
 *            the ZipEntry.
 * @return an input stream of the data contained in the {@code ZipEntry}.
 * @throws IOException
 *             if an {@code IOException} occurs.
 * @throws IllegalStateException if this zip file has been closed.
 */
public InputStream getInputStream(TinkerZipEntry entry) throws IOException {
    // Make sure this ZipEntry is in this Zip file.  We run it through the name lookup.
    entry = getEntry(entry.getName());
    if (entry == null) {
        return null;
    }
    // Create an InputStream at the right part of the file.
    RandomAccessFile localRaf = raf;
    synchronized (localRaf) {
        // We don't know the entry data's start position. All we have is the
        // position of the entry's local header.
        // http://www.pkware.com/documents/casestudies/APPNOTE.TXT
        RAFStream rafStream = new RAFStream(localRaf, entry.localHeaderRelOffset);
        DataInputStream is = new DataInputStream(rafStream);
        final int localMagic = Integer.reverseBytes(is.readInt());
        if (localMagic != LOCSIG) {
            throwZipException(filename, localRaf.length(), entry.getName(), entry.localHeaderRelOffset, "Local File Header", localMagic);
        }
        is.skipBytes(2);
        // At position 6 we find the General Purpose Bit Flag.
        int gpbf = Short.reverseBytes(is.readShort()) & 0xffff;
        if ((gpbf & TinkerZipFile.GPBF_UNSUPPORTED_MASK) != 0) {
            throw new ZipException("Invalid General Purpose Bit Flag: " + gpbf);
        }
        // Offset 26 has the file name length, and offset 28 has the extra field length.
        // These lengths can differ from the ones in the central header.
        is.skipBytes(18);
        int fileNameLength = Short.reverseBytes(is.readShort()) & 0xffff;
        int extraFieldLength = Short.reverseBytes(is.readShort()) & 0xffff;
        is.close();
        // Skip the variable-size file name and extra field data.
        rafStream.skip(fileNameLength + extraFieldLength);
        /*if (entry.compressionMethod == ZipEntry.STORED) {
            rafStream.endOffset = rafStream.offset + entry.size;
            return rafStream;
        } else {
            rafStream.endOffset = rafStream.offset + entry.compressedSize;
            int bufSize = Math.max(1024, (int) Math.min(entry.getSize(), 65535L));
            return new ZipInflaterInputStream(rafStream, new Inflater(true), bufSize, entry);
        }*/
        if (entry.compressionMethod == TinkerZipEntry.STORED) {
            rafStream.endOffset = rafStream.offset + entry.size;
        } else {
            rafStream.endOffset = rafStream.offset + entry.compressedSize;
        }
        return rafStream;
    }
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:59,代碼來源:TinkerZipFile.java

示例7: readAnnotationElementValue

import java.io.DataInputStream; //導入方法依賴的package包/類
/**
 * Read annotation element value from classfile.
 */
// --------------------------------CreditEase Modified START----------------------------
private void readAnnotationElementValue(final DataInputStream inp, final Object[] constantPool) throws Exception {

    // --------------------------------CreditEase Modified END----------------------------
    final int tag = inp.readUnsignedByte();
    switch (tag) {
        case 'B':
        case 'C':
        case 'D':
        case 'F':
        case 'I':
        case 'J':
        case 'S':
        case 'Z':
        case 's':
            // const_value_index
            inp.skipBytes(2);
            break;
        case 'e':
            // enum_const_value
            inp.skipBytes(4);
            break;
        case 'c':
            // class_info_index
            inp.skipBytes(2);
            break;
        case '@':
            // Complex (nested) annotation
            readAnnotation(inp, constantPool);
            break;
        case '[':
            // array_value
            final int count = inp.readUnsignedShort();
            for (int l = 0; l < count; ++l) {
                // Nested annotation element value
                readAnnotationElementValue(inp, constantPool);
            }
            break;
        default:
            // System.err.println("Invalid annotation element type tag: 0x" + Integer.toHexString(tag));
            break;
    }
}
 
開發者ID:uavorg,項目名稱:uavstack,代碼行數:47,代碼來源:ClassGraphBuilder.java

示例8: readHeader

import java.io.DataInputStream; //導入方法依賴的package包/類
public static final byte[] readHeader(InputStream inputStream,
                                    byte dataFormatIDExpected[],
                                    Authenticate authenticate)
                                                      throws IOException
{
    DataInputStream input = new DataInputStream(inputStream);
    char headersize = input.readChar();
    int readcount = 2;
    //reading the header format
    byte magic1 = input.readByte();
    readcount ++;
    byte magic2 = input.readByte();
    readcount ++;
    if (magic1 != MAGIC1 || magic2 != MAGIC2) {
        throw new IOException(MAGIC_NUMBER_AUTHENTICATION_FAILED_);
    }

    input.readChar(); // reading size
    readcount += 2;
    input.readChar(); // reading reserved word
    readcount += 2;
    byte bigendian    = input.readByte();
    readcount ++;
    byte charset      = input.readByte();
    readcount ++;
    byte charsize     = input.readByte();
    readcount ++;
    input.readByte(); // reading reserved byte
    readcount ++;

    byte dataFormatID[] = new byte[4];
    input.readFully(dataFormatID);
    readcount += 4;
    byte dataVersion[] = new byte[4];
    input.readFully(dataVersion);
    readcount += 4;
    byte unicodeVersion[] = new byte[4];
    input.readFully(unicodeVersion);
    readcount += 4;
    if (headersize < readcount) {
        throw new IOException("Internal Error: Header size error");
    }
    input.skipBytes(headersize - readcount);

    if (bigendian != BIG_ENDIAN_ || charset != CHAR_SET_
        || charsize != CHAR_SIZE_
        || !Arrays.equals(dataFormatIDExpected, dataFormatID)
        || (authenticate != null
            && !authenticate.isDataVersionAcceptable(dataVersion))) {
        throw new IOException(HEADER_AUTHENTICATION_FAILED_);
    }
    return unicodeVersion;
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:54,代碼來源:ICUBinary.java

示例9: printAllContents

import java.io.DataInputStream; //導入方法依賴的package包/類
public void printAllContents() throws IOException{
       DataInputStream data_in = new DataInputStream(new FileInputStream(f));
       // record block info section
       data_in.skipBytes( (int) (_record_block_offset+_number_width*4+_num_record_blocks*2*_number_width));
       
       // actual record block data
       //int i = (int) (position-infoI.num_entries_accumulator);//處於當前record塊的第幾個
       //record_info_struct RinfoI = _record_info_struct_list[accumulation_RecordB_tree.xxing(new mdict.myCpr(infoI.key_offsets[i],1)).getKey().value];
       
       
       //whole section of record_blocks;
       for(int i=0; i<_record_info_struct_list.length; i++){
       	record_info_struct RinfoI = _record_info_struct_list[i];
       	//data_in.skipBytes((int) RinfoI.compressed_size_accumulator);
       	long compressed_size = RinfoI.compressed_size;
       	long decompressed_size = RinfoI.decompressed_size;//用於驗證
       	byte[] record_block_compressed = new byte[(int) compressed_size];
       	data_in.read(record_block_compressed);//+8 TODO optimize
           // 4 bytes indicates block compression type
       	byte[] record_block_type = new byte[4];
       	System.arraycopy(record_block_compressed, 0, record_block_type, 0, 4);
       	String record_block_type_str = new String(record_block_type);
       	// 4 bytes adler checksum of uncompressed content
       	ByteBuffer sf1 = ByteBuffer.wrap(record_block_compressed);
           int adler32 = sf1.order(ByteOrder.BIG_ENDIAN).getInt(4);
           byte[] record_block = new byte[1];
           // no compression
           if(record_block_type_str.equals(new String(new byte[]{0,0,0,0}))){
           	record_block = new byte[(int) (compressed_size-8)];
           	System.arraycopy(record_block_compressed, 8, record_block, 0, record_block.length-8);
           }
           // lzo compression
           else if(record_block_type_str.equals(new String(new byte[]{1,0,0,0}))){
               long st=System.currentTimeMillis(); //獲取開始時間 
               record_block = new byte[(int) decompressed_size];
               MInt len = new MInt((int) decompressed_size);
               byte[] arraytmp = new byte[(int) compressed_size];
               System.arraycopy(record_block_compressed, 8, arraytmp, 0,(int) (compressed_size-8));
               MiniLZO.lzo1x_decompress(arraytmp,(int) compressed_size,record_block,len);
           	//System.out.println("get Record LZO decompressing key blocks done!") ;
               //System.out.println("解壓Record耗時:"+(System.currentTimeMillis()-st));
           }
           // zlib compression
           else if(record_block_type_str.equals(new String(new byte[]{02,00,00,00}))){
               record_block = zlib_decompress(record_block_compressed,8);
           }
           // notice not that adler32 return signed value
           assert(adler32 == (calcChecksum(record_block) ));
           assert(record_block.length == decompressed_size );
//當前內容塊解壓完畢
           

           String record_str = new String(record_block,_encoding); 	
           // substitute styles
           //if self._substyle and self._stylesheet:
           //    record = self._substitute_stylesheet(record);
           show(record_str);       
       	
       	
       }
   }
 
開發者ID:KnIfER,項目名稱:mdict-parser-java,代碼行數:62,代碼來源:mdict.java


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