IO / NOTES</>↗IO05 Jan 2026
Using FileChannel.map() allows you to map a region of a file directly into memory. This creates a MappedByteBuffer, which acts like a bridge between your application’s memory and the file on disk. The operating system handles the actual reading and writing in the background, making it extremely efficient for large files. Here is how you […]
IO / NOTES</>↗IO05 Jan 2026
To use ObjectOutputStream with a Java record, you need to make the record implement the java.io.Serializable interface. One of the great things about records is that they are designed to be “data carriers,” and Java’s serialization mechanism handles them more robustly and securely than regular classes. Specifically, records are serialized using only their components (the […]
IO / NOTES</>↗IO04 Jan 2026
In a modern Java environment, “safely” means avoiding the pitfalls of standard Java Serialization, which is often vulnerable to gadget attacks and remote code execution. Here are the best practices for safe serialization and deserialization: 1. Prefer Data-Only Formats (JSON/XML) Instead of standard Java serialization, use JSON with a library like Jackson (already common in […]
IO / NOTES</>↗IO04 Jan 2026
Using ByteBuffer to process binary files is a core part of Java NIO (New I/O). It provides a more efficient way to handle raw bytes compared to traditional stream-based I/O by allowing direct interaction with memory and OS-level optimizations. Here is a guide on how to effectively use ByteBuffer for binary file processing. 1. The […]
IO / NOTES</>↗IO03 Jan 2026
Using FileChannel from the java.nio.channels package is a powerful way to perform high-performance file operations. It allows for advanced features like memory-mapped files and direct transfer between channels, which are often much faster than traditional stream-based I/O. Here are the most efficient ways to use FileChannel. 1. Fast File Copying with transferTo or transferFrom This […]
IO / NOTES</>↗IO03 Jan 2026
To use Files.probeContentType(Path path) in Java, you simply pass a Path object to the method. It returns a string representing the MIME type (e.g., image/png, text/plain) or null if the type cannot be determined. Here is a practical example of how to implement it: package org.kodejava.nio; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; public […]