Decodes a byteArray containing jpeg encoded bytes into a purgeable bitmap

<p>Adds a JFIF End-Of-Image marker if needed before decoding.

@param bytesRef the byte buffer that contains the encoded bytes
@return
765184
@Override
  protected Bitmap decodeJPEGByteArrayAsPurgeable(
      CloseableReference<PooledByteBuffer> bytesRef, int length, BitmapFactory.Options options) {
    byte[] suffix = endsWithEOI(bytesRef, length) ? null : EOI;
    final PooledByteBuffer pooledByteBuffer = bytesRef.get();
    Preconditions.checkArgument(length <= pooledByteBuffer.size());
    // allocate bigger array in case EOI needs to be added
    final CloseableReference<byte[]> encodedBytesArrayRef = mFlexByteArrayPool.get(length + 2);
    try {
      byte[] encodedBytesArray = encodedBytesArrayRef.get();
      pooledByteBuffer.read(0, encodedBytesArray, 0, length);
      if (suffix != null) {
        putEOI(encodedBytesArray, length);
        length += 2;
      }
      Bitmap bitmap = BitmapFactory.decodeByteArray(
          encodedBytesArray,
          0,
          length,
          options);
      return Preconditions.checkNotNull(bitmap, "BitmapFactory returned null");
    } finally {
      CloseableReference.closeSafely(encodedBytesArrayRef);
    }
  }
880762
static final int decodeFromBytes(final byte[] arcs, final int start, final int n) {
    int r = 0;
    for (int i = n; --i >= 0;) {
      r = r << 8 | (arcs[start + i] & 0xff);
    }
    return r;
  }
1295458
public BitmapHandler decode(File file) {
        try {
            return decode(new FileInputStream(file));
        } catch (FileNotFoundException e) {
            throw new RuntimeException("unexpected error.", e);
        }
    }
143054
public static ByteBuffer copyBuffer(final ByteBuffer buf) {
        if(buf == null)
            return null;
        int offset=buf.hasArray()? buf.arrayOffset() + buf.position() : buf.position(), len=buf.remaining();
        byte[] tmp=new byte[len];
        if(!buf.isDirect())
            System.arraycopy(buf.array(), offset, tmp, 0, len);
        else {
         //   buf.get(tmp, 0, len);
            for(int i=0; i < len; i++)
                tmp[i]=buf.get(i+offset);
        }
        return ByteBuffer.wrap(tmp);
    }
496821
public int decode(final InputStream stream, final ByteBuffer buffer) throws IOException {
        while (buffer.remaining() >= 64) {
            int val = stream.read();
            if (val < 0) {
                break; // EOF
            }

            if ((val & COMPRESSED_RUN_MASK) == COMPRESSED_RUN_MASK) {
                int count = val & ~COMPRESSED_RUN_MASK;

                int pixel = stream.read();
                if (pixel < 0) {
                    break; // EOF
                }

                for (int i = 0; i < count; i++) {
                    buffer.put((byte) pixel);
                }
            }
            else {
                buffer.put((byte) val);
            }
        }

        return buffer.position();
    }
1103397
public Object decode(byte[] frame, int offset, int indirect, JMFMessageData msg) throws JMFMessageCorruptionException {
    if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) JmfTr.entry(this, tc, "decode", new Object[]{frame, offset, indirect, msg});
    Object result = null;
    if (indirect < 0) {
      indirect = this.indirect;
    }
    if (indirect > 0) {
      result = new JSVaryingListImpl(frame, offset, element, indirect);
    }
    else if (varying) {
      result = new JSVaryingListImpl(frame, offset, element, 0);
    }
    else {
      result = new JSFixedListImpl(frame, offset, element);
    }
    if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) JmfTr.exit(this, tc, "decode",  result);
    return result;
  }
639902
public static short[] decodeOctetString(ByteBuffer buf) {
        DerId id = DerId.decode(buf);
        if (!id.matches(DerId.TagClass.UNIVERSAL, ASN1_OCTET_STRING_TAG_NUM)) {
            throw new IllegalArgumentException("Expected OCTET STRING identifier, received " + id);
        }
        int len = DerUtils.decodeLength(buf);
        if (buf.remaining() < len) {
            throw new IllegalArgumentException("Insufficient content for OCTET STRING");
        }
        short[] dst = new short[len];
        for (int i = 0; i < len; i++) {
            dst[i] = (short) (0xff & buf.get());
        }
        return dst;
    }
191833
private String unexternalizeImageRef(String ref) {
    String unexternalizedRef = ref;

    if (StringUtils.isNotEmpty(unexternalizedRef)) {

      // decode if required
      unexternalizedRef = decodeIfEncoded(unexternalizedRef);

      // TODO: implementation has to be aligned with MediaSource implementations!
      // remove default servlet extension that is needed for inline images in RTE
      unexternalizedRef = StringUtils.removeEnd(unexternalizedRef, "/" + JcrConstants.JCR_CONTENT + ".default");
      unexternalizedRef = StringUtils.removeEnd(unexternalizedRef, "/_jcr_content.default");
    }

    return unexternalizedRef;
  }
66857
public final static byte[] encode(BytesRef[] values) throws IOException {
    BytesRefTermsSet termsSet = new BytesRefTermsSet(new NoopCircuitBreaker("<term_set>"));
    for (int i = 0; i < values.length; i++) {
      termsSet.add(values[i]);
    }
    return termsSet.writeToBytes().bytes;
  }
1322630
@Override
  public NamingRegisterRequest decode(final byte[] buf) {
    final AvroNamingRegisterRequest avroNamingRegisterRequest =
        AvroUtils.fromBytes(buf, AvroNamingRegisterRequest.class);
    return new NamingRegisterRequest(
        new NameAssignmentTuple(factory.getNewInstance(avroNamingRegisterRequest.getId().toString()),
            new InetSocketAddress(avroNamingRegisterRequest.getHost().toString(), avroNamingRegisterRequest.getPort()))
    );
  }
911642
public static long fromByteBuffer(ByteBuffer buf) {
      if (buf.remaining() < 1) {
         // XXX make all callers check for -1
         return -1;
      }
      long first = 0x00000000000000FFL & ((long) buf.get());
      long value;
      if (first < 253) {
         // Regard this byte as a 8 bit value.
         value = 0x00000000000000FFL & ((long) first);
      } else if (first == 253) {
         // Regard the following two bytes as a 16 bit value
         if (buf.remaining() < 2) {
            return -1;
         }
         buf.order(ByteOrder.LITTLE_ENDIAN);
         value = 0x0000000000FFFFL & ((long) buf.getShort());
      } else if (first == 254) {
         // Regard the following four bytes as a 32 bit value
         if (buf.remaining() < 4) {
            return -1;
         }
         buf.order(ByteOrder.LITTLE_ENDIAN);
         value = 0x00000000FFFFFFFF & ((long) buf.getInt());
      } else {
         // Regard the following four bytes as a 64 bit value
         if (buf.remaining() < 8) {
            return -1;
         }
         buf.order(ByteOrder.LITTLE_ENDIAN);
         value = buf.getLong();
      }
      return value;
   }
538026
@Override
    public int decode ( byte[] buffer, int bufferIndex, int len ) throws SMBProtocolDecodingException {
        int start = bufferIndex;
        this.allocationSize = SMBUtil.readInt8(buffer, bufferIndex);
        bufferIndex += 8;
        this.endOfFile = SMBUtil.readInt8(buffer, bufferIndex);
        bufferIndex += 8;
        this.numberOfLinks = SMBUtil.readInt4(buffer, bufferIndex);
        bufferIndex += 4;
        this.deletePending = ( buffer[ bufferIndex++ ] & 0xFF ) > 0;
        this.directory = ( buffer[ bufferIndex++ ] & 0xFF ) > 0;
        return bufferIndex - start;
    }
429963
public Packet decode(ByteBuffer bytes) {
        return processPacket(Memories.wrap(bytes, memoryProperties.getCheckBounds()));
    }
258124
public static int decodeSequence(ByteBuffer buf) {
        DerId id = DerId.decode(buf);
        if (!id.matches(DerId.TagClass.UNIVERSAL, DerId.EncodingType.CONSTRUCTED, ASN1_SEQUENCE_TAG_NUM)) {
            throw new IllegalArgumentException("Expected SEQUENCE identifier, received " + id);
        }
        int len = DerUtils.decodeLength(buf);
        if (buf.remaining() < len) {
            throw new IllegalArgumentException("Insufficient content for SEQUENCE");
        }
        return len;
    }
631204
public AsciiString decode(ByteBuf buf, int length) throws Http2Exception {
        processor.reset();
        buf.forEachByte(buf.readerIndex(), length, processor);
        buf.skipBytes(length);
        return processor.end();
    }
1278700
@Override
  public NamingLookupResponse decode(final byte[] buf) {
    final AvroNamingLookupResponse avroResponse = AvroUtils.fromBytes(buf, AvroNamingLookupResponse.class);
    final List<NameAssignment> nas = new ArrayList<>(avroResponse.getTuples().size());
    for (final AvroNamingAssignment tuple : avroResponse.getTuples()) {
      nas.add(
          new NameAssignmentTuple(
              factory.getNewInstance(tuple.getId().toString()),
              new InetSocketAddress(tuple.getHost().toString(), tuple.getPort())
          )
      );
    }
    return new NamingLookupResponse(nas);
  }
1229181
function amf3decByteArray(buf) {
    var sLen = amf3decUI29(buf);
    var s = sLen & 1; // TODO: Check if we follow the same rule!
    sLen = sLen >> 1; // The real length without the lowest bit
    if (s) return { len: sLen.value + 5, value: buf.slice(5, sLen.value + 5) };
    throw new Error("Error, we have a need to decode a String that is a Reference"); // TODO: Implement references!
}