Java : Flushable with Examples
Flushable (Java SE 21 & JDK 21) with Examples.
You will find code examples on most Flushable methods.
Summary
final var out = new ByteArrayOutputStream();
try (final var os = new BufferedOutputStream(out)) {
final Flushable flushable = os;
os.write(10);
System.out.println(Arrays.toString(out.toByteArray())); // []
flushable.flush();
System.out.println(Arrays.toString(out.toByteArray())); // [10]
os.write(20);
System.out.println(Arrays.toString(out.toByteArray())); // [10]
flushable.flush();
System.out.println(Arrays.toString(out.toByteArray())); // [10, 20]
os.write(30);
System.out.println(Arrays.toString(out.toByteArray())); // [10, 20]
flushable.flush();
System.out.println(Arrays.toString(out.toByteArray())); // [10, 20, 30]
}
Methods
void flush ()
final var out = new ByteArrayOutputStream();
try (final var os = new BufferedOutputStream(out)) {
final Flushable flushable = os;
os.write(10);
System.out.println(Arrays.toString(out.toByteArray())); // []
flushable.flush();
System.out.println(Arrays.toString(out.toByteArray())); // [10]
os.write(20);
System.out.println(Arrays.toString(out.toByteArray())); // [10]
flushable.flush();
System.out.println(Arrays.toString(out.toByteArray())); // [10, 20]
os.write(30);
System.out.println(Arrays.toString(out.toByteArray())); // [10, 20]
flushable.flush();
System.out.println(Arrays.toString(out.toByteArray())); // [10, 20, 30]
}
Related posts
- API Examples