Class DataFormat<T>
- Type Parameters:
T- the type of the value this format carries
Four formats are the ones every desktop program exchanges: TEXT, HTML,
IMAGE and FILES. An application adds its own in two ways. of(java.lang.String, java.util.function.Function<T, byte[]>, java.util.function.Function<byte[], T>) names a
format and says how its value becomes bytes, so it can cross to another program, or to another
run of this one. inProcess carries the object itself and never leaves this process:
what a list hands another list of the same window.
Two formats are equal when their names are. Declare each once, in a constant.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final DataFormat<List<Path>> Files and directories, as a file manager copies and drags them.static final DataFormat<String> A fragment of HTML, as a word processor or a spreadsheet pastes it with its formatting.static final DataFormat<Image> A picture.static final DataFormat<String> Plain text. -
Method Summary
Modifier and TypeMethodDescriptionstatic @Nullable DataFormat<?> The format an application declared under a name withof(java.lang.String, java.util.function.Function<T, byte[]>, java.util.function.Function<byte[], T>), for a backend that finds the name among what a platform offers.decode(byte[] bytes) The bytes another program handed over as a value; for a backend.byte[]The value as the bytes another program is handed; for a backend.booleaninthashCode()static <T> DataFormat<T> Declares a format that carries the object itself.booleanbooleanname()static <T> DataFormat<T> Declares a format of the application's own, carried as bytes under a name another program can ask for too.toString()
-
Field Details
-
TEXT
Plain text. -
HTML
A fragment of HTML, as a word processor or a spreadsheet pastes it with its formatting. -
IMAGE
A picture. -
FILES
Files and directories, as a file manager copies and drags them.
-
-
Method Details
-
of
public static <T> DataFormat<T> of(String name, Function<T, byte[]> encode, Function<byte[], T> decode) Declares a format of the application's own, carried as bytes under a name another program can ask for too. From this call on, something offered under that name by anyone is listed byOffer.formats()as this format.The name is written as a media type,
application/x-acme-order: lower case, one slash, no spaces. It is the type the Linux desktops see as written, a registered clipboard format on Windows and a pasteboard type on macOS. Declaring a name again replaces the earlier declaration.- Type Parameters:
T- the type of the value- Parameters:
name- the format's nameencode- the value as bytesdecode- the bytes as a value; what it throws fails the read- Returns:
- the format
- Throws:
IllegalArgumentException- if the name is not a media type, or is one of the four standard formats'
-
inProcess
Declares a format that carries the object itself. It costs no encoding, it is offered to this process alone, and it is gone when the process ends: another program, and another run of this one, never see it.- Type Parameters:
T- the type of the value- Parameters:
name- the format's name, written asof(java.lang.String, java.util.function.Function<T, byte[]>, java.util.function.Function<byte[], T>)askstype- the class of the value, which a read is checked against- Returns:
- the format
- Throws:
IllegalArgumentException- if the name is not a media type, or is one of the four standard formats'
-
declared
The format an application declared under a name withof(java.lang.String, java.util.function.Function<T, byte[]>, java.util.function.Function<byte[], T>), for a backend that finds the name among what a platform offers.- Parameters:
name- a native type's name- Returns:
- the declared format, or null when the application declared none by that name
-
name
- Returns:
- the format's name: a media type
-
isStandard
public boolean isStandard() -
isInProcess
public boolean isInProcess()- Returns:
- whether the value is carried as the object itself, within this process only
-
encode
The value as the bytes another program is handed; for a backend.- Parameters:
value- the value- Returns:
- its bytes
- Throws:
UnsupportedOperationException- for a standard or an in-process format, whose bytes are the platform's business or do not exist
-
decode
The bytes another program handed over as a value; for a backend.- Parameters:
bytes- the bytes- Returns:
- the value
- Throws:
UnsupportedOperationException- for a standard or an in-process format
-
equals
-
hashCode
public int hashCode() -
toString
-