Update from optimized (cooked) wire format. token-1 token-2 ... partition-1 partition-2 ... tokens are 4 bytes

@param compressedData optimized and compressed config data
@return token/partition map
765018
private Pair<Long, Integer> updateCooked(byte[] compressedData) {
        // Uncompress (inflate) the bytes.
        byte[] cookedBytes;
        try {
            cookedBytes = gunzipBytes(compressedData);
        } catch (IOException e) {
            throw new RuntimeException("Unable to decompress elastic hashinator data.");
        }

        int numEntries = (cookedBytes.length >= 4
                ? ByteBuffer.wrap(cookedBytes).getInt()
                : 0);
        int tokensSize = 4 * numEntries;
        int partitionsSize = 4 * numEntries;
        if (numEntries <= 0 || cookedBytes.length != 4 + tokensSize + partitionsSize) {
            throw new RuntimeException("Bad elastic hashinator cooked config size.");
        }
        long tokens = Bits.unsafe.allocateMemory(8 * numEntries);
        ByteBuffer tokenBuf = ByteBuffer.wrap(cookedBytes, 4, tokensSize);
        ByteBuffer partitionBuf = ByteBuffer.wrap(cookedBytes, 4 + tokensSize, partitionsSize);
        int tokensArray[] = new int[numEntries];
        for (int zz = 3; zz >= 0; zz--) {
            for (int ii = 0; ii < numEntries; ii++) {
                int value = tokenBuf.get();
                value = (value << (zz * 8)) & (0xFF << (zz * 8));
                tokensArray[ii] = (tokensArray[ii] | value);
            }
        }

        int lastToken = Integer.MIN_VALUE;
        for (int ii = 0; ii < numEntries; ii++) {
            int token = tokensArray[ii];
            Preconditions.checkArgument(token >= lastToken);
            lastToken = token;
            long ptr = tokens + (ii * 8);
            Bits.unsafe.putInt(ptr, token);
            final int partitionId = partitionBuf.getInt();
            Bits.unsafe.putInt(ptr + 4, partitionId);
        }
        return Pair.of(tokens, numEntries);
    }
1342076
public String storeData(String cookieData) {
        try {
            String token = generateToken();
            ensureSpaceExists();
            s3StorageProvider.addHiddenContent(this.hiddenSpaceName, token, Constants.MEDIA_TYPE_APPLICATION_JSON,
                                               IOUtil.writeStringToStream(cookieData));
            return token;
        } catch (Exception e) {
            throw new DuraCloudRuntimeException(e);
        }
    }
1078156
public static byte[] fromString(final String pData) {
		if (pData == null) {
			throw new IllegalArgumentException("Argument can't be null");
		}
		StringBuilder sb = new StringBuilder(pData);
		int j = 0;
		for (int i = 0; i < sb.length(); i++) {
			if (!Character.isWhitespace(sb.charAt(i))) {
				sb.setCharAt(j++, sb.charAt(i));
			}
		}
		sb.delete(j, sb.length());
		if (sb.length() % 2 != 0) {
			throw new IllegalArgumentException("Hex binary needs to be even-length :" + pData);
		}
		byte[] result = new byte[sb.length() / 2];
		j = 0;
		for (int i = 0; i < sb.length(); i += 2) {
			result[j++] = (byte) ((Character.digit(sb.charAt(i), 16) << 4) + Character.digit(sb.charAt(i + 1), 16));
		}
		return result;
	}
767382
public static byte[] encode( byte[] dData )
    {
        if( dData == null )
        {
            throw new IllegalArgumentException( "Cannot encode null" );
        }
        byte[] eData = new byte[( ( dData.length + 2 ) / 3 ) * 4];

        int eIndex = 0;
        for( int i = 0; i < dData.length; i += 3 )
        {
            int d1;
            int d2 = 0;
            int d3 = 0;
            int e1;
            int e2;
            int e3;
            int e4;
            int pad = 0;

            d1 = dData[ i ];
            if( ( i + 1 ) < dData.length )
            {
                d2 = dData[ i + 1 ];
                if( ( i + 2 ) < dData.length )
                {
                    d3 = dData[ i + 2 ];
                }
                else
                {
                    pad = 1;
                }
            }
            else
            {
                pad = 2;
            }

            e1 = ALPHASET[ ( d1 & I6O2 ) >> 2 ];
            e2 = ALPHASET[ ( d1 & O6I2 ) << 4 | ( d2 & I4O4 ) >> 4 ];
            e3 = ALPHASET[ ( d2 & O4I4 ) << 2 | ( d3 & I2O6 ) >> 6 ];
            e4 = ALPHASET[ ( d3 & O2I6 ) ];

            eData[ eIndex++ ] = (byte) e1;
            eData[ eIndex++ ] = (byte) e2;
            eData[ eIndex++ ] = ( pad < 2 ) ? (byte) e3 : (byte) '=';
            eData[ eIndex++ ] = ( pad < 1 ) ? (byte) e4 : (byte) '=';

        }
        return eData;
    }
906329
public QrCodeEncoder addBytes(byte[] data) {
		StringBuilder builder = new StringBuilder(data.length);
		for (int i = 0; i < data.length; i++) {
			builder.append((char)data[i]);
		}

		MessageSegment segment = new MessageSegment();
		segment.message = builder.toString();
		segment.data = data;
		segment.length = data.length;
		segment.mode = QrCode.Mode.BYTE;

		segment.encodedSizeBits += 4;
		segment.encodedSizeBits += 8*segment.length;

		segments.add(segment);

		return this;
	}
1253549
@Override
    public final byte[] decompress(byte[] compressed) {
        Assert.notNull(compressed, "compressed bytes cannot be null.");

        try {
            return doDecompress(compressed);
        } catch (IOException e) {
            throw new CompressionException("Unable to decompress bytes.", e);
        }
    }
464468
private void parseData(byte[] data)
	{
		int bytesRead = 0;

		if (grouped)
		{
			group = data[bytesRead];
			bytesRead ++;
		}
		if (encrypted)
		{
			encrType = data[bytesRead];
			bytesRead ++;
		}
		if (lengthIndicator)
		{
			dataLength = Helpers.convertDWordToInt(data, bytesRead);
			bytesRead += 4;
		}

		frameData = new byte[data.length - bytesRead];
		System.arraycopy(data, bytesRead, frameData, 0, frameData.length);
	}
1331888
@Override
    synchronized public int encodeIntoCompressedByteBuffer(
            final ByteBuffer targetBuffer,
            final int compressionLevel) {
        targetBuffer.putInt(DHIST_compressedEncodingCookie);
        targetBuffer.putInt(getNumberOfSignificantValueDigits());
        targetBuffer.putLong(configuredHighestToLowestValueRatio);
        return integerValuesHistogram.encodeIntoCompressedByteBuffer(targetBuffer, compressionLevel) + 16;
    }
1197368
private byte[] toCookedBytes()
    {
        // Allocate for a int pair per token/partition ID entry, plus a size.
        ByteBuffer buf = ByteBuffer.allocate(4 + (m_tokenCount * 8));

        buf.putInt(m_tokenCount);
        // Keep tokens and partition ids separate to aid compression.
        for (int zz = 3; zz >= 0; zz--) {
            int lastToken = Integer.MIN_VALUE;
            for (int ii = 0; ii < m_tokenCount; ii++) {
                int token = Bits.unsafe.getInt(m_tokens + (ii * 8));
                Preconditions.checkArgument(token >= lastToken);
                lastToken = token;
                token = token >>> (zz * 8);
                token = token & 0xFF;
                buf.put((byte)token);
            }
        }
        for (int ii = 0; ii < m_tokenCount; ii++) {
            buf.putInt(Bits.unsafe.getInt(m_tokens + (ii * 8) + 4));
        }

        try {
            return CompressionService.gzipBytes(buf.array());
        } catch (IOException e) {
            throw new RuntimeException("Failed to compress bytes", e);
        }
    }
389910
@Override
    synchronized public int encodeIntoCompressedByteBuffer(
            final ByteBuffer targetBuffer,
            final int compressionLevel) {
        int neededCapacity = getNeededByteBufferCapacity(countsArrayLength);
        if (intermediateUncompressedByteBuffer == null || intermediateUncompressedByteBuffer.capacity() < neededCapacity) {
            intermediateUncompressedByteBuffer = ByteBuffer.allocate(neededCapacity).order(BIG_ENDIAN);
        }
        intermediateUncompressedByteBuffer.clear();
        int initialTargetPosition = targetBuffer.position();

        final int uncompressedLength = encodeIntoByteBuffer(intermediateUncompressedByteBuffer);
        targetBuffer.putInt(getCompressedEncodingCookie());

        targetBuffer.putInt(0); // Placeholder for compressed contents length

        Deflater compressor = new Deflater(compressionLevel);
        compressor.setInput(intermediateUncompressedByteBuffer.array(), 0, uncompressedLength);
        compressor.finish();

        byte[] targetArray;

        if (targetBuffer.hasArray()) {
            targetArray = targetBuffer.array();
        } else {
            if (intermediateUncompressedByteArray == null ||
                intermediateUncompressedByteArray.length < targetBuffer.capacity()) {
                intermediateUncompressedByteArray = new byte[targetBuffer.capacity()];
            }
            targetArray = intermediateUncompressedByteArray;
        }

        int compressedTargetOffset = initialTargetPosition + 8;
        int compressedDataLength =
            compressor.deflate(
                targetArray,
                compressedTargetOffset,
                targetArray.length - compressedTargetOffset
            );
        compressor.end();

        if (!targetBuffer.hasArray()) {
            targetBuffer.put(targetArray, compressedTargetOffset, compressedDataLength);
        }

        targetBuffer.putInt(initialTargetPosition + 4, compressedDataLength); // Record the compressed length
        int bytesWritten = compressedDataLength + 8;
        targetBuffer.position(initialTargetPosition + bytesWritten);
        return bytesWritten;
    }
961601
public static RSAPrivateKey buildPrivateKey(final byte[] keyData)
            throws NoSuchAlgorithmException, InvalidKeySpecException {
        PKCS8EncodedKeySpec privateKeySpec = new PKCS8EncodedKeySpec(keyData);
        KeyFactory keyFactory = KeyFactory.getInstance(CIPHER_ALGORITHM);
        PrivateKey generatePrivate = keyFactory.generatePrivate(privateKeySpec);
        return (RSAPrivateKey) generatePrivate;
    }
727138
public function createToken(array $tokenData, $userId = null)
    {
        $userId = $this->_checkUserId($userId);
        return $this->getTokenLibrary()->createToken($tokenData, $userId);
    }
634874
function processCompressedData (o) {
  // Save the packet counter
  o.lastSampleNumber = parseInt(o.rawDataPacket[0]);

  const samples = [];
  // Decompress the buffer into array
  if (o.lastSampleNumber <= k.OBCIGanglionByteId18Bit.max) {
    decompressSamples(o, decompressDeltas18Bit(o.rawDataPacket.slice(k.OBCIGanglionPacket18Bit.dataStart, k.OBCIGanglionPacket18Bit.dataStop)));
    samples.push(buildSample(o.lastSampleNumber * 2 - 1, o.decompressedSamples[1], o.sendCounts));
    samples.push(buildSample(o.lastSampleNumber * 2, o.decompressedSamples[2], o.sendCounts));

    switch (o.lastSampleNumber % 10) {
      case k.OBCIGanglionAccelAxisX:
        o.accelArray[0] = o.sendCounts ? o.rawDataPacket.readInt8(k.OBCIGanglionPacket18Bit.auxByte - 1) : o.rawDataPacket.readInt8(k.OBCIGanglionPacket18Bit.auxByte - 1) * k.OBCIGanglionAccelScaleFactor;
        break;
      case k.OBCIGanglionAccelAxisY:
        o.accelArray[1] = o.sendCounts ? o.rawDataPacket.readInt8(k.OBCIGanglionPacket18Bit.auxByte - 1) : o.rawDataPacket.readInt8(k.OBCIGanglionPacket18Bit.auxByte - 1) * k.OBCIGanglionAccelScaleFactor;
        break;
      case k.OBCIGanglionAccelAxisZ:
        o.accelArray[2] = o.sendCounts ? o.rawDataPacket.readInt8(k.OBCIGanglionPacket18Bit.auxByte - 1) : o.rawDataPacket.readInt8(k.OBCIGanglionPacket18Bit.auxByte - 1) * k.OBCIGanglionAccelScaleFactor;
        if (o.sendCounts) {
          samples[0].accelData = o.accelArray;
        } else {
          samples[0].accelDataCounts = o.accelArray;
        }
        break;
      default:
        break;
    }
  } else {
    decompressSamples(o, decompressDeltas19Bit(o.rawDataPacket.slice(k.OBCIGanglionPacket19Bit.dataStart, k.OBCIGanglionPacket19Bit.dataStop)));

    samples.push(buildSample((o.lastSampleNumber - 100) * 2 - 1, o.decompressedSamples[1], o.sendCounts));
    samples.push(buildSample((o.lastSampleNumber - 100) * 2, o.decompressedSamples[2], o.sendCounts));
  }

  // Rotate the 0 position for next time
  for (let i = 0; i < k.OBCINumberOfChannelsGanglion; i++) {
    o.decompressedSamples[0][i] = o.decompressedSamples[2][i];
  }

  return samples;
}
469646
public static byte[] encodeBZ(byte[] data) {
    try {
      int blockSize = 4;
      ByteArrayOutputStream output = new ByteArrayOutputStream();
      BZip2CompressorOutputStream compresser = new BZip2CompressorOutputStream(output, blockSize);
      compresser.write(data);
      compresser.close();
      byte[] bytes = output.toByteArray();
      return bytes;
    } catch (IOException e) {
      throw new RuntimeException(e);
    }
  }
473945
public String binaryToString(Object objData) 
    {
        initGlobals();
        if (objData == null)
            return Constants.BLANK;
        String string = null;
        synchronized (gNumberFormat)
        {
            if (m_ibScale != 2)
            {
                gNumberFormat.setMinimumFractionDigits(m_ibScale);
                gNumberFormat.setMaximumFractionDigits(m_ibScale);
            }
            string = gNumberFormat.format(((Float)objData).floatValue());
            if (m_ibScale != 2)
            {
                gNumberFormat.setMinimumFractionDigits(2);
                gNumberFormat.setMaximumFractionDigits(2);
            }
        }
        return string;
    }
1346895
@SuppressWarnings("unchecked")
    public static Map<String, Object> bytesToDocument(byte[] data) {
        return data != null && data.length > 0
                ? SerializationUtils.fromByteArrayFst(data, Map.class)
                : null;
    }
961331
@Override
	public byte[] binaryDiff(final RevisionCodecData codecData, final Diff diff)
		throws UnsupportedEncodingException, EncodingException
	{

		byte[] bData = encode(codecData, diff);
		if (MODE_ZIP_COMPRESSION) {

			Deflater compresser = new Deflater();
			compresser.setInput(bData);
			compresser.finish();

			byte[] output = new byte[1000];
			ByteArrayOutputStream stream = new ByteArrayOutputStream();

			int cLength;
			do {
				cLength = compresser.deflate(output);
				stream.write(output, 0, cLength);
			}
			while (cLength == 1000);

			output = stream.toByteArray();
			if (bData.length + 1 < output.length) {
				return bData;
			}
			else {

				stream = new ByteArrayOutputStream();
				stream.write(new byte[] { -128 }, 0, 1);
				stream.write(output, 0, output.length);

				return stream.toByteArray();
			}
		}

		return bData;
	}