- java.lang.Object
-
- org.praxislive.core.Value
-
- org.praxislive.core.types.PBytes
-
public final class PBytes extends Value
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
PBytes.OutputStream
-
Nested classes/interfaces inherited from class org.praxislive.core.Value
Value.Type<T extends Value>
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description InputStream
asInputStream()
static <T extends DataObject>
Collector<T,?,PBytes>collector()
Collector to take Stream of DataObject subclasses and write into new PBytes.<T extends Serializable>
Tdeserialize(Class<T> type)
Extract serialized object from data.boolean
equals(Object obj)
Values must override the default equals method.boolean
equivalent(Value arg)
Indicates whether some other Value is equivalent to this one.<T extends DataObject>
voidforEachIn(T container, Consumer<T> consumer)
Iterate through data by decoding into provided container DataObject and calling consumer.static Optional<PBytes>
from(Value arg)
int
hashCode()
Values must override the default hashcode method.static ArgumentInfo
info()
boolean
isEmpty()
Check whether this Value is an empty value and has a zero length string representation.static PBytes
of(List<? extends DataObject> list)
Encode the provided List of DataObject subclasses into a new PBytesstatic PBytes
parse(String str)
void
read(byte[] dst)
static PBytes
serialize(Serializable obj)
Create a PBytes of the serialized form of the provided object.int
size()
<T extends DataObject>
Stream<T>streamOf(int count, Supplier<T> supplier)
Create a Stream over the data by decoding into count number of DataObjects provided by supplier.<T extends DataObject>
Stream<T>streamOf(Supplier<T> supplier)
Create a Stream over the data by decoding into DataObjects provided by supplierString
toString()
Values must override the default method to return a string representation that is immutable.<T extends DataObject>
PBytestransformIn(T container, Consumer<T> transformer)
Transform data by iterating into provided container and calling provided consumer before writing container into new PBytesstatic PBytes
valueOf(byte[] bytes)
-
-
-
Field Detail
-
EMPTY
public static final PBytes EMPTY
-
-
Method Detail
-
toString
public String toString()
Description copied from class:Value
Values must override the default method to return a string representation that is immutable.
-
read
public void read(byte[] dst)
-
asInputStream
public InputStream asInputStream()
-
size
public int size()
-
hashCode
public int hashCode()
Description copied from class:Value
Values must override the default hashcode method.
-
equals
public boolean equals(Object obj)
Description copied from class:Value
Values must override the default equals method. This method should only returntrue
if the supplied Object is of the same type as the implementing Value. Values of an unknown type should be coerced before calling this method. This method does not have to guarantee thatthis.equals(that) == this.toString().equals(that.toString())
-
equivalent
public boolean equivalent(Value arg)
Description copied from class:Value
Indicates whether some other Value is equivalent to this one. UnlikeValue.equals(java.lang.Object)
this method is not symmetric - a value of a different type might be equivalent to this without the other type considering the reverse to be true.The default implementation uses identity or String equality.
- Overrides:
equivalent
in classValue
- Parameters:
arg
- value to test for equivalence- Returns:
- true if value is equivalent to this
-
isEmpty
public boolean isEmpty()
Description copied from class:Value
Check whether this Value is an empty value and has a zero length string representation. Subclasses may wish to override this for efficiency if the String representation is lazily created.
-
deserialize
public <T extends Serializable> T deserialize(Class<T> type) throws IOException
Extract serialized object from data. Will throw an exception if this PBytes doesn't contain a valid object of the correct type.- Type Parameters:
T
-- Parameters:
type
- class of expected object- Returns:
- deserialized object
- Throws:
IOException
-
forEachIn
public <T extends DataObject> void forEachIn(T container, Consumer<T> consumer)
Iterate through data by decoding into provided container DataObject and calling consumer. Changes to the container are ignored outside of the consumer.- Type Parameters:
T
- DataObject sub-type- Parameters:
container
-consumer
-
-
transformIn
public <T extends DataObject> PBytes transformIn(T container, Consumer<T> transformer)
Transform data by iterating into provided container and calling provided consumer before writing container into new PBytes- Type Parameters:
T
- DataObject sub-type- Parameters:
container
-transformer
-- Returns:
- transformed data
-
streamOf
public <T extends DataObject> Stream<T> streamOf(Supplier<T> supplier)
Create a Stream over the data by decoding into DataObjects provided by supplier- Type Parameters:
T
-- Parameters:
supplier
- of DataObject- Returns:
- Stream of DataObject
-
streamOf
public <T extends DataObject> Stream<T> streamOf(int count, Supplier<T> supplier)
Create a Stream over the data by decoding into count number of DataObjects provided by supplier. Extra DataObjects with default values will be generated if required to reach count.- Type Parameters:
T
-- Parameters:
count
-supplier
-- Returns:
- Stream of DataObject
-
collector
public static <T extends DataObject> Collector<T,?,PBytes> collector()
Collector to take Stream of DataObject subclasses and write into new PBytes.- Type Parameters:
T
-- Returns:
- collector
-
valueOf
public static PBytes valueOf(byte[] bytes)
-
parse
public static PBytes parse(String str) throws ValueFormatException
- Throws:
ValueFormatException
-
of
public static PBytes of(List<? extends DataObject> list)
Encode the provided List of DataObject subclasses into a new PBytes- Parameters:
list
-- Returns:
- PBytes of data
-
serialize
public static PBytes serialize(Serializable obj) throws IOException
Create a PBytes of the serialized form of the provided object.- Parameters:
obj
-- Returns:
- PBytes of serialized data
- Throws:
IOException
-
info
public static ArgumentInfo info()
-
-