public static UTF8StringPointable copyResetUTF8Pointable(UTF8StringPointable srcString, ByteArrayAccessibleOutputStream destCopyStorage, UTF8StringPointable destString) { destCopyStorage.reset(); destCopyStorage.write(srcString.getByteArray(), srcString.getStartOffset(), srcString.getMetaDataLength() + srcString.getUTF8Length()); destString.set(destCopyStorage.getByteArray(), 0, destCopyStorage.size()); return destString; }
public static UTF8StringPointable generateUTF8Pointable(String string) { byte[] bytes; bytes = UTF8StringUtil.writeStringToBytes(string); UTF8StringPointable ptr = new UTF8StringPointable(); ptr.set(bytes, 0, bytes.length); return ptr; }
/** * Parses string as double * @param textPtr input string * @param result placeholder for the result * @return {@code true} if parsing was successful, {@code false} otherwise */ public static boolean parseDouble(UTF8StringPointable textPtr, AMutableDouble result) { double v; if (POSITIVE_INF.compareTo(textPtr) == 0) { v = Double.POSITIVE_INFINITY; } else if (NEGATIVE_INF.compareTo(textPtr) == 0) { v = Double.NEGATIVE_INFINITY; } else if (NAN.compareTo(textPtr) == 0) { v = Double.NaN; } else { try { v = Double.parseDouble(textPtr.toString()); } catch (NumberFormatException e) { return false; } } result.setValue(v); return true; }
public void reset(UTF8StringPointable valuePtr) { int utfLen = valuePtr.getUTF8Length(); if (buf == null || buf.length < utfLen) { buf = new char[utfLen]; } int bytePos = 0; int charPos = 0; while (bytePos < utfLen) { buf[charPos++] = valuePtr.charAt(valuePtr.getMetaDataLength() + bytePos); bytePos += valuePtr.charSize(valuePtr.getMetaDataLength() + bytePos); } this.length = charPos; }
public int getCharStartOffset() { return getStartOffset() + getMetaDataLength(); }
@Override public void convertAnyURI(UTF8StringPointable stringp, DataOutput dOut) throws SystemException, IOException { dOut.write(returnTag); dOut.write(stringp.getByteArray(), stringp.getStartOffset(), stringp.getLength()); }
protected void processArgument(int argIdx, IPointable argPtr, UTF8StringPointable outStrPtr) throws HyracksDataException { byte[] bytes = argPtr.getByteArray(); int start = argPtr.getStartOffset(); // Type check. if (bytes[start] != ATypeTag.SERIALIZED_STRING_TYPE_TAG) { throw new TypeMismatchException(sourceLoc, funcID, argIdx, bytes[start], ATypeTag.SERIALIZED_STRING_TYPE_TAG); } int len = argPtr.getLength(); outStrPtr.set(bytes, start + 1, len); }
@Override public void evaluate(IFrameTupleReference tuple, IPointable result) throws HyracksDataException { try { eval.evaluate(tuple, inputArg); byte[] binary = inputArg.getByteArray(); int startOffset = inputArg.getStartOffset(); int len = inputArg.getLength(); byte tt = binary[startOffset]; if (tt == ATypeTag.SERIALIZED_BINARY_TYPE_TAG) { result.set(inputArg); } else if (tt == ATypeTag.SERIALIZED_STRING_TYPE_TAG) { resultStorage.reset(); utf8Ptr.set(inputArg.getByteArray(), startOffset + 1, len - 1); char[] buffer = utf8Ptr.toString().toCharArray(); out.write(ATypeTag.BINARY.serialize()); byteArrayParser.parse(buffer, 0, buffer.length, out); result.set(resultStorage); } else { throw new TypeMismatchException(sourceLoc, BuiltinFunctions.BINARY_HEX_CONSTRUCTOR, 0, tt, ATypeTag.SERIALIZED_BINARY_TYPE_TAG, ATypeTag.SERIALIZED_STRING_TYPE_TAG); } } catch (IOException e) { throw new InvalidDataFormatException(sourceLoc, BuiltinFunctions.BINARY_HEX_CONSTRUCTOR, e, ATypeTag.SERIALIZED_BINARY_TYPE_TAG); } } }
byte[] bytes = textPtr.getByteArray(); int offset = textPtr.getCharStartOffset(); limit = Long.MIN_VALUE; int end = textPtr.getStartOffset() + textPtr.getLength(); for (; offset < end; offset++) { int digit;
stringp.set(abvsInner.getByteArray(), abvsInner.getStartOffset() + 1, abvsInner.getLength() - 1); } catch (IOException e) { if (stringp.getUTFLength() > 0) { out.write(stringp.getByteArray(), stringp.getStartOffset() + 2, stringp.getUTFLength());
/**** * String functions */ public int ignoreCaseCompareTo(UTF8StringPointable other) { return UTF8StringUtil.lowerCaseCompareTo(this.getByteArray(), this.getStartOffset(), other.getByteArray(), other.getStartOffset()); }
tvp1.getValue(stringp1); out.write(ValueTag.XS_STRING_TAG); out.write(stringp1.getByteArray(), stringp1.getStartOffset(), stringp1.getLength()); result.set(abvs.getByteArray(), abvs.getStartOffset(), abvs.getLength()); } catch (IOException e) { out.write(stringp2.getByteArray(), stringp2.getStartOffset() + 2, stringp2.getUTFLength()); out.write(stringp1.getByteArray(), stringp1.getStartOffset() + 2, stringp1.getUTFLength());
/** * Generates a reversed string from an input source string * * @param srcPtr * , the input source string. * @param builder * , a builder for the resulting string. * @param out * , the storage for a result string. * @throws IOException */ public static void reverse(UTF8StringPointable srcPtr, UTF8StringBuilder builder, GrowableArray out) throws IOException { builder.reset(out, srcPtr.getUTF8Length()); int srcStart = srcPtr.getCharStartOffset(); int srcEnd = srcPtr.getStartOffset() + srcPtr.getLength() - 1; for (int cursorIndex = srcEnd; cursorIndex >= srcStart; cursorIndex--) { if (UTF8StringUtil.isCharStart(srcPtr.bytes, cursorIndex)) { int charSize = UTF8StringUtil.charSize(srcPtr.bytes, cursorIndex); builder.appendUtf8StringPointable(srcPtr, cursorIndex, charSize); } } builder.finish(); }
@Override public boolean operateStringString(UTF8StringPointable stringp1, UTF8StringPointable stringp2) throws SystemException, IOException { return (stringp1.compareTo(stringp2) == -1); }
@Test public void test() throws Exception { UTF8StringPointable leftStrPointable1 = generateUTF8Pointable("coupon not available in store"); UTF8StringPointable rightStrPointable1 = generateUTF8Pointable("coupon is available in store"); UTF8StringPointable rightStrPointable2 = generateUTF8Pointable("coupon in store"); byte[] leftBytes1 = leftStrPointable1.getByteArray(); int leftStartOffset1 = leftStrPointable1.getStartOffset(); byte[] rightBytes1 = rightStrPointable1.getByteArray(); int rightStartOffset1 = rightStrPointable1.getStartOffset(); byte[] rightBytes2 = rightStrPointable2.getByteArray(); int rightStartOffset2 = rightStrPointable2.getStartOffset();
private void writeResult(IPointable resultPointable) throws IOException { dataOutput.writeByte(ATypeTag.SERIALIZED_STRING_TYPE_TAG); dataOutput.write(resultStrPtr.getByteArray(), 0, resultStrPtr.getLength()); resultPointable.set(resultStorage); } }
ATypeTag.SERIALIZED_STRING_TYPE_TAG); utf8Ptr.set(stringPtr.getByteArray(), stringPtr.getStartOffset() + 1, stringPtr.getLength()); int strLen = utf8Ptr.getStringLength();
private String getStringFromBytes(byte[] bytes) { if (bytes == null) { return null; } StringBuilder sb = new StringBuilder(); UTF8StringPointable.toString(sb, bytes, 0); return sb.toString(); }
/** * Write the substring before the given pattern. It will write a empty string if the matching fails. * * @param src * @param match * @param builder * @param out * @throws IOException */ public static void substrBefore(UTF8StringPointable src, UTF8StringPointable match, UTF8StringBuilder builder, GrowableArray out) throws IOException { int byteOffset = find(src, match, false); if (byteOffset < 0) { builder.reset(out, 0); builder.finish(); return; } final int srcMetaLen = src.getMetaDataLength(); builder.reset(out, byteOffset); for (int idx = 0; idx < byteOffset;) { builder.appendChar(src.charAt(srcMetaLen + idx)); idx += src.charSize(srcMetaLen + idx); } builder.finish(); }