Nội dung
Danh sách bài học
- 01~14 phút
I/O cổ điển — InputStream, Reader, buffered wrapper
Byte stream vs char stream, decorator pattern của java.io, vì sao BufferedReader nhanh hơn FileReader hàng trăm lần. Charset và bug latent khi không specify encoding.
- 02~13 phút
Path và Files — NIO.2 thay java.io.File
Path immutable thay File, Files utility đồng nhất: readString, write, copy, move, delete với exception cụ thể. Vì sao API 1996 phải thay, và 90% task file I/O hằng ngày gói trong vài dòng.
- 03~13 phút
Duyệt thư mục và theo dõi file — walk, atomic swap, WatchService
Files.walk/find/list duyệt cây thư mục, walkFileTree visitor pattern, file attribute theo OS. Pattern atomic swap cho ghi file an toàn và WatchService theo dõi thay đổi realtime.
- 04~14 phút
Serialization — cơ chế, serialVersionUID và transient
Java native serialization hoạt động thế nào: marker interface + reflection, serialVersionUID làm version check, transient cho secret/resource, custom writeObject/readObject để encrypt và validate.
- 05~13 phút
Deserialization — lỗ hổng RCE và alternatives JSON/Protobuf
Gadget chain biến ObjectInputStream.readObject thành remote code execution — câu chuyện 'Java deserialization apocalypse' 2015. Phòng chống với ObjectInputFilter (JEP 290) và alternatives: JSON, Protobuf, Avro.
- 06~14 phút
Stream file — Files.lines, memory-mapped, channel
Xử lý file lớn stream-based với Files.lines, try-with-resources. Memory-mapped file (MappedByteBuffer) cho random access, FileChannel + Buffer cho control chi tiết. Pattern xử lý file 10GB không OOM.
- 07~30 phút
Mini-challenge: Log aggregator với NIO.2 và Stream
Bài thực hành khép lại module I/O & NIO — walk thư mục log, stream từng file, parse line, aggregate thống kê, output report CSV. Pattern production thực tế.