Loads the optional header. Presumes a valid PE file.

@param pesig
pe signature
@param coff
coff file header
@param raf
the random access file instance
@return optional header
@throws IOException
if unable to read header
433641
private OptionalHeader loadOptionalHeader(PESignature pesig,
            COFFFileHeader coff, RandomAccessFile raf) throws IOException {
        // offset right after the eCOFF File Header
        long offset = pesig.getOffset() + PESignature.PE_SIG.length
                + COFFFileHeader.HEADER_SIZE;
        logger.info("Optional Header offset: " + offset);
        // set the maximum size for the bytes to read
        int size = getOptHeaderSize(offset);
        // read bytes and construct header
        byte[] headerbytes = loadBytesSafely(offset, size, raf);
        return OptionalHeader.newInstance(headerbytes, offset);
    }
865431
public static PCMContainer loadPCMContainer(String filename) throws IOException {

        // Define a file representing a PCM to load
        File pcmFile = new File(filename);

        // Create a loader that can handle the file format
        PCMLoader loader = new KMFJSONLoader();

        // Load the file
        // A loader may return multiple PCM containers depending on the input format
        // A PCM container encapsulates a PCM and its associated metadata
        List<PCMContainer> pcmContainers = loader.load(pcmFile);

        PCMContainer pcmContainer = pcmContainers.get(0);
        return pcmContainer;
    }
551472
def is_authenticode_signed(filename):
    """"""
    with open(filename, 'rb') as fp:
        fp.seek(0)
        magic = fp.read(2)
        if magic != b'MZ':
            return False

        # First grab the pointer to the coff_header, which is at offset 60
        fp.seek(60)
        coff_header_offset = struct.unpack('<L', fp.read(4))[0]

        # Check the COFF magic
        fp.seek(coff_header_offset)
        magic = fp.read(4)
        if magic != b'PE\x00\x00':
            return False

        # Get the PE type
        fp.seek(coff_header_offset + 0x18)
        pe_type = struct.unpack('<h', fp.read(2))[0]

        if pe_type == 0x10b:
            # PE32 file (32-bit apps)
            number_of_data_dirs_offset = coff_header_offset + 0x74
        elif pe_type == 0x20b:
            # PE32+ files (64-bit apps)
            # PE32+ files have slightly larger fields in the header
            number_of_data_dirs_offset = coff_header_offset + 0x74 + 16
        else:
            return False

        fp.seek(number_of_data_dirs_offset)
        num_data_dirs = struct.unpack('<L', fp.read(4))[0]

        if num_data_dirs < 5:
            # Probably shouldn't happen, but just in case
            return False

        cert_table_offset = number_of_data_dirs_offset + 4*8 + 4
        fp.seek(cert_table_offset)
        addr, size = struct.unpack('<LL', fp.read(8))
        if not addr or not size:
            return False
        # Check that addr is inside the file
        fp.seek(addr)
        if fp.tell() != addr:
            return False
        cert = fp.read(size)
        if len(cert) != size:
            return False
        return True
958676
void readHeader() throws IOException {
    int version = in.readInt();
    if (version != BlockCrcInfoWritable.LATEST_BLOCK_CRC_FILE_VERSION) {
      throw new IOException("Version " + version + " is not supported.");
    }
    numBuckets = in.readInt();
    currentBucket = -1;
    numRecordsReadInBucket = 0;
    numRecordsInBucket = 0;    
  }
324233
private static Optional<Token<?>> getTokenFromSeqFile(String authPath, String proxyUserName) throws IOException {
    try (Closer closer = Closer.create()) {
      FileSystem localFs = FileSystem.getLocal(new Configuration());
      SequenceFile.Reader tokenReader =
          closer.register(new SequenceFile.Reader(localFs, new Path(authPath), localFs.getConf()));
      Text key = new Text();
      Token<?> value = new Token<>();
      while (tokenReader.next(key, value)) {
        LOG.info("Found token for " + key);
        if (key.toString().equals(proxyUserName)) {
          return Optional.<Token<?>> of(value);
        }
      }
    }
    return Optional.absent();
  }
277143
public boolean readBufferFromFileChannel(Buffer buffer) throws IOException {
		checkArgument(fileChannel.size() - fileChannel.position() > 0);

		// Read header
		header.clear();
		fileChannel.read(header);
		header.flip();

		final boolean isBuffer = header.getInt() == 1;
		final int size = header.getInt();

		if (size > buffer.getMaxCapacity()) {
			throw new IllegalStateException("Buffer is too small for data: " + buffer.getMaxCapacity() + " bytes available, but " + size + " needed. This is most likely due to an serialized event, which is larger than the buffer size.");
		}
		checkArgument(buffer.getSize() == 0, "Buffer not empty");

		fileChannel.read(buffer.getNioBuffer(0, size));
		buffer.setSize(size);

		if (!isBuffer) {
			buffer.tagAsEvent();
		}

		return fileChannel.size() - fileChannel.position() == 0;
	}
1339098
public static COFFFileHeader newInstance(byte[] headerbytes, long offset) {
        COFFFileHeader header = new COFFFileHeader(headerbytes, offset);
        header.read();
        return header;
    }
433947
private void loadBytesAsNeeded() throws IOException {
        if (available() <= 0) {
            _isEof = true;
        }

        while ((!_isEof) && (bytesLeftInBuffer() <= 0)) {
            _currentBufferPosition = 0;
            NfsReadResponse response = _file.read(_offset, _bytes.length, _bytes, _currentBufferPosition);
            _bytesInBuffer = response.getBytesRead();
            _offset += _bytesInBuffer;
            _isEof = response.isEof();
        }
    }
812563
private void consumeCRLF(ImapRequestLineReader request)
            throws ProtocolException {
        char next = request.nextChar();
        if (next != '\n') {
            consumeChar(request, '\r');
        }
        consumeChar(request, '\n');
    }
271416
private void readHeader(RandomAccessInputStream raf) throws IOException
	{
		raf.seek(HEAD_LOCATION);

		byte[] head = new byte[HEAD_SIZE];
		if (raf.read(head) != HEAD_SIZE)
		{
			throw new IOException("Error encountered reading id3v2 header");
		}

		majorVersion = (int) head[3];

		if (majorVersion <= NEW_MAJOR_VERSION)
		{
			minorVersion = (int) head[4];
			unsynchronisation = (head[5]&0x80)!=0;
			extended = (head[5]&0x40)!=0;
			experimental = (head[5]&0x20)!=0;
			footer = (head[5]&0x10)!=0;
			tagSize = Helpers.convertDWordToInt(head, 6);
		}
	}
1349450
@Override
    public void readHeader(RandomAccessFile file) throws IOException {
        super.readHeader(file);
        this.k_max = file.readInt();
    }
1322090
private void readHeader() throws IOException {
    headerBuffer.rewind();

    final int flgRead = in.read();
    if (flgRead < 0) {
      throw new IOException(PREMATURE_EOS);
    }
    final int bdRead = in.read();
    if (bdRead < 0) {
      throw new IOException(PREMATURE_EOS);
    }

    final byte flgByte = (byte)(flgRead & 0xFF);
    final LZ4FrameOutputStream.FLG flg = LZ4FrameOutputStream.FLG.fromByte(flgByte);
    headerBuffer.put(flgByte);
    final byte bdByte = (byte)(bdRead & 0xFF);
    final LZ4FrameOutputStream.BD bd = LZ4FrameOutputStream.BD.fromByte(bdByte);
    headerBuffer.put(bdByte);

    this.frameInfo = new LZ4FrameOutputStream.FrameInfo(flg, bd);

    if (flg.isEnabled(LZ4FrameOutputStream.FLG.Bits.CONTENT_SIZE)) {
      expectedContentSize = readLong(in);
      headerBuffer.putLong(expectedContentSize);
    }
    totalContentSize = 0L;

    // check stream descriptor hash
    final byte hash = (byte) ((checksum.hash(headerArray, 0, headerBuffer.position(), 0) >> 8) & 0xFF);
    final int expectedHash = in.read();
    if (expectedHash < 0) {
      throw new IOException(PREMATURE_EOS);
    }

    if (hash != (byte)(expectedHash & 0xFF)) {
      throw new IOException(DESCRIPTOR_HASH_MISMATCH);
    }

    maxBlockSize = frameInfo.getBD().getBlockMaximumSize();
    compressedBuffer = new byte[maxBlockSize]; // Reused during different compressions
    rawBuffer = new byte[maxBlockSize];
    buffer = ByteBuffer.wrap(rawBuffer);
    buffer.limit(0);
  }
1124117
private void readCrlf() throws IOException {
        final int crsymbol = this.origin.read();
        final int lfsymbol = this.origin.read();
        if (crsymbol != '\r' || lfsymbol != '\n') {
            throw new IOException(
                String.format(
                    "%s %d%s%d",
                    "CRLF expected at end of chunk: ",
                    crsymbol,
                    "/",
                    lfsymbol
                )
            );
        }
    }
1003301
public void read() throws IOException {
		try (RandomAccessFile raf = new RandomAccessFile(file, "r")) {
			// check that offset location is within the file
			throwIf(file.length() < PE_OFFSET_LOCATION);
			/* read pe signature offset at offset location */
			byte[] offsetBytes = loadBytesSafely(PE_OFFSET_LOCATION,
					PE_OFFSET_LOCATION_SIZE, raf);
			// save signature offset
			peOffset = Optional.of((long) bytesToInt(offsetBytes));
			// check if supposed pe signature is within the file
			// a truncated signature has to be taken into account and allowed
			// see d_nonnull.dll
			throwIf(file.length() < peOffset.get() || peOffset.get() < 0);
			/* read PE signature at offset and verify */
			byte[] peSigVal = loadBytesSafely(peOffset.get(), PE_SIG.length,
					raf);
			for (int i = 0; i < PE_SIG.length; i++) {
				throwIf(peSigVal[i] != PE_SIG[i]);
			}
		}
	}
635883
private void readHeaders(Map<String, Object> aff_properties, Map<String, Object> af_properties) throws IOException {
        LOG.log(Level.FINE, "readHeaders(");
        int bufferSize_ = bufferMultiple_ * 256 * 2;
        index = oggSyncState_.buffer(bufferSize_);
        buffer = oggSyncState_.data;
        bytes = readFromStream(buffer, index, bufferSize_);
        if (bytes == -1) {
            LOG.log(Level.FINE, "Cannot get any data from selected Ogg bitstream.");
            throw new IOException("Cannot get any data from selected Ogg bitstream.");
        }
        oggSyncState_.wrote(bytes);
        if (oggSyncState_.pageout(oggPage_) != 1) {
            if (bytes < bufferSize_) {
                throw new IOException("EOF");
            }
            LOG.log(Level.FINE, "Input does not appear to be an Ogg bitstream.");
            throw new IOException("Input does not appear to be an Ogg bitstream.");
        }
        oggStreamState_.init(oggPage_.serialno());
        vorbisInfo.init();
        vorbisComment.init();
        aff_properties.put("ogg.serial", oggPage_.serialno());
        if (oggStreamState_.pagein(oggPage_) < 0) {
            // error; stream version mismatch perhaps
            LOG.log(Level.FINE, "Error reading first page of Ogg bitstream data.");
            throw new IOException("Error reading first page of Ogg bitstream data.");
        }
        if (oggStreamState_.packetout(oggPacket_) != 1) {
            // no page? must not be vorbis
            LOG.log(Level.FINE, "Error reading initial header packet.");
            throw new IOException("Error reading initial header packet.");
        }
        if (vorbisInfo.synthesis_headerin(vorbisComment, oggPacket_) < 0) {
            // error case; not a vorbis header
            LOG.log(Level.FINE, "This Ogg bitstream does not contain Vorbis audio data.");
            throw new IOException("This Ogg bitstream does not contain Vorbis audio data.");
        }
        int i = 0;
        while (i < 2) {
            while (i < 2) {
                int result = oggSyncState_.pageout(oggPage_);
                if (result == 0) {
                    break;
                } // Need more data
                if (result == 1) {
                    oggStreamState_.pagein(oggPage_);
                    while (i < 2) {
                        result = oggStreamState_.packetout(oggPacket_);
                        if (result == 0) {
                            break;
                        }
                        if (result == -1) {
                            LOG.log(Level.FINE, "Corrupt secondary header.  Exiting.");
                            throw new IOException("Corrupt secondary header.  Exiting.");
                        }
                        vorbisInfo.synthesis_headerin(vorbisComment, oggPacket_);
                        i++;
                    }
                }
            }
            index = oggSyncState_.buffer(bufferSize_);
            buffer = oggSyncState_.data;
            bytes = readFromStream(buffer, index, bufferSize_);
            if (bytes == -1) {
                break;
            }
            if (bytes == 0 && i < 2) {
                LOG.log(Level.FINE, "End of file before finding all Vorbis headers!");
                throw new IOException("End of file before finding all Vorbis  headers!");
            }
            oggSyncState_.wrote(bytes);
        }
        // Read Ogg Vorbis comments.
        byte[][] ptr = vorbisComment.user_comments;
        int c = 0;
        for (byte[] ptr1 : ptr) {
            if (ptr1 == null) {
                break;
            }
            String currComment = new String(ptr1, 0, ptr1.length - 1, "UTF-8").trim();
            LOG.log(Level.FINE, currComment);
            if (currComment.toLowerCase(Locale.ENGLISH).startsWith("artist")) {
                aff_properties.put("author", currComment.substring(7));
            } else if (currComment.toLowerCase(Locale.ENGLISH).startsWith("title")) {
                aff_properties.put("title", currComment.substring(6));
            } else if (currComment.toLowerCase(Locale.ENGLISH).startsWith("album")) {
                aff_properties.put("album", currComment.substring(6));
            } else if (currComment.toLowerCase(Locale.ENGLISH).startsWith("date")) {
                aff_properties.put("date", currComment.substring(5));
            } else if (currComment.toLowerCase(Locale.ENGLISH).startsWith("copyright")) {
                aff_properties.put("copyright", currComment.substring(10));
            } else if (currComment.toLowerCase(Locale.ENGLISH).startsWith("comment")) {
                aff_properties.put("comment", currComment.substring(8));
            } else if (currComment.toLowerCase(Locale.ENGLISH).startsWith("genre")) {
                aff_properties.put("ogg.comment.genre", currComment.substring(6));
            } else if (currComment.toLowerCase(Locale.ENGLISH).startsWith("tracknumber")) {
                aff_properties.put("ogg.comment.track", currComment.substring(12));
            } else {
                c++;
                aff_properties.put("ogg.comment.ext." + c, currComment);
            }
            aff_properties.put("ogg.comment.encodedby", new String(vorbisComment.vendor, 0, vorbisComment.vendor.length - 1, Charset.forName("US-ASCII")));
        }
    }
1325623
@Override
  public final IEntityFileReporter lazyGet(
    final Map<String, Object> pAddParam,
      final String pBeanName) throws Exception {
    IEntityFileReporter proc =
      this.reportersMap.get(pBeanName);
    if (proc == null) {
      // locking:
      synchronized (this) {
        // make sure again whether it's null after locking:
        proc = this.reportersMap.get(pBeanName);
        if (proc == null
          && pBeanName.equals(InvoiceReportPdf.class.getSimpleName())) {
          proc = lazyGetInvoiceReportPdf(pAddParam);
        }
      }
    }
    if (proc == null) {
      throw new ExceptionWithCode(ExceptionWithCode.CONFIGURATION_MISTAKE,
        "There is no entity processor with name " + pBeanName);
    }
    return proc;
  }
1314981
public void removeTag(RandomAccessFile raf) throws FileNotFoundException, IOException
	{
		if (exists)
		{
			int bufSize = (int)(raf.length() - origSize);
			byte[] buf = new byte[bufSize];

			raf.seek(origSize);

			if (raf.read(buf) != buf.length)
			{
				throw new IOException("Error encountered while removing " + "id3v2 tag.");
			}

			raf.setLength(bufSize);
			raf.seek(0);
			raf.write(buf);

			exists = false;
		}
	}