public ArrayWritable readArray(ArrayWritable aw) throws IOException { if (aw == null) { aw = new ArrayWritable(TypedBytesWritable.class); } else if (!aw.getValueClass().equals(TypedBytesWritable.class)) { throw new RuntimeException("value class has to be TypedBytesWritable"); } int length = in.readVectorHeader(); Writable[] writables = new Writable[length]; for (int i = 0; i < length; i++) { writables[i] = new TypedBytesWritable(in.readRaw()); } aw.set(writables); return aw; }
/** Generate a suitable string representation. */ @Override public String toString() { return getValue().toString(); }
/** Set the typed bytes from a given Java object. */ public void setValue(Object obj) { try { ByteArrayOutputStream baos = new ByteArrayOutputStream(); TypedBytesOutput tbo = TypedBytesOutput.get(new DataOutputStream(baos)); tbo.write(obj); byte[] bytes = baos.toByteArray(); set(bytes, 0, bytes.length); } catch (IOException e) { throw new RuntimeException(e); } }
/** Get the type code embedded in the first byte. */ public Type getType() { byte[] bytes = getBytes(); if (bytes == null || bytes.length == 0) { return null; } for (Type type : Type.values()) { if (type.code == bytes[0]) { return type; } } return null; }
/** Get the type code embedded in the first byte. */ public Type getType() { byte[] bytes = get(); if (bytes == null || bytes.length == 0) { return null; } for (Type type : Type.values()) { if (type.code == bytes[0]) { return type; } } return null; }
/** Get the typed bytes as a Java object. */ public Object getValue() { try { ByteArrayInputStream bais = new ByteArrayInputStream(getBytes()); TypedBytesInput tbi = TypedBytesInput.get(new DataInputStream(bais)); Object obj = tbi.read(); return obj; } catch (IOException e) { throw new RuntimeException(e); } }
/** Get the typed bytes as a Java object. */ public Object getValue() { try { ByteArrayInputStream bais = new ByteArrayInputStream(get()); TypedBytesInput tbi = TypedBytesInput.get(new DataInputStream(bais)); Object obj = tbi.read(); return obj; } catch (IOException e) { throw new RuntimeException(e); } }
/** Get the type code embedded in the first byte. */ public Type getType() { byte[] bytes = getBytes(); if (bytes == null || bytes.length == 0) { return null; } for (Type type : Type.values()) { if (type.code == bytes[0]) { return type; } } return null; }
/** Generate a suitable string representation. */ @Override public String toString() { return getValue().toString(); }
/** Set the typed bytes from a given Java object. */ public void setValue(Object obj) { try { ByteArrayOutputStream baos = new ByteArrayOutputStream(); TypedBytesOutput tbo = TypedBytesOutput.get(new DataOutputStream(baos)); tbo.write(obj); byte[] bytes = baos.toByteArray(); set(bytes, 0, bytes.length); } catch (IOException e) { throw new RuntimeException(e); } }
public ArrayWritable readArray(ArrayWritable aw) throws IOException { if (aw == null) { aw = new ArrayWritable(TypedBytesWritable.class); } else if (!aw.getValueClass().equals(TypedBytesWritable.class)) { throw new RuntimeException("value class has to be TypedBytesWritable"); } int length = in.readVectorHeader(); Writable[] writables = new Writable[length]; for (int i = 0; i < length; i++) { writables[i] = new TypedBytesWritable(in.readRaw()); } aw.set(writables); return aw; }
/** Get the type code embedded in the first byte. */ public Type getType() { byte[] bytes = getBytes(); if (bytes == null || bytes.length == 0) { return null; } for (Type type : Type.values()) { if (type.code == bytes[0]) { return type; } } return null; }
/** Generate a suitable string representation. */ @Override public String toString() { return getValue().toString(); }
/** Set the typed bytes from a given Java object. */ public void setValue(Object obj) { try { ByteArrayOutputStream baos = new ByteArrayOutputStream(); TypedBytesOutput tbo = TypedBytesOutput.get(new DataOutputStream(baos)); tbo.write(obj); byte[] bytes = baos.toByteArray(); set(bytes, 0, bytes.length); } catch (IOException e) { throw new RuntimeException(e); } }
public ArrayWritable readArray(ArrayWritable aw) throws IOException { if (aw == null) { aw = new ArrayWritable(TypedBytesWritable.class); } else if (!aw.getValueClass().equals(TypedBytesWritable.class)) { throw new RuntimeException("value class has to be TypedBytesWritable"); } int length = in.readVectorHeader(); Writable[] writables = new Writable[length]; for (int i = 0; i < length; i++) { writables[i] = new TypedBytesWritable(in.readRaw()); } aw.set(writables); return aw; }