/** * @param bytes Bytes to check. * @return True if passed <code>bytes</code> has {@link ProtobufMagic#PB_MAGIC} for a prefix. */ public static boolean isPBMagicPrefix(final byte [] bytes) { return ProtobufMagic.isPBMagicPrefix(bytes); }
/** * @param bytes Bytes to check. * @return True if passed <code>bytes</code> has {@link ProtobufMagic#PB_MAGIC} for a prefix. */ public static boolean isPBMagicPrefix(final byte [] bytes) { return ProtobufMagic.isPBMagicPrefix(bytes); }
/** * @param bytes Bytes to check. * @return True if passed <code>bytes</code> has {@link #PB_MAGIC} for a prefix. */ public static boolean isPBMagicPrefix(final byte [] bytes) { if (bytes == null) return false; return isPBMagicPrefix(bytes, 0, bytes.length); }
/** * @param bytes Bytes to check. * @param offset offset to start at * @param len length to use * @return True if passed <code>bytes</code> has {@link ProtobufMagic#PB_MAGIC} for a prefix. */ public static boolean isPBMagicPrefix(final byte [] bytes, int offset, int len) { return ProtobufMagic.isPBMagicPrefix(bytes, offset, len); }
/** * @param bytes Bytes to check. * @param offset offset to start at * @param len length to use * @return True if passed <code>bytes</code> has {@link ProtobufMagic#PB_MAGIC} for a prefix. */ public static boolean isPBMagicPrefix(final byte [] bytes, int offset, int len) { return ProtobufMagic.isPBMagicPrefix(bytes, offset, len); }
protected static Quotas quotasFromData( final byte[] data, int offset, int length) throws IOException { int magicLen = ProtobufMagic.lengthOfPBMagic(); if (!ProtobufMagic.isPBMagicPrefix(data, offset, magicLen)) { throw new IOException("Missing pb magic prefix"); } return Quotas.parseFrom(new ByteArrayInputStream(data, offset + magicLen, length - magicLen)); }
/** * @see #persistToFile() */ private void retrieveFromFile(int[] bucketSizes) throws IOException { File persistenceFile = new File(persistencePath); if (!persistenceFile.exists()) { return; } assert !cacheEnabled; try (FileInputStream in = deleteFileOnClose(persistenceFile)) { int pblen = ProtobufMagic.lengthOfPBMagic(); byte[] pbuf = new byte[pblen]; int read = in.read(pbuf); if (read != pblen) { throw new IOException("Incorrect number of bytes read while checking for protobuf magic " + "number. Requested=" + pblen + ", Received= " + read + ", File=" + persistencePath); } if (! ProtobufMagic.isPBMagicPrefix(pbuf)) { // In 3.0 we have enough flexibility to dump the old cache data. // TODO: In 2.x line, this might need to be filled in to support reading the old format throw new IOException("Persistence file does not start with protobuf magic number. " + persistencePath); } parsePB(BucketCacheProtos.BucketCacheEntry.parseDelimitedFrom(in)); bucketAllocator = new BucketAllocator(cacheCapacity, bucketSizes, backingMap, realCacheSize); } }
if (ProtobufMagic.isPBMagicPrefix(data)) { int prefixLen = ProtobufMagic.lengthOfPBMagic(); try {
/** * @param bytes Bytes to check. * @return True if passed <code>bytes</code> has {@link #PB_MAGIC} for a prefix. */ public static boolean isPBMagicPrefix(final byte [] bytes) { if (bytes == null) return false; return isPBMagicPrefix(bytes, 0, bytes.length); }
/** * @param bytes Bytes to check. * @return True if passed <code>bytes</code> has {@link ProtobufMagic#PB_MAGIC} for a prefix. */ public static boolean isPBMagicPrefix(final byte [] bytes) { return ProtobufMagic.isPBMagicPrefix(bytes); }
if (ProtobufMagic.isPBMagicPrefix(data)) { int prefixLen = ProtobufMagic.lengthOfPBMagic(); try {
/** * @param bytes Bytes to check. * @return True if passed <code>bytes</code> has {@link ProtobufMagic#PB_MAGIC} for a prefix. */ public static boolean isPBMagicPrefix(final byte [] bytes) { return ProtobufMagic.isPBMagicPrefix(bytes); }
/** * @param bytes Bytes to check. * @param offset offset to start at * @param len length to use * @return True if passed <code>bytes</code> has {@link ProtobufMagic#PB_MAGIC} for a prefix. */ public static boolean isPBMagicPrefix(final byte [] bytes, int offset, int len) { return ProtobufMagic.isPBMagicPrefix(bytes, offset, len); }
/** * @param bytes Bytes to check. * @param offset offset to start at * @param len length to use * @return True if passed <code>bytes</code> has {@link ProtobufMagic#PB_MAGIC} for a prefix. */ public static boolean isPBMagicPrefix(final byte [] bytes, int offset, int len) { return ProtobufMagic.isPBMagicPrefix(bytes, offset, len); }
protected static Quotas quotasFromData( final byte[] data, int offset, int length) throws IOException { int magicLen = ProtobufMagic.lengthOfPBMagic(); if (!ProtobufMagic.isPBMagicPrefix(data, offset, magicLen)) { throw new IOException("Missing pb magic prefix"); } return Quotas.parseFrom(new ByteArrayInputStream(data, offset + magicLen, length - magicLen)); }
if (ProtobufMagic.isPBMagicPrefix(data)) { int prefixLen = ProtobufMagic.lengthOfPBMagic(); try {
/** * @param bytes Bytes to check. * @return True if passed <code>bytes</code> has {@link ProtobufMagic#PB_MAGIC} for a prefix. */ public static boolean isPBMagicPrefix(final byte [] bytes) { return ProtobufMagic.isPBMagicPrefix(bytes); }
/** * @param bytes Bytes to check. * @return True if passed <code>bytes</code> has {@link ProtobufMagic#PB_MAGIC} for a prefix. */ public static boolean isPBMagicPrefix(final byte [] bytes) { return ProtobufMagic.isPBMagicPrefix(bytes); }
/** * @param bytes Bytes to check. * @param offset offset to start at * @param len length to use * @return True if passed <code>bytes</code> has {@link ProtobufMagic#PB_MAGIC} for a prefix. */ public static boolean isPBMagicPrefix(final byte [] bytes, int offset, int len) { return ProtobufMagic.isPBMagicPrefix(bytes, offset, len); }
if (ProtobufMagic.isPBMagicPrefix(data)) { int prefixLen = ProtobufMagic.lengthOfPBMagic(); try {