/** * Utility to convert a String to bytes * * @param string incoming String to convert * @return a byte array */ public static byte[] stringToBinary(final String string) { return string.getBytes(getGeoWaveCharset()); }
/** * Utility to convert bytes to a String * * @param binary a byte array to convert to a String * @return a String representation of the byte array */ public static String stringFromBinary(final byte[] binary) { return new String(binary, getGeoWaveCharset()); }
/** * Convert binary data to a string for transport * * @param byteArray the binary data * @return the base64url encoded string */ public static String byteArrayToString(final byte[] byteArray) { return new String(ENCODER.encode(byteArray), StringUtils.getGeoWaveCharset()); }
public MemoryMetadataEntry(final GeoWaveMetadata metadata) { this(metadata, UUID.randomUUID().toString().getBytes(StringUtils.getGeoWaveCharset())); }
private static String getGroupAsString(final byte[] data) { return new String(getGroup(data), StringUtils.getGeoWaveCharset()); }
private byte[] putData(final String groupID, final double weight, final byte[] dataIdBytes) { keyBuffer.rewind(); final byte[] groupIDBytes = groupID.getBytes(StringUtils.getGeoWaveCharset()); // try to reuse final int size = dataIdBytes.length + 16 + groupIDBytes.length; if (keyBuffer.capacity() < size) { keyBuffer = ByteBuffer.allocate(size); } keyBuffer.putDouble(weight); keyBuffer.putInt(groupIDBytes.length); keyBuffer.put(groupIDBytes); keyBuffer.putInt(dataIdBytes.length); keyBuffer.put(dataIdBytes); return keyBuffer.array(); } }
public static boolean validate(final URL file) { try (Scanner scanner = new Scanner(file.openStream(), StringUtils.getGeoWaveCharset().toString())) { if (scanner.hasNextLine()) { final String line = scanner.nextLine(); return line.split(",").length == 4; } } catch (final Exception e) { Log.warn("Error validating file: " + file.getPath(), e); return false; } return false; } }
/** * Utility to convert bytes to a String * * @param binary a byte array to convert to a String * @return a String representation of the byte array */ public static String[] stringsFromBinary(final byte[] binary) { final ByteBuffer buf = ByteBuffer.wrap(binary); final int count = VarintUtils.readUnsignedInt(buf); final String[] result = new String[count]; for (int i = 0; i < count; i++) { final int size = VarintUtils.readUnsignedInt(buf); final byte[] strBytes = new byte[size]; buf.get(strBytes); result[i] = new String(strBytes, getGeoWaveCharset()); } return result; }
/** * Utility to convert a String to bytes * * @param string incoming String to convert * @return a byte array */ public static byte[] stringsToBinary(final String strings[]) { int len = VarintUtils.unsignedIntByteLength(strings.length); final List<byte[]> strsBytes = new ArrayList<byte[]>(); for (final String str : strings) { final byte[] strByte = str.getBytes(getGeoWaveCharset()); strsBytes.add(strByte); len += (strByte.length + VarintUtils.unsignedIntByteLength(strByte.length)); } final ByteBuffer buf = ByteBuffer.allocate(len); VarintUtils.writeUnsignedInt(strings.length, buf); for (final byte[] str : strsBytes) { VarintUtils.writeUnsignedInt(str.length, buf); buf.put(str); } return buf.array(); }
public static void initialize(String configFile) { synchronized (MUTEX) { if (!initialized) { FeatureConfigParser fcp = new FeatureConfigParser(); ByteArrayInputStream bais = new ByteArrayInputStream(configFile.getBytes(StringUtils.getGeoWaveCharset())); try { fcp.parseConfig(bais); } catch (IOException e) { LOGGER.error("Unable to parse config file string", e); } finally { IOUtils.closeQuietly(bais); } for (FeatureDefinition fd : Features) { parseFeatureDefinition(fd); } initialized = true; } } }
final InputStream fis = input.openStream(); final BufferedReader fr = new BufferedReader(new InputStreamReader(fis, StringUtils.getGeoWaveCharset())); final BufferedReader br = new BufferedReader(fr); return new CloseableIterator<AvroTdrivePoint>() {
final InputStreamReader isr = new InputStreamReader(in, StringUtils.getGeoWaveCharset()); final BufferedReader br = new BufferedReader(isr); int pointInstance = 0;