/** * Converts the provided String to bytes using the * UTF-8 encoding. If the input is malformed, * invalid chars are replaced by a default value. * @return ByteBuffer: bytes stores at ByteBuffer.array() * and length is ByteBuffer.limit() */ public static ByteBuffer encode(String string) throws CharacterCodingException { return encode(string, true); }
/** Set to contain the contents of a string. */ public void set(String string) { try { ByteBuffer bb = encode(string, true); bytes = bb.array(); length = bb.limit(); }catch(CharacterCodingException e) { throw new RuntimeException("Should not have happened ", e); } }
public static void writeUTF8(OutputStream out, HiveIntervalYearMonthWritable i) throws IOException { ByteBuffer b = Text.encode(i.toString()); out.write(b.array(), 0, b.limit()); }
public static void writeUTF8(OutputStream out, HiveIntervalDayTimeWritable i) throws IOException { ByteBuffer b = Text.encode(i.toString()); out.write(b.array(), 0, b.limit()); }
/** * Writes a Date in SQL date format to the output stream. * @param out * The output stream * @param d * The Date to write * @throws IOException */ public static void writeUTF8(OutputStream out, DateWritableV2 d) throws IOException { ByteBuffer b = Text.encode(d.toString()); out.write(b.array(), 0, b.limit()); }
/** Write a UTF8 encoded string to out */ public static int writeString(DataOutput out, String s) throws IOException { ByteBuffer bytes = encode(s); int length = bytes.limit(); WritableUtils.writeVInt(out, length); out.write(bytes.array(), 0, length); return length; }
/** Write a UTF8 encoded string with a maximum size to out */ public static int writeString(DataOutput out, String s, int maxLength) throws IOException { ByteBuffer bytes = encode(s); int length = bytes.limit(); if (length > maxLength) { throw new IOException("string was too long to write! Expected " + "less than or equal to " + maxLength + " bytes, but got " + length + " bytes."); } WritableUtils.writeVInt(out, length); out.write(bytes.array(), 0, length); return length; }
@Override public void writeFloat(float vf) throws IOException { beginPrimitive(); ByteBuffer b = Text.encode(String.valueOf(vf)); output.write(b.array(), 0, b.limit()); finishPrimitive(); }
@Override public void writeDouble(double v) throws IOException { beginPrimitive(); ByteBuffer b = Text.encode(String.valueOf(v)); output.write(b.array(), 0, b.limit()); finishPrimitive(); }
@Override public void writeHiveVarchar(HiveVarchar hiveVarchar) throws IOException { beginPrimitive(); ByteBuffer b = Text.encode(hiveVarchar.getValue()); LazyUtils.writeEscaped(output, b.array(), 0, b.limit(), isEscaped, escapeChar, needsEscape); finishPrimitive(); }
try { ByteBuffer src = ByteBuffer.wrap(this.bytes,0,this.length); ByteBuffer tgt = encode(what); byte b = tgt.get(); src.position(start);
@Override public void writeHiveChar(HiveChar hiveChar) throws IOException { beginPrimitive(); ByteBuffer b = Text.encode(hiveChar.getPaddedValue()); LazyUtils.writeEscaped(output, b.array(), 0, b.limit(), isEscaped, escapeChar, needsEscape); finishPrimitive(); }
private byte[] encodeTime(Timestamp timestamp) { ByteBuffer encoded; long time = timestamp.getTime(); try { String formatted = dateFormat.format(new Date(time)); encoded = Text.encode(formatted); } catch (CharacterCodingException e) { throw new RuntimeException(e); } return Arrays.copyOf(encoded.array(), encoded.limit()); }
/** * Converts the provided String to bytes using the * UTF-8 encoding. If the input is malformed, * invalid chars are replaced by a default value. * @return ByteBuffer: bytes stores at ByteBuffer.array() * and length is ByteBuffer.limit() */ public static ByteBuffer encode(String string) throws CharacterCodingException { return encode(string, true); }
/** * Converts the provided String to bytes using the * UTF-8 encoding. If the input is malformed, * invalid chars are replaced by a default value. * @return ByteBuffer: bytes stores at ByteBuffer.array() * and length is ByteBuffer.limit() */ public static ByteBuffer encode(String string) throws CharacterCodingException { return encode(string, true); }
/** Set to contain the contents of a string. */ public void set(String string) { try { ByteBuffer bb = encode(string, true); bytes = bb.array(); length = bb.limit(); }catch(CharacterCodingException e) { throw new RuntimeException("Should not have happened ", e); } }
public static void writeUTF8(OutputStream out, HiveIntervalYearMonthWritable i) throws IOException { ByteBuffer b = Text.encode(i.toString()); out.write(b.array(), 0, b.limit()); }
/** Write a UTF8 encoded string to out */ public static int writeString(DataOutput out, String s) throws IOException { ByteBuffer bytes = encode(s); int length = bytes.limit(); WritableUtils.writeVInt(out, length); out.write(bytes.array(), 0, length); return length; }
/** Write a UTF8 encoded string to out */ public static int writeString(DataOutput out, String s) throws IOException { ByteBuffer bytes = encode(s); int length = bytes.limit(); WritableUtils.writeVInt(out, length); out.write(bytes.array(), 0, length); return length; }