Pro Java 7 NIO.2
Copyright 2011 by Anghel Leonard
This work is subject to copyright. All rights are reserved by the Publisher, whether the whole or part of the material is concerned, specifically the rights of translation, reprinting, reuse of illustrations, recitation, broadcasting, reproduction on microfilms or in any other physical way, and transmission or information storage and retrieval, electronic adaptation, computer software, or by similar or dissimilar methodology now known or hereafter developed. Exempted from this legal reservation are brief excerpts in connection with reviews or scholarly analysis or material supplied specifically for the purpose of being entered and executed on a computer system, for exclusive use by the purchaser of the work. Duplication of this publication or parts thereof is permitted only under the provisions of the Copyright Law of the Publisher's location, in its current version, and permission for use must always be obtained from Springer. Permissions for use may be obtained through RightsLink at the Copyright Clearance Center. Violations are liable to prosecution under the respective Copyright Law.
ISBN-13 (pbk): 978-1-4302-4011-2
ISBN-13 (electronic): 978-1-4302-4012-9
Trademarked names, logos, and images may appear in this book. Rather than use a trademark symbol with every occurrence of a trademarked name, logo, or image we use the names, logos, and images only in an editorial fashion and to the benefit of the trademark owner, with no intention of infringement of the trademark.
The use in this publication of trade names, trademarks, service marks, and similar terms, even if they are not identified as such, is not to be taken as an expression of opinion as to whether or not they are subject to proprietary rights.
While the advice and information in this book are believed to be true and accurate at the date of publication, neither the authors nor the editors nor the publisher can accept any legal responsibility for any errors or omissions that may be made. The publisher makes no warranty, express or implied, with respect to the material contained herein.
President and Publisher: Paul Manning
Lead Editor: Matthew Moodie
Technical Reviewer: Michael Turner
Editorial Board: Steve Anglin, Mark Beckner, Ewan Buckingham, Gary Cornell, Morgan Ertel, Jonathan Gennick,
Jonathan Hassell, Robert Hutchinson, Michelle Lowman, James Markham, Matthew Moodie, Jeff Olson,
Jeffrey Pepper, Douglas Pundick, Ben Renow-Clarke, Dominic Shakeshaft, Gwenan Spearing, Matt Wade,
Tom Welsh
Coordinating Editor: Corbin Collins
Copy Editor: Bill McManus, Damon Larson
Compositor: Apress Production (Christine Ricketts)
Indexer: SPI Global
Artist: SPI Global
Cover Designer: Anna Ishchenko
Distributed to the book trade worldwide by Springer Science+Business Media New York, 233 Spring Street, 6th Floor, New York, NY 10013. Phone 1-800-SPRINGER, fax (201) 348-4505, e-mail .
For information on translations, please e-mail .
Apress and friends of ED books may be purchased in bulk for academic, corporate, or promotional use. eBook versions and licenses are also available for most titles. For more information, reference our Special Bulk SaleseBook Licensing web page at www.apress.com/bulk-sales
.
Any source code or other supplementary materials referenced by the author in this text is available to readers at www.apress.com
. For detailed information about how to locate your book's source code, go to www.apress.com/source-code/
.
Contents at a Glance
Contents
What You Need to Use This Book
About the Author
Anghel Leonard is a senior Java developer with more than 12 years of experience in Java SE, Java EE, and related frameworks. He has written and published more than 30 articles about Java technologies and more than 200 tips and tricks for JavaBoutique, O'Reilly, DevX, Developer and InformIT. In addition, he wrote two books about XML and Java (one for beginners and one for advanced developers) for Albastra, a Romanian publisher, and three books for Packt: Jboss Tools 3 Developer Guide, JSF 2.0 Cookbook and JSF 2.0 Cookbook LITE. Currently, he is developing web applications using the latest Java technologies on the market (EJB 3.0, CDI, Spring, JSF, Struts, Hibernate, and more). In the past two years, he has focused on developing rich Internet applications for geographic information systems. He can be contacted at .
About the Technical Reviewer
Boris Minkin is a Senior Technical Architect at a major financial corporation. He has more than 20 years of experience working in various areas of information technology and financial services. Boris achieved his Master's Degree in Information Systems at Stevens Institute of Technology, New Jersey. His professional interests are in Internet technology, service-oriented architecture, enterprise application architecture, multi-platform distributed applications, cloud, distributed caching, Java, grid, and high performance computing. You can contact Boris at .
Acknowledgments
Thank You, God, because without You nothing is possible. Thank you to the Java 7 Project team for developing NIO.2. Thank you to the Apress team for trust in me to write this book and for the hard work you put in this project. And thank you, Octavia, my dear wife, for your love, patience, and for being next to me all the time.
Preface
This book covers all the important aspects involved in developing NIO.2-based applications. It provides clear instructions for getting the most out of NIO.2 and offers many exercises and case studies to spice up your Java 7 applications with the new I/O capabilities. You will learn to develop NIO.2 applications, beginning with simple but essential stuff and gradually moving on to complex features such as sockets and asynchronous channels.
Who This Book Is For
This book is for both experienced Java programmers who are new to Java 7 and for those who have some experience with Java 7. For the opening chapters (Chapters ), having some knowledge about a few fundamental programming concepts such as recursion, multi-threading and concurrency, Internet protocols, and network applications is essential.
What This Book Covers
This section contains a brief summary of what is covered in each chapter.
Carry out Path class operations
: Here you meet the new API for manipulating file paths; you now use the java.nio.file.Path
class to manipulate a file in any file system. In this chapter I cover such important topics as declaring Path instances and syntactic operations.
Get/set file metadata through the new java.nio.file.attribute API (including POSIX)
deeply explores each of these categories.
Manage symbolic and hard links
: An unexplored territory of Java is now revealed in NIO.2. This chapter shows you how to create, follow, and manipulate symbolic and hard links.
Deal with files and directories through the new java.nio.file.Files API
: Here you learn the most common tasks that involve files/directories, such as create, read, write, update, and more. You learn how to check file status and loop file stores, how to work with temporary files, and how to delete, copy, and move files and directories.