Decodes the JPEG header. This must be called before the image size can be queried.

@throws IOException if an IO error occurred
768090
public void decodeHeader() throws IOException {
        if(!headerDecoded) {
            headerDecoded = true;

            int m = getMarker();
            if(m != 0xD8) {
                throw new IOException("no SOI");
            }
            m = getMarker();
            while(m != 0xC0 && m != 0xC1) { // SOF
                processMarker(m);
                m = getMarker();
                while(m == MARKER_NONE) {
                    m = getMarker();
                }
            }

            processSOF();
        }
    }
1220038
@Override
    protected void decode(DataInputStream buffer) throws IOException
    {
        entityId = buffer.readShort();
        final int number = buffer.readByte();
        for (int i = 0; i < number; i++)
        {
            decode(buffer, i);
        }
    }
253387
private void readHeader() {
        final int type = readUnsignedByte();
        if ((type & RESERVED_MASK) != 0) {
            throw new ArmeriaStatusException(
                    StatusCodes.INTERNAL,
                    DEBUG_STRING + ": Frame header malformed: reserved bits not zero");
        }
        compressedFlag = (type & COMPRESSED_FLAG_MASK) != 0;

        // Update the required length to include the length of the frame.
        requiredLength = readInt();
        if (requiredLength < 0 || requiredLength > maxMessageSizeBytes) {
            throw new ArmeriaStatusException(
                    StatusCodes.RESOURCE_EXHAUSTED,
                    String.format("%s: Frame size %d exceeds maximum: %d. ",
                                  DEBUG_STRING, requiredLength,
                                  maxMessageSizeBytes));
        }

        // Continue reading the frame body.
        state = State.BODY;
    }
794450
public static void decode(CharSequence in, Appendable out) throws IOException{
		decode(in, UTF_8, out);
	}
1316011
public synchronized ByteBuffer getExtraHeader() throws IOException {
    final int size = headersize - INTERNAL_HEADER_SIZE;
    final MapMode mode = writable ? MapMode.READ_WRITE : MapMode.READ_ONLY;
    return file.getChannel().map(mode, INTERNAL_HEADER_SIZE, size);
  }
1108393
private void encodeThis() throws IOException {
        DerOutputStream out = new DerOutputStream();
        out.putInteger(skipCerts);
        this.extensionValue = out.toByteArray();
    }
1046051
public final void decode(byte type, byte from, byte dest, DataInputStream buffer) throws IOException
    {
        this.type = type;
        clientId = from;
        clientDestId = dest;
        decode(buffer);
    }
715649
def decode_header_field v
    return unless v
    return v unless v.is_a? String
    return unless v.size < MAX_HEADER_VALUE_SIZE # avoid regex blowup on spam
    d = v.dup
    d = d.transcode($encoding, 'ASCII')
    Rfc2047.decode_to $encoding, d
  end
619416
protected void readHeader() throws IOException {
        StringBuilder id = new StringBuilder(8);
        for (int i = 0; i < 6; i++) {
            id.append((char)in.read());
        }
        if (!id.toString().startsWith("GIF8")) {
            throw new IOException("Gif signature nor found.");
        }
        
        readLSD();
        if (gctFlag) {
            m_global_table = readColorTable(m_gbpc);
        }
    }
1051623
private void go() throws IOException {
    long start = System.currentTimeMillis();
    System.out.println("Decompressing image file: " + inputFile + " to "
        + outputFile);
    DataInputStream in = null;
    DataOutputStream out = null;

    try {
      // setup in
      PositionTrackingInputStream ptis = new PositionTrackingInputStream(
          new FileInputStream(new File(inputFile)));
      in = new DataInputStream(ptis);

      // read header information
      int imgVersion = in.readInt();
      if (!LayoutVersion.supports(Feature.FSIMAGE_COMPRESSION, imgVersion)) {
        System.out
            .println("Image is not compressed. No output will be produced.");
        return;
      }
      int namespaceId = in.readInt();
      long numFiles = in.readLong();
      long genstamp = in.readLong();

      long imgTxId = -1;
      if (LayoutVersion.supports(Feature.STORED_TXIDS, imgVersion)) {
        imgTxId = in.readLong();
      }
      FSImageCompression compression = FSImageCompression
          .readCompressionHeader(new Configuration(), in);
      if (compression.isNoOpCompression()) {
        System.out
            .println("Image is not compressed. No output will be produced.");
        return;
      }
      in = BufferedByteInputStream.wrapInputStream(
          compression.unwrapInputStream(in), FSImage.LOAD_SAVE_BUFFER_SIZE,
          FSImage.LOAD_SAVE_CHUNK_SIZE);
      System.out.println("Starting decompression.");

      // setup output
      out = new DataOutputStream(new BufferedOutputStream(new FileOutputStream(
          outputFile)));

      // write back the uncompressed information
      out.writeInt(imgVersion);
      out.writeInt(namespaceId);
      out.writeLong(numFiles);
      out.writeLong(genstamp);
      if (LayoutVersion.supports(Feature.STORED_TXIDS, imgVersion)) {
        out.writeLong(imgTxId);
      }
      // no compression
      out.writeBoolean(false);

      // copy the data
      long size = new File(inputFile).length();
      // read in 1MB chunks
      byte[] block = new byte[1024 * 1024];
      while (true) {
        int bytesRead = in.read(block);
        if (bytesRead <= 0)
          break;
        out.write(block, 0, bytesRead);
        printProgress(ptis.getPos(), size);
      }

      out.close();

      long stop = System.currentTimeMillis();
      System.out.println("Input file : " + inputFile + " size: " + size);
      System.out.println("Output file: " + outputFile + " size: "
          + new File(outputFile).length());
      System.out.println("Decompression completed in " + (stop - start)
          + " ms.");
    } finally {
      if (in != null)
        in.close();
      if (out != null)
        out.close();
    }
  }
424454
@Deprecated
	public static FileMessage decode(ByteArray encodedMessage) throws IOException {
		File file = File.createTempFile("FileMessage.", null);
		file.deleteOnExit();
		return decode(encodedMessage, file);
	}
496990
private void initializeStream() throws IOException {
    int headerDataSize;
    if (isPasswordEncrypted) {
      headerDataSize = AES256v3Ciphertext.HEADER_SIZE
          + AES256v3Ciphertext.ENCRYPTION_SALT_LENGTH
          + AES256v3Ciphertext.HMAC_SALT_LENGTH
          + AES256v3Ciphertext.AES_BLOCK_SIZE;
    } else {
      headerDataSize = AES256v3Ciphertext.HEADER_SIZE
          + AES256v3Ciphertext.AES_BLOCK_SIZE;
    }

    byte[] headerData = new byte[headerDataSize];
    StreamUtils.readAllBytesOrFail(in, headerData); // throws EOF if insufficient data

    int offset = 0;
    byte version = headerData[offset++];

    if (version != AES256v3Ciphertext.EXPECTED_VERSION) {
      throw new IOException(String.format("Expected version %d but found %d.",
          AES256v3Ciphertext.EXPECTED_VERSION, version));
    }

    byte options = headerData[offset++];

    if (isPasswordEncrypted) {
      if (options != AES256v3Ciphertext.FLAG_PASSWORD) {
        throw new IOException("Expected password flag missing.");
      }

      byte[] decryptionSalt = new byte[AES256v3Ciphertext.ENCRYPTION_SALT_LENGTH];
      System.arraycopy(headerData, offset, decryptionSalt, 0,
          decryptionSalt.length);
      offset += decryptionSalt.length;

      byte[] hmacSalt = new byte[AES256v3Ciphertext.HMAC_SALT_LENGTH];
      System.arraycopy(headerData, offset, hmacSalt, 0, hmacSalt.length);
      offset += hmacSalt.length;

      // Derive keys
      JNCryptor cryptor = new AES256JNCryptor();
      try {
        decryptionKey = cryptor.keyForPassword(password, decryptionSalt);
        hmacKey = cryptor.keyForPassword(password, hmacSalt);
      } catch (CryptorException e) {
        throw new IOException("Failed to derive keys from password.", e);
      }

    } else {
      if (options != 0) {
        throw new IOException("Expected options byte to be zero.");
      }
    }

    byte[] iv = new byte[AES256v3Ciphertext.AES_BLOCK_SIZE];
    System.arraycopy(headerData, offset, iv, 0, iv.length);

    trailerIn = new TrailerInputStream(in, AES256v3Ciphertext.HMAC_SIZE);

    try {
      Cipher decryptCipher = Cipher
          .getInstance(AES256JNCryptor.AES_CIPHER_ALGORITHM);
      decryptCipher.init(Cipher.DECRYPT_MODE, decryptionKey,
          new IvParameterSpec(iv));

      mac = Mac.getInstance(AES256JNCryptor.HMAC_ALGORITHM);
      mac.init(hmacKey);

      // MAC the header
      mac.update(headerData);

      // The decryption stream will write the non-decrypted bytes to the mac
      // stream
      pushbackInputStream = new PushbackInputStream(new CipherInputStream(
          new MacUpdateInputStream(trailerIn, mac), decryptCipher), 1);


    } catch (GeneralSecurityException e) {
      throw new IOException("Failed to initiate cipher.", e);
    }
  }
808598
public BufferedImage readFrame() throws IOException {

		if (!open) {
			return null;
		}

		mark(FRAME_MAX_LENGTH);

		int n = getStartOfSequence(this, SOI_MARKER);

		reset();

		final byte[] header = new byte[n];

		readFully(header);

		int length = -1;
		try {
			length = parseContentLength(header);
		} catch (NumberFormatException e) {
			length = getEndOfSeqeunce(this, EOI_MARKER);
		}

		if (length == 0) {
			LOG.error("Invalid MJPEG stream, EOI (0xFF,0xD9) not found!");
		}

		reset();

		final byte[] frame = new byte[length];

		skipBytes(n);

		readFully(frame);

		try (final ByteArrayInputStream bais = new ByteArrayInputStream(frame)) {
			return ImageIO.read(bais);
		} catch (IOException e) {
			return null;
		}
	}
679495
private void writeHeader() throws IOException {
    final ByteBuffer headerBuffer = ByteBuffer.allocate(LZ4_MAX_HEADER_LENGTH).order(ByteOrder.LITTLE_ENDIAN);
    headerBuffer.putInt(MAGIC);
    headerBuffer.put(frameInfo.getFLG().toByte());
    headerBuffer.put(frameInfo.getBD().toByte());
    if (frameInfo.isEnabled(FLG.Bits.CONTENT_SIZE)) {
      headerBuffer.putLong(knownSize);
    }
    // compute checksum on all descriptor fields
    final int hash = (checksum.hash(headerBuffer.array(), INTEGER_BYTES, headerBuffer.position() - INTEGER_BYTES, 0) >> 8) & 0xFF;
    headerBuffer.put((byte) hash);
    // write out frame descriptor
    out.write(headerBuffer.array(), 0, headerBuffer.position());
  }
274159
protected final int decodeLength ()
    {
        // if we don't have enough bytes to determine our frame size, stop
        // here and let the caller know that we're not ready
        if (_have < HEADER_SIZE) {
            return -1;
        }

        // decode the frame length
        _buffer.rewind();
        int length = (_buffer.get() & 0xFF) << 24;
        length += (_buffer.get() & 0xFF) << 16;
        length += (_buffer.get() & 0xFF) << 8;
        length += (_buffer.get() & 0xFF);
        _buffer.position(_have);

        return length;
    }
126591
public void decode(int streamId, ByteBuf in, Http2Headers headers, boolean validateHeaders) throws Http2Exception {
        Http2HeadersSink sink = new Http2HeadersSink(streamId, headers, maxHeaderListSize, validateHeaders);
        decode(in, sink);

        // Now that we've read all of our headers we can perform the validation steps. We must
        // delay throwing until this point to prevent dynamic table corruption.
        sink.finish();
    }
148018
private void readHeader() {
        String id = "";
        for (int i = 0; i < 6; i++) {
            id += (char) read();
        }
        if (!id.startsWith("GIF")) {
            header.status = GifDecoder.STATUS_FORMAT_ERROR;
            return;
        }
        readLSD();
        if (header.gctFlag && !err()) {
            header.gct = readColorTable(header.gctSize);
            header.bgColor = header.gct[header.bgIndex];
        }
    }