protected static Pair<String, byte[]> decomposeIndexAndPartitionFromId(final String idString) { final int pos = idString.lastIndexOf(STATS_ID_SEPARATOR); if (pos < 0) { return Pair.of(idString, null); } return Pair.of( idString.substring(0, pos), ByteArrayUtils.byteArrayFromString(idString.substring(pos + 1))); }
public static String getRowSetName(final String setNamePrefix, final byte[] partitionKey) { String partitionStr; if ((partitionKey != null) && (partitionKey.length > 0)) { partitionStr = "_" + ByteArrayUtils.byteArrayToString(partitionKey); } else { partitionStr = ""; } return setNamePrefix + partitionStr; }
public byte[] getNextPrefix() { return ByteArrayUtils.getNextPrefix(bytes); }
public byte[] getCombinedEndKey() { if ((partitionKey == null) || (partitionKey.length == 0)) { return endKey; } return (endKey == null) ? ByteArrayUtils.combineArrays(ByteArrayUtils.getNextPrefix(partitionKey), endKey) : ByteArrayUtils.combineArrays(partitionKey, endKey); }
public static short shortFromString(final String input) { return byteArrayToShort(byteArrayFromString(input)); }
public static String shortToString(final short input) { return byteArrayToString(shortToByteArray(input)); }
@Override public byte[] toBinary() { if (adapterId == null) { return ByteArrayUtils.shortToByteArray((short) 0); } return ByteArrayUtils.shortToByteArray(adapterId); }
public byte[] getCombinedStartKey() { if ((partitionKey == null) || (partitionKey.length == 0)) { return startKey; } return (startKey == null) ? null : ByteArrayUtils.combineArrays(partitionKey, startKey); }
new AttributeValue().withB(ByteBuffer.wrap(partitionId)))); if (sortRange == null) { start = ByteArrayUtils.shortToByteArray(internalAdapterId); end = new ByteArray(start).getNextPrefix(); } else if (sortRange.isSingleValue()) { start = ByteArrayUtils.combineArrays( ByteArrayUtils.shortToByteArray(internalAdapterId), DynamoDBUtils.encodeSortableBase64(sortRange.getStart())); end = ByteArrayUtils.combineArrays( ByteArrayUtils.shortToByteArray(internalAdapterId), DynamoDBUtils.encodeSortableBase64( ByteArrayUtils.getNextPrefix(sortRange.getStart()))); } else { if (sortRange.getStart() == null) { start = ByteArrayUtils.shortToByteArray(internalAdapterId); } else { start = ByteArrayUtils.combineArrays( ByteArrayUtils.shortToByteArray(internalAdapterId), DynamoDBUtils.encodeSortableBase64(sortRange.getStart())); end = new ByteArray(ByteArrayUtils.shortToByteArray(internalAdapterId)).getNextPrefix(); } else { end = ByteArrayUtils.combineArrays( ByteArrayUtils.shortToByteArray(internalAdapterId), DynamoDBUtils.encodeSortableBase64(sortRange.getEndAsNextPrefix()));
final byte[] currentStrategyBytes = ByteArrayUtils.byteArrayFromString(currentValue); final byte[] nextStrategyBytes = ByteArrayUtils.byteArrayFromString(nextValue); final Object currentObj = PersistenceUtils.fromBinary(currentStrategyBytes); MultiAdapterServerMergeStrategy currentStrategy; return ByteArrayUtils.byteArrayToString(PersistenceUtils.toBinary(currentStrategy));
@Override public void fromBinary(final byte[] bytes) { if (ByteArrayUtils.byteArrayToShort(bytes) == 0) { adapterId = null; } else { adapterId = ByteArrayUtils.byteArrayToShort(bytes); } } }
@Override public Map<String, String> getOptions(final Map<String, String> existingOptions) { final Map<String, String> newOptions = adapter.getOptions(internalAdapterId, existingOptions); String nextAdapterIdsValue = ByteArrayUtils.shortToString(internalAdapterId); if ((existingOptions != null) && existingOptions.containsKey(ADAPTER_IDS_OPTION)) { final String existingAdapterIds = existingOptions.get(ADAPTER_IDS_OPTION); final Set<String> nextAdapters = new HashSet<String>(); for (final String id : nextAdapterIdsValue.split(",")) { nextAdapters.add(id); } final StringBuffer str = new StringBuffer(nextAdapterIdsValue); for (final String id : existingAdapterIds.split(",")) { if (!nextAdapters.contains(id)) { str.append(","); str.append(id); } } nextAdapterIdsValue = str.toString(); } newOptions.put(ADAPTER_IDS_OPTION, nextAdapterIdsValue); newOptions.put( ROW_TRANSFORM_KEY, ByteArrayUtils.byteArrayToString(PersistenceUtils.toBinary(adapter.getTransform()))); return newOptions; } }
@Override protected ByteArray shortToByteArrayId(final short internalAdapterId) { return new ByteArray(ByteArrayUtils.shortToString(internalAdapterId)); }
final SpaceFillingCurve sfc) { final List<byte[]> retVal = new ArrayList<>(); final byte[] tierAndBinId = ByteArrayUtils.combineArrays(new byte[] {tierId}, index.getBinId()); final RangeDecomposition rangeDecomp = sfc.decomposeRange(index, false, DEFAULT_MAX_RANGES); currentRowId = Arrays.copyOf(currentRowId, currentRowId.length); boolean overflow = !ByteArrayUtils.increment(currentRowId); if (!overflow) { retVal.add(currentRowId);
@Override public int compareTo(final GeoWaveKey o) { byte[] internalAdapterIdBytes = ByteArrayUtils.shortToByteArray(adapterId); return WritableComparator.compareBytes( internalAdapterIdBytes, 0, internalAdapterIdBytes.length, ByteArrayUtils.shortToByteArray(o.adapterId), 0, ByteArrayUtils.shortToByteArray(o.adapterId).length); }
protected static byte[] fitExpectedByteCount(final int expectedByteCount, final byte[] bytes) { final int leftPadding = expectedByteCount - bytes.length; if (leftPadding > 0) { final byte[] zeroes = new byte[leftPadding]; Arrays.fill(zeroes, (byte) 0); return ByteArrayUtils.combineArrays(zeroes, bytes); } else if (leftPadding < 0) { final byte[] truncatedBytes = new byte[expectedByteCount]; if (bytes[0] != 0) { Arrays.fill(truncatedBytes, (byte) 255); } else { System.arraycopy(bytes, -leftPadding, truncatedBytes, 0, expectedByteCount); } return truncatedBytes; } return bytes; }
protected short byteArrayToShort(final byte[] bytes) { return ByteArrayUtils.byteArrayToShort(bytes); }
public void deleteRowsFromDataIndex(final byte[][] rows, final short adapterId) { try { final BufferedMutator mutator = getBufferedMutator(getTableName(DataIndexUtils.DATA_ID_INDEX.getName())); final byte[] family = StringUtils.stringToBinary(ByteArrayUtils.shortToString(adapterId)); mutator.mutate(Arrays.stream(rows).map(r -> { final Delete delete = new Delete(r); delete.addFamily(family); return delete; }).collect(Collectors.toList())); } catch (final IOException e) { LOGGER.warn("Unable to delete from data index", e); } }
@Override public void initOptions(final Map<String, String> options) throws IOException { final String mergeStrategyStr = options.get(MERGE_STRATEGY_KEY); if (mergeStrategyStr != null) { final byte[] mergeStrategyBytes = ByteArrayUtils.byteArrayFromString(mergeStrategyStr); mergeStrategy = (ServerMergeStrategy<T>) PersistenceUtils.fromBinary(mergeStrategyBytes); } }
public static String getTableName(final String setNamePrefix, final byte[] partitionKey) { String partitionStr; if ((partitionKey != null) && (partitionKey.length > 0)) { partitionStr = "_" + ByteArrayUtils.byteArrayToString(partitionKey); } else { partitionStr = ""; } return setNamePrefix + partitionStr; }