diff --git a/9781430240112.jpg b/9781430240112.jpg new file mode 100644 index 0000000..754c930 Binary files /dev/null and b/9781430240112.jpg differ diff --git a/LICENSE.txt b/LICENSE.txt new file mode 100644 index 0000000..dea94ce --- /dev/null +++ b/LICENSE.txt @@ -0,0 +1,27 @@ +Freeware License, some rights reserved + +Copyright (c) 2011 Anghel Leonard + +Permission is hereby granted, free of charge, to anyone obtaining a copy +of this software and associated documentation files (the "Software"), +to work with the Software within the limits of freeware distribution and fair use. +This includes the rights to use, copy, and modify the Software for personal use. +Users are also allowed and encouraged to submit corrections and modifications +to the Software for the benefit of other users. + +It is not allowed to reuse, modify, or redistribute the Software for +commercial use in any way, or for a user’s educational materials such as books +or blog articles without prior permission from the copyright holder. + +The above copyright notice and this permission notice need to be included +in all copies or substantial portions of the software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS OR APRESS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + + diff --git a/Pro Java 7 NIO.2/Chapter01/path/path_01/build.xml b/Pro Java 7 NIO.2/Chapter01/path/path_01/build.xml new file mode 100644 index 0000000..ff46948 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter01/path/path_01/build.xml @@ -0,0 +1,74 @@ + + + + + + + + + + + Builds, tests, and runs the project path_01. + + + diff --git a/Pro Java 7 NIO.2/Chapter01/path/path_01/build/built-jar.properties b/Pro Java 7 NIO.2/Chapter01/path/path_01/build/built-jar.properties new file mode 100644 index 0000000..435b081 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter01/path/path_01/build/built-jar.properties @@ -0,0 +1,4 @@ +#Sun, 16 Oct 2011 15:47:54 +0200 + + +C\:\\NIO\\path\\path_01= diff --git a/Pro Java 7 NIO.2/Chapter01/path/path_01/build/classes/.netbeans_automatic_build b/Pro Java 7 NIO.2/Chapter01/path/path_01/build/classes/.netbeans_automatic_build new file mode 100644 index 0000000..e69de29 diff --git a/Pro Java 7 NIO.2/Chapter01/path/path_01/build/classes/path_01/Main.class b/Pro Java 7 NIO.2/Chapter01/path/path_01/build/classes/path_01/Main.class new file mode 100644 index 0000000..e3e2c57 Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter01/path/path_01/build/classes/path_01/Main.class differ diff --git a/Pro Java 7 NIO.2/Chapter01/path/path_01/dist/README.TXT b/Pro Java 7 NIO.2/Chapter01/path/path_01/dist/README.TXT new file mode 100644 index 0000000..9a8fc57 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter01/path/path_01/dist/README.TXT @@ -0,0 +1,33 @@ +======================== +BUILD OUTPUT DESCRIPTION +======================== + +When you build an Java application project that has a main class, the IDE +automatically copies all of the JAR +files on the projects classpath to your projects dist/lib folder. The IDE +also adds each of the JAR files to the Class-Path element in the application +JAR files manifest file (MANIFEST.MF). + +To run the project from the command line, go to the dist folder and +type the following: + +java -jar "path_01.jar" + +To distribute this project, zip up the dist folder (including the lib folder) +and distribute the ZIP file. + +Notes: + +* If two JAR files on the project classpath have the same name, only the first +JAR file is copied to the lib folder. +* Only JAR files are copied to the lib folder. +If the classpath contains other types of files or folders, none of the +classpath elements are copied to the lib folder. In such a case, +you need to copy the classpath elements to the lib folder manually after the build. +* If a library on the projects classpath also has a Class-Path element +specified in the manifest,the content of the Class-Path element has to be on +the projects runtime path. +* To set a main class in a standard Java project, right-click the project node +in the Projects window and choose Properties. Then click Run and enter the +class name in the Main Class field. Alternatively, you can manually type the +class name in the manifest Main-Class element. diff --git a/Pro Java 7 NIO.2/Chapter01/path/path_01/dist/path_01.jar b/Pro Java 7 NIO.2/Chapter01/path/path_01/dist/path_01.jar new file mode 100644 index 0000000..5b30f68 Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter01/path/path_01/dist/path_01.jar differ diff --git a/Pro Java 7 NIO.2/Chapter01/path/path_01/lib/CopyLibs/org-netbeans-modules-java-j2seproject-copylibstask.jar b/Pro Java 7 NIO.2/Chapter01/path/path_01/lib/CopyLibs/org-netbeans-modules-java-j2seproject-copylibstask.jar new file mode 100644 index 0000000..5ee71d2 Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter01/path/path_01/lib/CopyLibs/org-netbeans-modules-java-j2seproject-copylibstask.jar differ diff --git a/Pro Java 7 NIO.2/Chapter01/path/path_01/lib/junit/junit-3.8.2-api.zip b/Pro Java 7 NIO.2/Chapter01/path/path_01/lib/junit/junit-3.8.2-api.zip new file mode 100644 index 0000000..6d792fd Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter01/path/path_01/lib/junit/junit-3.8.2-api.zip differ diff --git a/Pro Java 7 NIO.2/Chapter01/path/path_01/lib/junit/junit-3.8.2.jar b/Pro Java 7 NIO.2/Chapter01/path/path_01/lib/junit/junit-3.8.2.jar new file mode 100644 index 0000000..d835872 Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter01/path/path_01/lib/junit/junit-3.8.2.jar differ diff --git a/Pro Java 7 NIO.2/Chapter01/path/path_01/lib/junit_4/junit-4.5-api.zip b/Pro Java 7 NIO.2/Chapter01/path/path_01/lib/junit_4/junit-4.5-api.zip new file mode 100644 index 0000000..5748c44 Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter01/path/path_01/lib/junit_4/junit-4.5-api.zip differ diff --git a/Pro Java 7 NIO.2/Chapter01/path/path_01/lib/junit_4/junit-4.5-src.jar b/Pro Java 7 NIO.2/Chapter01/path/path_01/lib/junit_4/junit-4.5-src.jar new file mode 100644 index 0000000..18774a5 Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter01/path/path_01/lib/junit_4/junit-4.5-src.jar differ diff --git a/Pro Java 7 NIO.2/Chapter01/path/path_01/lib/junit_4/junit-4.5.jar b/Pro Java 7 NIO.2/Chapter01/path/path_01/lib/junit_4/junit-4.5.jar new file mode 100644 index 0000000..83f8bc7 Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter01/path/path_01/lib/junit_4/junit-4.5.jar differ diff --git a/Pro Java 7 NIO.2/Chapter01/path/path_01/lib/nblibraries.properties b/Pro Java 7 NIO.2/Chapter01/path/path_01/lib/nblibraries.properties new file mode 100644 index 0000000..9137b06 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter01/path/path_01/lib/nblibraries.properties @@ -0,0 +1,12 @@ +libs.CopyLibs.classpath=\ + ${base}/CopyLibs/org-netbeans-modules-java-j2seproject-copylibstask.jar +libs.junit.classpath=\ + ${base}/junit/junit-3.8.2.jar +libs.junit.javadoc=\ + ${base}/junit/junit-3.8.2-api.zip +libs.junit_4.classpath=\ + ${base}/junit_4/junit-4.5.jar +libs.junit_4.javadoc=\ + ${base}/junit_4/junit-4.5-api.zip +libs.junit_4.src=\ + ${base}/junit_4/junit-4.5-src.jar diff --git a/Pro Java 7 NIO.2/Chapter01/path/path_01/manifest.mf b/Pro Java 7 NIO.2/Chapter01/path/path_01/manifest.mf new file mode 100644 index 0000000..328e8e5 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter01/path/path_01/manifest.mf @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +X-COMMENT: Main-Class will be added automatically by build + diff --git a/Pro Java 7 NIO.2/Chapter01/path/path_01/nbproject/build-impl.xml b/Pro Java 7 NIO.2/Chapter01/path/path_01/nbproject/build-impl.xml new file mode 100644 index 0000000..7060e35 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter01/path/path_01/nbproject/build-impl.xml @@ -0,0 +1,1066 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set src.dir + Must set test.src.dir + Must set build.dir + Must set dist.dir + Must set build.classes.dir + Must set dist.javadoc.dir + Must set build.test.classes.dir + Must set build.test.results.dir + Must set build.classes.excludes + Must set dist.jar + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set JVM to use for profiling in profiler.info.jvm + Must set profiler agent JVM arguments in profiler.info.jvmargs.agent + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + + + + + + java -cp "${run.classpath.with.dist.jar}" ${main.class} + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + java -jar "${dist.jar.resolved}" + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set run.class + + + + Must select one file in the IDE or set run.class + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set debug.class + + + + + Must select one file in the IDE or set debug.class + + + + + Must set fix.includes + + + + + + + + + + + + + + + + + Must select one file in the IDE or set profile.class + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + Some tests failed; see details above. + + + + + + + + + Must select some files in the IDE or set test.includes + + + + Some tests failed; see details above. + + + + + Must select one file in the IDE or set test.class + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Pro Java 7 NIO.2/Chapter01/path/path_01/nbproject/genfiles.properties b/Pro Java 7 NIO.2/Chapter01/path/path_01/nbproject/genfiles.properties new file mode 100644 index 0000000..9a87fd3 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter01/path/path_01/nbproject/genfiles.properties @@ -0,0 +1,8 @@ +build.xml.data.CRC32=5e76cd9e +build.xml.script.CRC32=3f512728 +build.xml.stylesheet.CRC32=28e38971@1.43.1.45 +# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. +# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. +nbproject/build-impl.xml.data.CRC32=5e76cd9e +nbproject/build-impl.xml.script.CRC32=09d1d1ca +nbproject/build-impl.xml.stylesheet.CRC32=0c01fd8e@1.43.1.45 diff --git a/Pro Java 7 NIO.2/Chapter01/path/path_01/nbproject/private/config.properties b/Pro Java 7 NIO.2/Chapter01/path/path_01/nbproject/private/config.properties new file mode 100644 index 0000000..e69de29 diff --git a/Pro Java 7 NIO.2/Chapter01/path/path_01/nbproject/private/private.properties b/Pro Java 7 NIO.2/Chapter01/path/path_01/nbproject/private/private.properties new file mode 100644 index 0000000..a5ab360 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter01/path/path_01/nbproject/private/private.properties @@ -0,0 +1,6 @@ +compile.on.save=true +do.depend=false +do.jar=true +javac.debug=true +javadoc.preview=true +user.properties.file=C:\\Users\\Leo\\.netbeans\\7.0\\build.properties diff --git a/Pro Java 7 NIO.2/Chapter01/path/path_01/nbproject/private/private.xml b/Pro Java 7 NIO.2/Chapter01/path/path_01/nbproject/private/private.xml new file mode 100644 index 0000000..c1f155a --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter01/path/path_01/nbproject/private/private.xml @@ -0,0 +1,4 @@ + + + + diff --git a/Pro Java 7 NIO.2/Chapter01/path/path_01/nbproject/project.properties b/Pro Java 7 NIO.2/Chapter01/path/path_01/nbproject/project.properties new file mode 100644 index 0000000..c5c6f13 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter01/path/path_01/nbproject/project.properties @@ -0,0 +1,82 @@ +annotation.processing.enabled=true +annotation.processing.enabled.in.editor=false +annotation.processing.run.all.processors=true +annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output +application.title=path_01 +application.vendor=Leo +build.classes.dir=${build.dir}/classes +build.classes.excludes=**/*.java,**/*.form +# This directory is removed when the project is cleaned: +build.dir=build +build.generated.dir=${build.dir}/generated +build.generated.sources.dir=${build.dir}/generated-sources +# Only compile against the classpath explicitly listed here: +build.sysclasspath=ignore +build.test.classes.dir=${build.dir}/test/classes +build.test.results.dir=${build.dir}/test/results +# Uncomment to specify the preferred debugger connection transport: +#debug.transport=dt_socket +debug.classpath=\ + ${run.classpath} +debug.test.classpath=\ + ${run.test.classpath} +# This directory is removed when the project is cleaned: +dist.dir=dist +dist.jar=${dist.dir}/path_01.jar +dist.javadoc.dir=${dist.dir}/javadoc +endorsed.classpath= +excludes= +includes=** +jar.archive.disabled=${jnlp.enabled} +jar.compress=false +jar.index=${jnlp.enabled} +javac.classpath= +# Space-separated list of extra javac options +javac.compilerargs= +javac.deprecation=false +javac.processorpath=\ + ${javac.classpath} +javac.source=1.7 +javac.target=1.7 +javac.test.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir}:\ + ${libs.junit.classpath}:\ + ${libs.junit_4.classpath} +javac.test.processorpath=\ + ${javac.test.classpath} +javadoc.additionalparam= +javadoc.author=false +javadoc.encoding=${source.encoding} +javadoc.noindex=false +javadoc.nonavbar=false +javadoc.notree=false +javadoc.private=false +javadoc.splitindex=true +javadoc.use=true +javadoc.version=false +javadoc.windowtitle= +jnlp.codebase.type=no.codebase +jnlp.descriptor=application +jnlp.enabled=false +jnlp.mixed.code=defaut +jnlp.offline-allowed=false +jnlp.signed=false +main.class=path_01.Main +manifest.file=manifest.mf +meta.inf.dir=${src.dir}/META-INF +mkdist.disabled=false +platform.active=default_platform +run.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +# Space-separated list of JVM arguments used when running the project +# (you may also define separate properties like run-sys-prop.name=value instead of -Dname=value +# or test-sys-prop.name=value to set system properties for unit tests): +run.jvmargs= +run.test.classpath=\ + ${javac.test.classpath}:\ + ${build.test.classes.dir} +source.encoding=UTF-8 +src.dir=src +test.src.dir=test diff --git a/Pro Java 7 NIO.2/Chapter01/path/path_01/nbproject/project.xml b/Pro Java 7 NIO.2/Chapter01/path/path_01/nbproject/project.xml new file mode 100644 index 0000000..5bc4175 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter01/path/path_01/nbproject/project.xml @@ -0,0 +1,18 @@ + + + org.netbeans.modules.java.j2seproject + + + path_01 + + + + + + + + + .\lib\nblibraries.properties + + + diff --git a/Pro Java 7 NIO.2/Chapter01/path/path_01/src/path_01/Main.java b/Pro Java 7 NIO.2/Chapter01/path/path_01/src/path_01/Main.java new file mode 100644 index 0000000..67ffc70 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter01/path/path_01/src/path_01/Main.java @@ -0,0 +1,44 @@ +package path_01; + +import java.net.URI; +import java.nio.file.FileSystems; +import java.nio.file.Path; +import java.nio.file.Paths; + +/** + * + * @author Apress + */ +public class Main { + + public static void main(String[] args) { + + //define a path relative to root, C:/, D:/ etc + Path path01 = Paths.get("rafaelnadal/tournaments/2009/BNP.txt"); + Path path02 = Paths.get("/rafaelnadal", "tournaments/2009/BNP.txt"); + Path path03 = FileSystems.getDefault().getPath("/rafaelnadal/tournaments/2009", "BNP.txt"); + Path path04 = FileSystems.getDefault().getPath("/rafaelnadal/tournaments/2009/BNP.txt"); + Path path05 = Paths.get(URI.create("file:///rafaelnadal/tournaments/2009/BNP.txt")); + + //define a path relative to current folder + Path path06 = Paths.get("rafaelnadal/tournaments/2009/BNP.txt"); + Path path07 = Paths.get("rafaelnadal", "tournaments/2009/BNP.txt"); + Path path08 = FileSystems.getDefault().getPath("rafaelnadal/tournaments/2009", "BNP.txt"); + Path path09 = FileSystems.getDefault().getPath("rafaelnadal/tournaments/2009/BNP.txt"); + + //define an absolute path + Path path10 = Paths.get("C:/rafaelnadal/tournaments/2009", "BNP.txt"); + Path path11 = Paths.get("C:", "rafaelnadal/tournaments/2009", "BNP.txt"); + Path path12 = Paths.get("C:", "rafaelnadal", "tournaments", "2009", "BNP.txt"); + Path path13 = Paths.get("C:/rafaelnadal/tournaments/2009/BNP.txt"); + Path path14 = Paths.get(System.getProperty("user.home"), "downloads", "game.exe"); + Path path15 = Paths.get(URI.create("file:///C:/rafaelnadal/tournaments/2009/BNP.txt")); + + //define paths using "." and ".." notations + Path path16 = FileSystems.getDefault().getPath("/rafaelnadal/tournaments/./2009", "BNP.txt").normalize(); + Path path17 = Paths.get("C:/rafaelnadal/tournaments/2009/dummy/../BNP.txt").normalize(); + Path path18 = Paths.get("C:/rafaelnadal/tournaments/./2009/dummy/../BNP.txt").normalize(); + + System.out.println("All Paths were successfully defined!"); + } +} diff --git a/Pro Java 7 NIO.2/Chapter01/path/path_02/build.xml b/Pro Java 7 NIO.2/Chapter01/path/path_02/build.xml new file mode 100644 index 0000000..659bc5c --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter01/path/path_02/build.xml @@ -0,0 +1,74 @@ + + + + + + + + + + + Builds, tests, and runs the project path_02. + + + diff --git a/Pro Java 7 NIO.2/Chapter01/path/path_02/build/built-jar.properties b/Pro Java 7 NIO.2/Chapter01/path/path_02/build/built-jar.properties new file mode 100644 index 0000000..1e19831 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter01/path/path_02/build/built-jar.properties @@ -0,0 +1,4 @@ +#Sun, 16 Oct 2011 15:51:41 +0200 + + +C\:\\NIO\\path\\path_02= diff --git a/Pro Java 7 NIO.2/Chapter01/path/path_02/build/classes/path_02/Main.class b/Pro Java 7 NIO.2/Chapter01/path/path_02/build/classes/path_02/Main.class new file mode 100644 index 0000000..49bbed5 Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter01/path/path_02/build/classes/path_02/Main.class differ diff --git a/Pro Java 7 NIO.2/Chapter01/path/path_02/dist/README.TXT b/Pro Java 7 NIO.2/Chapter01/path/path_02/dist/README.TXT new file mode 100644 index 0000000..5c486d6 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter01/path/path_02/dist/README.TXT @@ -0,0 +1,33 @@ +======================== +BUILD OUTPUT DESCRIPTION +======================== + +When you build an Java application project that has a main class, the IDE +automatically copies all of the JAR +files on the projects classpath to your projects dist/lib folder. The IDE +also adds each of the JAR files to the Class-Path element in the application +JAR files manifest file (MANIFEST.MF). + +To run the project from the command line, go to the dist folder and +type the following: + +java -jar "path_02.jar" + +To distribute this project, zip up the dist folder (including the lib folder) +and distribute the ZIP file. + +Notes: + +* If two JAR files on the project classpath have the same name, only the first +JAR file is copied to the lib folder. +* Only JAR files are copied to the lib folder. +If the classpath contains other types of files or folders, none of the +classpath elements are copied to the lib folder. In such a case, +you need to copy the classpath elements to the lib folder manually after the build. +* If a library on the projects classpath also has a Class-Path element +specified in the manifest,the content of the Class-Path element has to be on +the projects runtime path. +* To set a main class in a standard Java project, right-click the project node +in the Projects window and choose Properties. Then click Run and enter the +class name in the Main Class field. Alternatively, you can manually type the +class name in the manifest Main-Class element. diff --git a/Pro Java 7 NIO.2/Chapter01/path/path_02/dist/path_02.jar b/Pro Java 7 NIO.2/Chapter01/path/path_02/dist/path_02.jar new file mode 100644 index 0000000..befb794 Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter01/path/path_02/dist/path_02.jar differ diff --git a/Pro Java 7 NIO.2/Chapter01/path/path_02/lib/CopyLibs/org-netbeans-modules-java-j2seproject-copylibstask.jar b/Pro Java 7 NIO.2/Chapter01/path/path_02/lib/CopyLibs/org-netbeans-modules-java-j2seproject-copylibstask.jar new file mode 100644 index 0000000..5ee71d2 Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter01/path/path_02/lib/CopyLibs/org-netbeans-modules-java-j2seproject-copylibstask.jar differ diff --git a/Pro Java 7 NIO.2/Chapter01/path/path_02/lib/junit/junit-3.8.2-api.zip b/Pro Java 7 NIO.2/Chapter01/path/path_02/lib/junit/junit-3.8.2-api.zip new file mode 100644 index 0000000..6d792fd Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter01/path/path_02/lib/junit/junit-3.8.2-api.zip differ diff --git a/Pro Java 7 NIO.2/Chapter01/path/path_02/lib/junit/junit-3.8.2.jar b/Pro Java 7 NIO.2/Chapter01/path/path_02/lib/junit/junit-3.8.2.jar new file mode 100644 index 0000000..d835872 Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter01/path/path_02/lib/junit/junit-3.8.2.jar differ diff --git a/Pro Java 7 NIO.2/Chapter01/path/path_02/lib/junit_4/junit-4.5-api.zip b/Pro Java 7 NIO.2/Chapter01/path/path_02/lib/junit_4/junit-4.5-api.zip new file mode 100644 index 0000000..5748c44 Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter01/path/path_02/lib/junit_4/junit-4.5-api.zip differ diff --git a/Pro Java 7 NIO.2/Chapter01/path/path_02/lib/junit_4/junit-4.5-src.jar b/Pro Java 7 NIO.2/Chapter01/path/path_02/lib/junit_4/junit-4.5-src.jar new file mode 100644 index 0000000..18774a5 Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter01/path/path_02/lib/junit_4/junit-4.5-src.jar differ diff --git a/Pro Java 7 NIO.2/Chapter01/path/path_02/lib/junit_4/junit-4.5.jar b/Pro Java 7 NIO.2/Chapter01/path/path_02/lib/junit_4/junit-4.5.jar new file mode 100644 index 0000000..83f8bc7 Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter01/path/path_02/lib/junit_4/junit-4.5.jar differ diff --git a/Pro Java 7 NIO.2/Chapter01/path/path_02/lib/nblibraries.properties b/Pro Java 7 NIO.2/Chapter01/path/path_02/lib/nblibraries.properties new file mode 100644 index 0000000..9137b06 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter01/path/path_02/lib/nblibraries.properties @@ -0,0 +1,12 @@ +libs.CopyLibs.classpath=\ + ${base}/CopyLibs/org-netbeans-modules-java-j2seproject-copylibstask.jar +libs.junit.classpath=\ + ${base}/junit/junit-3.8.2.jar +libs.junit.javadoc=\ + ${base}/junit/junit-3.8.2-api.zip +libs.junit_4.classpath=\ + ${base}/junit_4/junit-4.5.jar +libs.junit_4.javadoc=\ + ${base}/junit_4/junit-4.5-api.zip +libs.junit_4.src=\ + ${base}/junit_4/junit-4.5-src.jar diff --git a/Pro Java 7 NIO.2/Chapter01/path/path_02/manifest.mf b/Pro Java 7 NIO.2/Chapter01/path/path_02/manifest.mf new file mode 100644 index 0000000..328e8e5 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter01/path/path_02/manifest.mf @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +X-COMMENT: Main-Class will be added automatically by build + diff --git a/Pro Java 7 NIO.2/Chapter01/path/path_02/nbproject/build-impl.xml b/Pro Java 7 NIO.2/Chapter01/path/path_02/nbproject/build-impl.xml new file mode 100644 index 0000000..6aae56a --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter01/path/path_02/nbproject/build-impl.xml @@ -0,0 +1,1099 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set platform.home + Must set platform.bootcp + Must set platform.java + Must set platform.javac + + The J2SE Platform is not correctly set up. + Your active platform is: ${platform.active}, but the corresponding property "platforms.${platform.active}.home" is not found in the project's properties files. + Either open the project in the IDE and setup the Platform with the same name or add it manually. + For example like this: + ant -Duser.properties.file=<path_to_property_file> jar (where you put the property "platforms.${platform.active}.home" in a .properties file) + or ant -Dplatforms.${platform.active}.home=<path_to_JDK_home> jar (where no properties file is used) + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set src.dir + Must set test.src.dir + Must set build.dir + Must set dist.dir + Must set build.classes.dir + Must set dist.javadoc.dir + Must set build.test.classes.dir + Must set build.test.results.dir + Must set build.classes.excludes + Must set dist.jar + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set JVM to use for profiling in profiler.info.jvm + Must set profiler agent JVM arguments in profiler.info.jvmargs.agent + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + + + + + + ${platform.java} -cp "${run.classpath.with.dist.jar}" ${main.class} + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + ${platform.java} -jar "${dist.jar.resolved}" + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set run.class + + + + Must select one file in the IDE or set run.class + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set debug.class + + + + + Must select one file in the IDE or set debug.class + + + + + Must set fix.includes + + + + + + + + + + + + + + + + + Must select one file in the IDE or set profile.class + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + Some tests failed; see details above. + + + + + + + + + Must select some files in the IDE or set test.includes + + + + Some tests failed; see details above. + + + + + Must select one file in the IDE or set test.class + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Pro Java 7 NIO.2/Chapter01/path/path_02/nbproject/genfiles.properties b/Pro Java 7 NIO.2/Chapter01/path/path_02/nbproject/genfiles.properties new file mode 100644 index 0000000..891e127 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter01/path/path_02/nbproject/genfiles.properties @@ -0,0 +1,8 @@ +build.xml.data.CRC32=0276ecd4 +build.xml.script.CRC32=2235eced +build.xml.stylesheet.CRC32=28e38971@1.38.2.45 +# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. +# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. +nbproject/build-impl.xml.data.CRC32=0276ecd4 +nbproject/build-impl.xml.script.CRC32=569f0147 +nbproject/build-impl.xml.stylesheet.CRC32=0c01fd8e@1.43.1.45 diff --git a/Pro Java 7 NIO.2/Chapter01/path/path_02/nbproject/private/config.properties b/Pro Java 7 NIO.2/Chapter01/path/path_02/nbproject/private/config.properties new file mode 100644 index 0000000..e69de29 diff --git a/Pro Java 7 NIO.2/Chapter01/path/path_02/nbproject/private/private.properties b/Pro Java 7 NIO.2/Chapter01/path/path_02/nbproject/private/private.properties new file mode 100644 index 0000000..a5ab360 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter01/path/path_02/nbproject/private/private.properties @@ -0,0 +1,6 @@ +compile.on.save=true +do.depend=false +do.jar=true +javac.debug=true +javadoc.preview=true +user.properties.file=C:\\Users\\Leo\\.netbeans\\7.0\\build.properties diff --git a/Pro Java 7 NIO.2/Chapter01/path/path_02/nbproject/private/private.xml b/Pro Java 7 NIO.2/Chapter01/path/path_02/nbproject/private/private.xml new file mode 100644 index 0000000..c1f155a --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter01/path/path_02/nbproject/private/private.xml @@ -0,0 +1,4 @@ + + + + diff --git a/Pro Java 7 NIO.2/Chapter01/path/path_02/nbproject/project.properties b/Pro Java 7 NIO.2/Chapter01/path/path_02/nbproject/project.properties new file mode 100644 index 0000000..d313d69 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter01/path/path_02/nbproject/project.properties @@ -0,0 +1,74 @@ +annotation.processing.enabled=true +annotation.processing.enabled.in.editor=false +annotation.processing.run.all.processors=true +annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output +application.title=path_02 +application.vendor=Leo +build.classes.dir=${build.dir}/classes +build.classes.excludes=**/*.java,**/*.form +# This directory is removed when the project is cleaned: +build.dir=build +build.generated.dir=${build.dir}/generated +build.generated.sources.dir=${build.dir}/generated-sources +# Only compile against the classpath explicitly listed here: +build.sysclasspath=ignore +build.test.classes.dir=${build.dir}/test/classes +build.test.results.dir=${build.dir}/test/results +# Uncomment to specify the preferred debugger connection transport: +#debug.transport=dt_socket +debug.classpath=\ + ${run.classpath} +debug.test.classpath=\ + ${run.test.classpath} +# This directory is removed when the project is cleaned: +dist.dir=dist +dist.jar=${dist.dir}/path_02.jar +dist.javadoc.dir=${dist.dir}/javadoc +endorsed.classpath= +excludes= +includes=** +jar.compress=false +javac.classpath= +# Space-separated list of extra javac options +javac.compilerargs= +javac.deprecation=false +javac.processorpath=\ + ${javac.classpath} +javac.source=1.7 +javac.target=1.7 +javac.test.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir}:\ + ${libs.junit.classpath}:\ + ${libs.junit_4.classpath} +javac.test.processorpath=\ + ${javac.test.classpath} +javadoc.additionalparam= +javadoc.author=false +javadoc.encoding=${source.encoding} +javadoc.noindex=false +javadoc.nonavbar=false +javadoc.notree=false +javadoc.private=false +javadoc.splitindex=true +javadoc.use=true +javadoc.version=false +javadoc.windowtitle= +main.class=path_02.Main +manifest.file=manifest.mf +meta.inf.dir=${src.dir}/META-INF +mkdist.disabled=false +platform.active=JDK_1.7 +run.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +# Space-separated list of JVM arguments used when running the project +# (you may also define separate properties like run-sys-prop.name=value instead of -Dname=value +# or test-sys-prop.name=value to set system properties for unit tests): +run.jvmargs= +run.test.classpath=\ + ${javac.test.classpath}:\ + ${build.test.classes.dir} +source.encoding=UTF-8 +src.dir=src +test.src.dir=test diff --git a/Pro Java 7 NIO.2/Chapter01/path/path_02/nbproject/project.xml b/Pro Java 7 NIO.2/Chapter01/path/path_02/nbproject/project.xml new file mode 100644 index 0000000..49083ea --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter01/path/path_02/nbproject/project.xml @@ -0,0 +1,19 @@ + + + org.netbeans.modules.java.j2seproject + + + path_02 + + + + + + + + + + .\lib\nblibraries.properties + + + diff --git a/Pro Java 7 NIO.2/Chapter01/path/path_02/src/path_02/Main.java b/Pro Java 7 NIO.2/Chapter01/path/path_02/src/path_02/Main.java new file mode 100644 index 0000000..f97b15d --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter01/path/path_02/src/path_02/Main.java @@ -0,0 +1,25 @@ +package path_02; + +import java.nio.file.Path; +import java.nio.file.Paths; + +/** + * + * @author Apress + */ +public class Main { + + public static void main(String[] args) { + + Path path = Paths.get("C:", "rafaelnadal/tournaments/2009", "BNP.txt"); + + System.out.println("The file/directory indicated by path: " + path.getFileName()); + System.out.println("Root of this path: " + path.getRoot()); + System.out.println("Parent: " + path.getParent()); + System.out.println("Number of name elements is path: " + path.getNameCount()); + for (int i = 0; i < path.getNameCount(); i++) { + System.out.println("Name element " + i + " is: " + path.getName(i)); + } + System.out.println("Subpath (0,3): " + path.subpath(0, 3)); + } +} diff --git a/Pro Java 7 NIO.2/Chapter01/path/path_03/build.xml b/Pro Java 7 NIO.2/Chapter01/path/path_03/build.xml new file mode 100644 index 0000000..5658fc7 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter01/path/path_03/build.xml @@ -0,0 +1,74 @@ + + + + + + + + + + + Builds, tests, and runs the project path_03. + + + diff --git a/Pro Java 7 NIO.2/Chapter01/path/path_03/build/built-jar.properties b/Pro Java 7 NIO.2/Chapter01/path/path_03/build/built-jar.properties new file mode 100644 index 0000000..3a71a6a --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter01/path/path_03/build/built-jar.properties @@ -0,0 +1,4 @@ +#Sun, 16 Oct 2011 15:54:43 +0200 + + +C\:\\NIO\\path\\path_03= diff --git a/Pro Java 7 NIO.2/Chapter01/path/path_03/build/classes/.netbeans_automatic_build b/Pro Java 7 NIO.2/Chapter01/path/path_03/build/classes/.netbeans_automatic_build new file mode 100644 index 0000000..e69de29 diff --git a/Pro Java 7 NIO.2/Chapter01/path/path_03/build/classes/path_03/Main.class b/Pro Java 7 NIO.2/Chapter01/path/path_03/build/classes/path_03/Main.class new file mode 100644 index 0000000..243953d Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter01/path/path_03/build/classes/path_03/Main.class differ diff --git a/Pro Java 7 NIO.2/Chapter01/path/path_03/dist/README.TXT b/Pro Java 7 NIO.2/Chapter01/path/path_03/dist/README.TXT new file mode 100644 index 0000000..856ff43 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter01/path/path_03/dist/README.TXT @@ -0,0 +1,33 @@ +======================== +BUILD OUTPUT DESCRIPTION +======================== + +When you build an Java application project that has a main class, the IDE +automatically copies all of the JAR +files on the projects classpath to your projects dist/lib folder. The IDE +also adds each of the JAR files to the Class-Path element in the application +JAR files manifest file (MANIFEST.MF). + +To run the project from the command line, go to the dist folder and +type the following: + +java -jar "path_03.jar" + +To distribute this project, zip up the dist folder (including the lib folder) +and distribute the ZIP file. + +Notes: + +* If two JAR files on the project classpath have the same name, only the first +JAR file is copied to the lib folder. +* Only JAR files are copied to the lib folder. +If the classpath contains other types of files or folders, none of the +classpath elements are copied to the lib folder. In such a case, +you need to copy the classpath elements to the lib folder manually after the build. +* If a library on the projects classpath also has a Class-Path element +specified in the manifest,the content of the Class-Path element has to be on +the projects runtime path. +* To set a main class in a standard Java project, right-click the project node +in the Projects window and choose Properties. Then click Run and enter the +class name in the Main Class field. Alternatively, you can manually type the +class name in the manifest Main-Class element. diff --git a/Pro Java 7 NIO.2/Chapter01/path/path_03/dist/path_03.jar b/Pro Java 7 NIO.2/Chapter01/path/path_03/dist/path_03.jar new file mode 100644 index 0000000..a21d416 Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter01/path/path_03/dist/path_03.jar differ diff --git a/Pro Java 7 NIO.2/Chapter01/path/path_03/lib/CopyLibs/org-netbeans-modules-java-j2seproject-copylibstask.jar b/Pro Java 7 NIO.2/Chapter01/path/path_03/lib/CopyLibs/org-netbeans-modules-java-j2seproject-copylibstask.jar new file mode 100644 index 0000000..5ee71d2 Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter01/path/path_03/lib/CopyLibs/org-netbeans-modules-java-j2seproject-copylibstask.jar differ diff --git a/Pro Java 7 NIO.2/Chapter01/path/path_03/lib/junit/junit-3.8.2-api.zip b/Pro Java 7 NIO.2/Chapter01/path/path_03/lib/junit/junit-3.8.2-api.zip new file mode 100644 index 0000000..6d792fd Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter01/path/path_03/lib/junit/junit-3.8.2-api.zip differ diff --git a/Pro Java 7 NIO.2/Chapter01/path/path_03/lib/junit/junit-3.8.2.jar b/Pro Java 7 NIO.2/Chapter01/path/path_03/lib/junit/junit-3.8.2.jar new file mode 100644 index 0000000..d835872 Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter01/path/path_03/lib/junit/junit-3.8.2.jar differ diff --git a/Pro Java 7 NIO.2/Chapter01/path/path_03/lib/junit_4/junit-4.5-api.zip b/Pro Java 7 NIO.2/Chapter01/path/path_03/lib/junit_4/junit-4.5-api.zip new file mode 100644 index 0000000..5748c44 Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter01/path/path_03/lib/junit_4/junit-4.5-api.zip differ diff --git a/Pro Java 7 NIO.2/Chapter01/path/path_03/lib/junit_4/junit-4.5-src.jar b/Pro Java 7 NIO.2/Chapter01/path/path_03/lib/junit_4/junit-4.5-src.jar new file mode 100644 index 0000000..18774a5 Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter01/path/path_03/lib/junit_4/junit-4.5-src.jar differ diff --git a/Pro Java 7 NIO.2/Chapter01/path/path_03/lib/junit_4/junit-4.5.jar b/Pro Java 7 NIO.2/Chapter01/path/path_03/lib/junit_4/junit-4.5.jar new file mode 100644 index 0000000..83f8bc7 Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter01/path/path_03/lib/junit_4/junit-4.5.jar differ diff --git a/Pro Java 7 NIO.2/Chapter01/path/path_03/lib/nblibraries.properties b/Pro Java 7 NIO.2/Chapter01/path/path_03/lib/nblibraries.properties new file mode 100644 index 0000000..9137b06 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter01/path/path_03/lib/nblibraries.properties @@ -0,0 +1,12 @@ +libs.CopyLibs.classpath=\ + ${base}/CopyLibs/org-netbeans-modules-java-j2seproject-copylibstask.jar +libs.junit.classpath=\ + ${base}/junit/junit-3.8.2.jar +libs.junit.javadoc=\ + ${base}/junit/junit-3.8.2-api.zip +libs.junit_4.classpath=\ + ${base}/junit_4/junit-4.5.jar +libs.junit_4.javadoc=\ + ${base}/junit_4/junit-4.5-api.zip +libs.junit_4.src=\ + ${base}/junit_4/junit-4.5-src.jar diff --git a/Pro Java 7 NIO.2/Chapter01/path/path_03/manifest.mf b/Pro Java 7 NIO.2/Chapter01/path/path_03/manifest.mf new file mode 100644 index 0000000..328e8e5 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter01/path/path_03/manifest.mf @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +X-COMMENT: Main-Class will be added automatically by build + diff --git a/Pro Java 7 NIO.2/Chapter01/path/path_03/nbproject/build-impl.xml b/Pro Java 7 NIO.2/Chapter01/path/path_03/nbproject/build-impl.xml new file mode 100644 index 0000000..39cd702 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter01/path/path_03/nbproject/build-impl.xml @@ -0,0 +1,1099 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set platform.home + Must set platform.bootcp + Must set platform.java + Must set platform.javac + + The J2SE Platform is not correctly set up. + Your active platform is: ${platform.active}, but the corresponding property "platforms.${platform.active}.home" is not found in the project's properties files. + Either open the project in the IDE and setup the Platform with the same name or add it manually. + For example like this: + ant -Duser.properties.file=<path_to_property_file> jar (where you put the property "platforms.${platform.active}.home" in a .properties file) + or ant -Dplatforms.${platform.active}.home=<path_to_JDK_home> jar (where no properties file is used) + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set src.dir + Must set test.src.dir + Must set build.dir + Must set dist.dir + Must set build.classes.dir + Must set dist.javadoc.dir + Must set build.test.classes.dir + Must set build.test.results.dir + Must set build.classes.excludes + Must set dist.jar + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set JVM to use for profiling in profiler.info.jvm + Must set profiler agent JVM arguments in profiler.info.jvmargs.agent + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + + + + + + ${platform.java} -cp "${run.classpath.with.dist.jar}" ${main.class} + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + ${platform.java} -jar "${dist.jar.resolved}" + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set run.class + + + + Must select one file in the IDE or set run.class + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set debug.class + + + + + Must select one file in the IDE or set debug.class + + + + + Must set fix.includes + + + + + + + + + + + + + + + + + Must select one file in the IDE or set profile.class + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + Some tests failed; see details above. + + + + + + + + + Must select some files in the IDE or set test.includes + + + + Some tests failed; see details above. + + + + + Must select one file in the IDE or set test.class + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Pro Java 7 NIO.2/Chapter01/path/path_03/nbproject/genfiles.properties b/Pro Java 7 NIO.2/Chapter01/path/path_03/nbproject/genfiles.properties new file mode 100644 index 0000000..0e7b09b --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter01/path/path_03/nbproject/genfiles.properties @@ -0,0 +1,8 @@ +build.xml.data.CRC32=cc656c25 +build.xml.script.CRC32=291655ae +build.xml.stylesheet.CRC32=28e38971@1.38.2.45 +# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. +# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. +nbproject/build-impl.xml.data.CRC32=cc656c25 +nbproject/build-impl.xml.script.CRC32=06dad9b4 +nbproject/build-impl.xml.stylesheet.CRC32=0c01fd8e@1.43.1.45 diff --git a/Pro Java 7 NIO.2/Chapter01/path/path_03/nbproject/private/config.properties b/Pro Java 7 NIO.2/Chapter01/path/path_03/nbproject/private/config.properties new file mode 100644 index 0000000..e69de29 diff --git a/Pro Java 7 NIO.2/Chapter01/path/path_03/nbproject/private/private.properties b/Pro Java 7 NIO.2/Chapter01/path/path_03/nbproject/private/private.properties new file mode 100644 index 0000000..a5ab360 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter01/path/path_03/nbproject/private/private.properties @@ -0,0 +1,6 @@ +compile.on.save=true +do.depend=false +do.jar=true +javac.debug=true +javadoc.preview=true +user.properties.file=C:\\Users\\Leo\\.netbeans\\7.0\\build.properties diff --git a/Pro Java 7 NIO.2/Chapter01/path/path_03/nbproject/private/private.xml b/Pro Java 7 NIO.2/Chapter01/path/path_03/nbproject/private/private.xml new file mode 100644 index 0000000..c1f155a --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter01/path/path_03/nbproject/private/private.xml @@ -0,0 +1,4 @@ + + + + diff --git a/Pro Java 7 NIO.2/Chapter01/path/path_03/nbproject/project.properties b/Pro Java 7 NIO.2/Chapter01/path/path_03/nbproject/project.properties new file mode 100644 index 0000000..4435609 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter01/path/path_03/nbproject/project.properties @@ -0,0 +1,74 @@ +annotation.processing.enabled=true +annotation.processing.enabled.in.editor=false +annotation.processing.run.all.processors=true +annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output +application.title=path_03 +application.vendor=Leo +build.classes.dir=${build.dir}/classes +build.classes.excludes=**/*.java,**/*.form +# This directory is removed when the project is cleaned: +build.dir=build +build.generated.dir=${build.dir}/generated +build.generated.sources.dir=${build.dir}/generated-sources +# Only compile against the classpath explicitly listed here: +build.sysclasspath=ignore +build.test.classes.dir=${build.dir}/test/classes +build.test.results.dir=${build.dir}/test/results +# Uncomment to specify the preferred debugger connection transport: +#debug.transport=dt_socket +debug.classpath=\ + ${run.classpath} +debug.test.classpath=\ + ${run.test.classpath} +# This directory is removed when the project is cleaned: +dist.dir=dist +dist.jar=${dist.dir}/path_03.jar +dist.javadoc.dir=${dist.dir}/javadoc +endorsed.classpath= +excludes= +includes=** +jar.compress=false +javac.classpath= +# Space-separated list of extra javac options +javac.compilerargs= +javac.deprecation=false +javac.processorpath=\ + ${javac.classpath} +javac.source=1.7 +javac.target=1.7 +javac.test.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir}:\ + ${libs.junit.classpath}:\ + ${libs.junit_4.classpath} +javac.test.processorpath=\ + ${javac.test.classpath} +javadoc.additionalparam= +javadoc.author=false +javadoc.encoding=${source.encoding} +javadoc.noindex=false +javadoc.nonavbar=false +javadoc.notree=false +javadoc.private=false +javadoc.splitindex=true +javadoc.use=true +javadoc.version=false +javadoc.windowtitle= +main.class=path_03.Main +manifest.file=manifest.mf +meta.inf.dir=${src.dir}/META-INF +mkdist.disabled=false +platform.active=JDK_1.7 +run.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +# Space-separated list of JVM arguments used when running the project +# (you may also define separate properties like run-sys-prop.name=value instead of -Dname=value +# or test-sys-prop.name=value to set system properties for unit tests): +run.jvmargs= +run.test.classpath=\ + ${javac.test.classpath}:\ + ${build.test.classes.dir} +source.encoding=UTF-8 +src.dir=src +test.src.dir=test diff --git a/Pro Java 7 NIO.2/Chapter01/path/path_03/nbproject/project.xml b/Pro Java 7 NIO.2/Chapter01/path/path_03/nbproject/project.xml new file mode 100644 index 0000000..9db8e3f --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter01/path/path_03/nbproject/project.xml @@ -0,0 +1,19 @@ + + + org.netbeans.modules.java.j2seproject + + + path_03 + + + + + + + + + + .\lib\nblibraries.properties + + + diff --git a/Pro Java 7 NIO.2/Chapter01/path/path_03/src/path_03/Main.java b/Pro Java 7 NIO.2/Chapter01/path/path_03/src/path_03/Main.java new file mode 100644 index 0000000..f434506 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter01/path/path_03/src/path_03/Main.java @@ -0,0 +1,46 @@ +package path_03; + +import java.io.File; +import java.io.IOException; +import java.net.URI; +import java.nio.file.LinkOption; +import java.nio.file.Path; +import java.nio.file.Paths; + +/** + * + * @author Apress + */ +public class Main { + + public static void main(String[] args) { + + Path path = Paths.get("/rafaelnadal/tournaments/2009", "BNP.txt"); + + //convert path to String + String path_to_string = path.toString(); + System.out.println("Path to String: " + path_to_string); + + //convert path to an URI (browser format) + URI path_to_uri = path.toUri(); + System.out.println("Path to URI: " + path_to_uri); + + //convert relative path to absolute path + Path path_to_absolute_path = path.toAbsolutePath(); + System.out.println("Path to absolute path: " + path_to_absolute_path.toString()); + + //convert path to "real" path + try { + Path real_path = path.toRealPath(LinkOption.NOFOLLOW_LINKS); + System.out.println("Path to real path: " + real_path); + } catch (IOException e) { + System.err.println(e); + } + + //convert path to File object + File path_to_file = path.toFile(); + Path file_to_path = path_to_file.toPath(); + System.out.println("Path to file name: " + path_to_file.getName()); + System.out.println("File to path: " + file_to_path.toString()); + } +} diff --git a/Pro Java 7 NIO.2/Chapter01/path/path_04/build.xml b/Pro Java 7 NIO.2/Chapter01/path/path_04/build.xml new file mode 100644 index 0000000..0122744 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter01/path/path_04/build.xml @@ -0,0 +1,74 @@ + + + + + + + + + + + Builds, tests, and runs the project path_04. + + + diff --git a/Pro Java 7 NIO.2/Chapter01/path/path_04/build/built-jar.properties b/Pro Java 7 NIO.2/Chapter01/path/path_04/build/built-jar.properties new file mode 100644 index 0000000..e002282 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter01/path/path_04/build/built-jar.properties @@ -0,0 +1,4 @@ +#Thu, 20 Oct 2011 08:57:14 +0200 + + +C\:\\NIO\\path\\path_04= diff --git a/Pro Java 7 NIO.2/Chapter01/path/path_04/build/classes/path_04/Main.class b/Pro Java 7 NIO.2/Chapter01/path/path_04/build/classes/path_04/Main.class new file mode 100644 index 0000000..c2ef6c4 Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter01/path/path_04/build/classes/path_04/Main.class differ diff --git a/Pro Java 7 NIO.2/Chapter01/path/path_04/dist/README.TXT b/Pro Java 7 NIO.2/Chapter01/path/path_04/dist/README.TXT new file mode 100644 index 0000000..67a9251 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter01/path/path_04/dist/README.TXT @@ -0,0 +1,33 @@ +======================== +BUILD OUTPUT DESCRIPTION +======================== + +When you build an Java application project that has a main class, the IDE +automatically copies all of the JAR +files on the projects classpath to your projects dist/lib folder. The IDE +also adds each of the JAR files to the Class-Path element in the application +JAR files manifest file (MANIFEST.MF). + +To run the project from the command line, go to the dist folder and +type the following: + +java -jar "path_04.jar" + +To distribute this project, zip up the dist folder (including the lib folder) +and distribute the ZIP file. + +Notes: + +* If two JAR files on the project classpath have the same name, only the first +JAR file is copied to the lib folder. +* Only JAR files are copied to the lib folder. +If the classpath contains other types of files or folders, none of the +classpath elements are copied to the lib folder. In such a case, +you need to copy the classpath elements to the lib folder manually after the build. +* If a library on the projects classpath also has a Class-Path element +specified in the manifest,the content of the Class-Path element has to be on +the projects runtime path. +* To set a main class in a standard Java project, right-click the project node +in the Projects window and choose Properties. Then click Run and enter the +class name in the Main Class field. Alternatively, you can manually type the +class name in the manifest Main-Class element. diff --git a/Pro Java 7 NIO.2/Chapter01/path/path_04/dist/path_04.jar b/Pro Java 7 NIO.2/Chapter01/path/path_04/dist/path_04.jar new file mode 100644 index 0000000..e778acf Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter01/path/path_04/dist/path_04.jar differ diff --git a/Pro Java 7 NIO.2/Chapter01/path/path_04/lib/CopyLibs/org-netbeans-modules-java-j2seproject-copylibstask.jar b/Pro Java 7 NIO.2/Chapter01/path/path_04/lib/CopyLibs/org-netbeans-modules-java-j2seproject-copylibstask.jar new file mode 100644 index 0000000..5ee71d2 Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter01/path/path_04/lib/CopyLibs/org-netbeans-modules-java-j2seproject-copylibstask.jar differ diff --git a/Pro Java 7 NIO.2/Chapter01/path/path_04/lib/junit/junit-3.8.2-api.zip b/Pro Java 7 NIO.2/Chapter01/path/path_04/lib/junit/junit-3.8.2-api.zip new file mode 100644 index 0000000..6d792fd Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter01/path/path_04/lib/junit/junit-3.8.2-api.zip differ diff --git a/Pro Java 7 NIO.2/Chapter01/path/path_04/lib/junit/junit-3.8.2.jar b/Pro Java 7 NIO.2/Chapter01/path/path_04/lib/junit/junit-3.8.2.jar new file mode 100644 index 0000000..d835872 Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter01/path/path_04/lib/junit/junit-3.8.2.jar differ diff --git a/Pro Java 7 NIO.2/Chapter01/path/path_04/lib/junit_4/junit-4.5-api.zip b/Pro Java 7 NIO.2/Chapter01/path/path_04/lib/junit_4/junit-4.5-api.zip new file mode 100644 index 0000000..5748c44 Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter01/path/path_04/lib/junit_4/junit-4.5-api.zip differ diff --git a/Pro Java 7 NIO.2/Chapter01/path/path_04/lib/junit_4/junit-4.5-src.jar b/Pro Java 7 NIO.2/Chapter01/path/path_04/lib/junit_4/junit-4.5-src.jar new file mode 100644 index 0000000..18774a5 Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter01/path/path_04/lib/junit_4/junit-4.5-src.jar differ diff --git a/Pro Java 7 NIO.2/Chapter01/path/path_04/lib/junit_4/junit-4.5.jar b/Pro Java 7 NIO.2/Chapter01/path/path_04/lib/junit_4/junit-4.5.jar new file mode 100644 index 0000000..83f8bc7 Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter01/path/path_04/lib/junit_4/junit-4.5.jar differ diff --git a/Pro Java 7 NIO.2/Chapter01/path/path_04/lib/nblibraries.properties b/Pro Java 7 NIO.2/Chapter01/path/path_04/lib/nblibraries.properties new file mode 100644 index 0000000..9137b06 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter01/path/path_04/lib/nblibraries.properties @@ -0,0 +1,12 @@ +libs.CopyLibs.classpath=\ + ${base}/CopyLibs/org-netbeans-modules-java-j2seproject-copylibstask.jar +libs.junit.classpath=\ + ${base}/junit/junit-3.8.2.jar +libs.junit.javadoc=\ + ${base}/junit/junit-3.8.2-api.zip +libs.junit_4.classpath=\ + ${base}/junit_4/junit-4.5.jar +libs.junit_4.javadoc=\ + ${base}/junit_4/junit-4.5-api.zip +libs.junit_4.src=\ + ${base}/junit_4/junit-4.5-src.jar diff --git a/Pro Java 7 NIO.2/Chapter01/path/path_04/manifest.mf b/Pro Java 7 NIO.2/Chapter01/path/path_04/manifest.mf new file mode 100644 index 0000000..328e8e5 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter01/path/path_04/manifest.mf @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +X-COMMENT: Main-Class will be added automatically by build + diff --git a/Pro Java 7 NIO.2/Chapter01/path/path_04/nbproject/build-impl.xml b/Pro Java 7 NIO.2/Chapter01/path/path_04/nbproject/build-impl.xml new file mode 100644 index 0000000..d41c020 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter01/path/path_04/nbproject/build-impl.xml @@ -0,0 +1,1099 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set platform.home + Must set platform.bootcp + Must set platform.java + Must set platform.javac + + The J2SE Platform is not correctly set up. + Your active platform is: ${platform.active}, but the corresponding property "platforms.${platform.active}.home" is not found in the project's properties files. + Either open the project in the IDE and setup the Platform with the same name or add it manually. + For example like this: + ant -Duser.properties.file=<path_to_property_file> jar (where you put the property "platforms.${platform.active}.home" in a .properties file) + or ant -Dplatforms.${platform.active}.home=<path_to_JDK_home> jar (where no properties file is used) + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set src.dir + Must set test.src.dir + Must set build.dir + Must set dist.dir + Must set build.classes.dir + Must set dist.javadoc.dir + Must set build.test.classes.dir + Must set build.test.results.dir + Must set build.classes.excludes + Must set dist.jar + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set JVM to use for profiling in profiler.info.jvm + Must set profiler agent JVM arguments in profiler.info.jvmargs.agent + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + + + + + + ${platform.java} -cp "${run.classpath.with.dist.jar}" ${main.class} + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + ${platform.java} -jar "${dist.jar.resolved}" + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set run.class + + + + Must select one file in the IDE or set run.class + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set debug.class + + + + + Must select one file in the IDE or set debug.class + + + + + Must set fix.includes + + + + + + + + + + + + + + + + + Must select one file in the IDE or set profile.class + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + Some tests failed; see details above. + + + + + + + + + Must select some files in the IDE or set test.includes + + + + Some tests failed; see details above. + + + + + Must select one file in the IDE or set test.class + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Pro Java 7 NIO.2/Chapter01/path/path_04/nbproject/genfiles.properties b/Pro Java 7 NIO.2/Chapter01/path/path_04/nbproject/genfiles.properties new file mode 100644 index 0000000..786dbfe --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter01/path/path_04/nbproject/genfiles.properties @@ -0,0 +1,8 @@ +build.xml.data.CRC32=cb8ce431 +build.xml.script.CRC32=18fc7b67 +build.xml.stylesheet.CRC32=28e38971@1.38.2.45 +# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. +# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. +nbproject/build-impl.xml.data.CRC32=cb8ce431 +nbproject/build-impl.xml.script.CRC32=6c72d52c +nbproject/build-impl.xml.stylesheet.CRC32=0c01fd8e@1.43.1.45 diff --git a/Pro Java 7 NIO.2/Chapter01/path/path_04/nbproject/private/config.properties b/Pro Java 7 NIO.2/Chapter01/path/path_04/nbproject/private/config.properties new file mode 100644 index 0000000..e69de29 diff --git a/Pro Java 7 NIO.2/Chapter01/path/path_04/nbproject/private/private.properties b/Pro Java 7 NIO.2/Chapter01/path/path_04/nbproject/private/private.properties new file mode 100644 index 0000000..a5ab360 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter01/path/path_04/nbproject/private/private.properties @@ -0,0 +1,6 @@ +compile.on.save=true +do.depend=false +do.jar=true +javac.debug=true +javadoc.preview=true +user.properties.file=C:\\Users\\Leo\\.netbeans\\7.0\\build.properties diff --git a/Pro Java 7 NIO.2/Chapter01/path/path_04/nbproject/private/private.xml b/Pro Java 7 NIO.2/Chapter01/path/path_04/nbproject/private/private.xml new file mode 100644 index 0000000..c1f155a --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter01/path/path_04/nbproject/private/private.xml @@ -0,0 +1,4 @@ + + + + diff --git a/Pro Java 7 NIO.2/Chapter01/path/path_04/nbproject/project.properties b/Pro Java 7 NIO.2/Chapter01/path/path_04/nbproject/project.properties new file mode 100644 index 0000000..b8f3be0 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter01/path/path_04/nbproject/project.properties @@ -0,0 +1,74 @@ +annotation.processing.enabled=true +annotation.processing.enabled.in.editor=false +annotation.processing.run.all.processors=true +annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output +application.title=path_04 +application.vendor=Leo +build.classes.dir=${build.dir}/classes +build.classes.excludes=**/*.java,**/*.form +# This directory is removed when the project is cleaned: +build.dir=build +build.generated.dir=${build.dir}/generated +build.generated.sources.dir=${build.dir}/generated-sources +# Only compile against the classpath explicitly listed here: +build.sysclasspath=ignore +build.test.classes.dir=${build.dir}/test/classes +build.test.results.dir=${build.dir}/test/results +# Uncomment to specify the preferred debugger connection transport: +#debug.transport=dt_socket +debug.classpath=\ + ${run.classpath} +debug.test.classpath=\ + ${run.test.classpath} +# This directory is removed when the project is cleaned: +dist.dir=dist +dist.jar=${dist.dir}/path_04.jar +dist.javadoc.dir=${dist.dir}/javadoc +endorsed.classpath= +excludes= +includes=** +jar.compress=false +javac.classpath= +# Space-separated list of extra javac options +javac.compilerargs= +javac.deprecation=false +javac.processorpath=\ + ${javac.classpath} +javac.source=1.7 +javac.target=1.7 +javac.test.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir}:\ + ${libs.junit.classpath}:\ + ${libs.junit_4.classpath} +javac.test.processorpath=\ + ${javac.test.classpath} +javadoc.additionalparam= +javadoc.author=false +javadoc.encoding=${source.encoding} +javadoc.noindex=false +javadoc.nonavbar=false +javadoc.notree=false +javadoc.private=false +javadoc.splitindex=true +javadoc.use=true +javadoc.version=false +javadoc.windowtitle= +main.class=path_04.Main +manifest.file=manifest.mf +meta.inf.dir=${src.dir}/META-INF +mkdist.disabled=false +platform.active=JDK_1.7 +run.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +# Space-separated list of JVM arguments used when running the project +# (you may also define separate properties like run-sys-prop.name=value instead of -Dname=value +# or test-sys-prop.name=value to set system properties for unit tests): +run.jvmargs= +run.test.classpath=\ + ${javac.test.classpath}:\ + ${build.test.classes.dir} +source.encoding=UTF-8 +src.dir=src +test.src.dir=test diff --git a/Pro Java 7 NIO.2/Chapter01/path/path_04/nbproject/project.xml b/Pro Java 7 NIO.2/Chapter01/path/path_04/nbproject/project.xml new file mode 100644 index 0000000..8867b3d --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter01/path/path_04/nbproject/project.xml @@ -0,0 +1,19 @@ + + + org.netbeans.modules.java.j2seproject + + + path_04 + + + + + + + + + + .\lib\nblibraries.properties + + + diff --git a/Pro Java 7 NIO.2/Chapter01/path/path_04/src/path_04/Main.java b/Pro Java 7 NIO.2/Chapter01/path/path_04/src/path_04/Main.java new file mode 100644 index 0000000..2a96eb5 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter01/path/path_04/src/path_04/Main.java @@ -0,0 +1,31 @@ +package path_04; + +import java.nio.file.Path; +import java.nio.file.Paths; + +/** + * + * @author Apress + */ +public class Main { + + public static void main(String[] args) { + + //define the fix path + Path base_1 = Paths.get("C:/rafaelnadal/tournaments/2009"); + Path base_2 = Paths.get("C:/rafaelnadal/tournaments/2009/BNP.txt"); + + //resolve BNP.txt file + Path path_1 = base_1.resolve("BNP.txt"); + System.out.println(path_1.toString()); + + //resolve AEGON.txt file + Path path_2 = base_1.resolve("AEGON.txt"); + System.out.println(path_2.toString()); + + //resolve sibling AEGON.txt file + Path path_3 = base_2.resolveSibling("AEGON.txt"); + System.out.println(path_3.toString()); + } + +} diff --git a/Pro Java 7 NIO.2/Chapter01/path/path_05/build.xml b/Pro Java 7 NIO.2/Chapter01/path/path_05/build.xml new file mode 100644 index 0000000..50385da --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter01/path/path_05/build.xml @@ -0,0 +1,74 @@ + + + + + + + + + + + Builds, tests, and runs the project path_05. + + + diff --git a/Pro Java 7 NIO.2/Chapter01/path/path_05/build/built-jar.properties b/Pro Java 7 NIO.2/Chapter01/path/path_05/build/built-jar.properties new file mode 100644 index 0000000..e674753 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter01/path/path_05/build/built-jar.properties @@ -0,0 +1,4 @@ +#Sun, 16 Oct 2011 15:56:21 +0200 + + +C\:\\NIO\\path\\path_05= diff --git a/Pro Java 7 NIO.2/Chapter01/path/path_05/build/classes/.netbeans_automatic_build b/Pro Java 7 NIO.2/Chapter01/path/path_05/build/classes/.netbeans_automatic_build new file mode 100644 index 0000000..e69de29 diff --git a/Pro Java 7 NIO.2/Chapter01/path/path_05/build/classes/path_05/Main.class b/Pro Java 7 NIO.2/Chapter01/path/path_05/build/classes/path_05/Main.class new file mode 100644 index 0000000..fcb324d Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter01/path/path_05/build/classes/path_05/Main.class differ diff --git a/Pro Java 7 NIO.2/Chapter01/path/path_05/dist/README.TXT b/Pro Java 7 NIO.2/Chapter01/path/path_05/dist/README.TXT new file mode 100644 index 0000000..03ed57c --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter01/path/path_05/dist/README.TXT @@ -0,0 +1,33 @@ +======================== +BUILD OUTPUT DESCRIPTION +======================== + +When you build an Java application project that has a main class, the IDE +automatically copies all of the JAR +files on the projects classpath to your projects dist/lib folder. The IDE +also adds each of the JAR files to the Class-Path element in the application +JAR files manifest file (MANIFEST.MF). + +To run the project from the command line, go to the dist folder and +type the following: + +java -jar "path_05.jar" + +To distribute this project, zip up the dist folder (including the lib folder) +and distribute the ZIP file. + +Notes: + +* If two JAR files on the project classpath have the same name, only the first +JAR file is copied to the lib folder. +* Only JAR files are copied to the lib folder. +If the classpath contains other types of files or folders, none of the +classpath elements are copied to the lib folder. In such a case, +you need to copy the classpath elements to the lib folder manually after the build. +* If a library on the projects classpath also has a Class-Path element +specified in the manifest,the content of the Class-Path element has to be on +the projects runtime path. +* To set a main class in a standard Java project, right-click the project node +in the Projects window and choose Properties. Then click Run and enter the +class name in the Main Class field. Alternatively, you can manually type the +class name in the manifest Main-Class element. diff --git a/Pro Java 7 NIO.2/Chapter01/path/path_05/dist/path_05.jar b/Pro Java 7 NIO.2/Chapter01/path/path_05/dist/path_05.jar new file mode 100644 index 0000000..1d44bb9 Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter01/path/path_05/dist/path_05.jar differ diff --git a/Pro Java 7 NIO.2/Chapter01/path/path_05/lib/CopyLibs/org-netbeans-modules-java-j2seproject-copylibstask.jar b/Pro Java 7 NIO.2/Chapter01/path/path_05/lib/CopyLibs/org-netbeans-modules-java-j2seproject-copylibstask.jar new file mode 100644 index 0000000..5ee71d2 Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter01/path/path_05/lib/CopyLibs/org-netbeans-modules-java-j2seproject-copylibstask.jar differ diff --git a/Pro Java 7 NIO.2/Chapter01/path/path_05/lib/junit/junit-3.8.2-api.zip b/Pro Java 7 NIO.2/Chapter01/path/path_05/lib/junit/junit-3.8.2-api.zip new file mode 100644 index 0000000..6d792fd Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter01/path/path_05/lib/junit/junit-3.8.2-api.zip differ diff --git a/Pro Java 7 NIO.2/Chapter01/path/path_05/lib/junit/junit-3.8.2.jar b/Pro Java 7 NIO.2/Chapter01/path/path_05/lib/junit/junit-3.8.2.jar new file mode 100644 index 0000000..d835872 Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter01/path/path_05/lib/junit/junit-3.8.2.jar differ diff --git a/Pro Java 7 NIO.2/Chapter01/path/path_05/lib/junit_4/junit-4.5-api.zip b/Pro Java 7 NIO.2/Chapter01/path/path_05/lib/junit_4/junit-4.5-api.zip new file mode 100644 index 0000000..5748c44 Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter01/path/path_05/lib/junit_4/junit-4.5-api.zip differ diff --git a/Pro Java 7 NIO.2/Chapter01/path/path_05/lib/junit_4/junit-4.5-src.jar b/Pro Java 7 NIO.2/Chapter01/path/path_05/lib/junit_4/junit-4.5-src.jar new file mode 100644 index 0000000..18774a5 Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter01/path/path_05/lib/junit_4/junit-4.5-src.jar differ diff --git a/Pro Java 7 NIO.2/Chapter01/path/path_05/lib/junit_4/junit-4.5.jar b/Pro Java 7 NIO.2/Chapter01/path/path_05/lib/junit_4/junit-4.5.jar new file mode 100644 index 0000000..83f8bc7 Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter01/path/path_05/lib/junit_4/junit-4.5.jar differ diff --git a/Pro Java 7 NIO.2/Chapter01/path/path_05/lib/nblibraries.properties b/Pro Java 7 NIO.2/Chapter01/path/path_05/lib/nblibraries.properties new file mode 100644 index 0000000..9137b06 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter01/path/path_05/lib/nblibraries.properties @@ -0,0 +1,12 @@ +libs.CopyLibs.classpath=\ + ${base}/CopyLibs/org-netbeans-modules-java-j2seproject-copylibstask.jar +libs.junit.classpath=\ + ${base}/junit/junit-3.8.2.jar +libs.junit.javadoc=\ + ${base}/junit/junit-3.8.2-api.zip +libs.junit_4.classpath=\ + ${base}/junit_4/junit-4.5.jar +libs.junit_4.javadoc=\ + ${base}/junit_4/junit-4.5-api.zip +libs.junit_4.src=\ + ${base}/junit_4/junit-4.5-src.jar diff --git a/Pro Java 7 NIO.2/Chapter01/path/path_05/manifest.mf b/Pro Java 7 NIO.2/Chapter01/path/path_05/manifest.mf new file mode 100644 index 0000000..328e8e5 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter01/path/path_05/manifest.mf @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +X-COMMENT: Main-Class will be added automatically by build + diff --git a/Pro Java 7 NIO.2/Chapter01/path/path_05/nbproject/build-impl.xml b/Pro Java 7 NIO.2/Chapter01/path/path_05/nbproject/build-impl.xml new file mode 100644 index 0000000..b03e9dd --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter01/path/path_05/nbproject/build-impl.xml @@ -0,0 +1,1066 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set src.dir + Must set test.src.dir + Must set build.dir + Must set dist.dir + Must set build.classes.dir + Must set dist.javadoc.dir + Must set build.test.classes.dir + Must set build.test.results.dir + Must set build.classes.excludes + Must set dist.jar + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set JVM to use for profiling in profiler.info.jvm + Must set profiler agent JVM arguments in profiler.info.jvmargs.agent + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + + + + + + java -cp "${run.classpath.with.dist.jar}" ${main.class} + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + java -jar "${dist.jar.resolved}" + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set run.class + + + + Must select one file in the IDE or set run.class + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set debug.class + + + + + Must select one file in the IDE or set debug.class + + + + + Must set fix.includes + + + + + + + + + + + + + + + + + Must select one file in the IDE or set profile.class + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + Some tests failed; see details above. + + + + + + + + + Must select some files in the IDE or set test.includes + + + + Some tests failed; see details above. + + + + + Must select one file in the IDE or set test.class + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Pro Java 7 NIO.2/Chapter01/path/path_05/nbproject/genfiles.properties b/Pro Java 7 NIO.2/Chapter01/path/path_05/nbproject/genfiles.properties new file mode 100644 index 0000000..9850568 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter01/path/path_05/nbproject/genfiles.properties @@ -0,0 +1,8 @@ +build.xml.data.CRC32=e1b8a116 +build.xml.script.CRC32=13dfc224 +build.xml.stylesheet.CRC32=28e38971@1.43.1.45 +# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. +# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. +nbproject/build-impl.xml.data.CRC32=e1b8a116 +nbproject/build-impl.xml.script.CRC32=1351363e +nbproject/build-impl.xml.stylesheet.CRC32=0c01fd8e@1.43.1.45 diff --git a/Pro Java 7 NIO.2/Chapter01/path/path_05/nbproject/private/config.properties b/Pro Java 7 NIO.2/Chapter01/path/path_05/nbproject/private/config.properties new file mode 100644 index 0000000..e69de29 diff --git a/Pro Java 7 NIO.2/Chapter01/path/path_05/nbproject/private/private.properties b/Pro Java 7 NIO.2/Chapter01/path/path_05/nbproject/private/private.properties new file mode 100644 index 0000000..a5ab360 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter01/path/path_05/nbproject/private/private.properties @@ -0,0 +1,6 @@ +compile.on.save=true +do.depend=false +do.jar=true +javac.debug=true +javadoc.preview=true +user.properties.file=C:\\Users\\Leo\\.netbeans\\7.0\\build.properties diff --git a/Pro Java 7 NIO.2/Chapter01/path/path_05/nbproject/private/private.xml b/Pro Java 7 NIO.2/Chapter01/path/path_05/nbproject/private/private.xml new file mode 100644 index 0000000..c1f155a --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter01/path/path_05/nbproject/private/private.xml @@ -0,0 +1,4 @@ + + + + diff --git a/Pro Java 7 NIO.2/Chapter01/path/path_05/nbproject/project.properties b/Pro Java 7 NIO.2/Chapter01/path/path_05/nbproject/project.properties new file mode 100644 index 0000000..4e6cc42 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter01/path/path_05/nbproject/project.properties @@ -0,0 +1,74 @@ +annotation.processing.enabled=true +annotation.processing.enabled.in.editor=false +annotation.processing.run.all.processors=true +annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output +application.title=path_05 +application.vendor=Leo +build.classes.dir=${build.dir}/classes +build.classes.excludes=**/*.java,**/*.form +# This directory is removed when the project is cleaned: +build.dir=build +build.generated.dir=${build.dir}/generated +build.generated.sources.dir=${build.dir}/generated-sources +# Only compile against the classpath explicitly listed here: +build.sysclasspath=ignore +build.test.classes.dir=${build.dir}/test/classes +build.test.results.dir=${build.dir}/test/results +# Uncomment to specify the preferred debugger connection transport: +#debug.transport=dt_socket +debug.classpath=\ + ${run.classpath} +debug.test.classpath=\ + ${run.test.classpath} +# This directory is removed when the project is cleaned: +dist.dir=dist +dist.jar=${dist.dir}/path_05.jar +dist.javadoc.dir=${dist.dir}/javadoc +endorsed.classpath= +excludes= +includes=** +jar.compress=false +javac.classpath= +# Space-separated list of extra javac options +javac.compilerargs= +javac.deprecation=false +javac.processorpath=\ + ${javac.classpath} +javac.source=1.7 +javac.target=1.7 +javac.test.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir}:\ + ${libs.junit.classpath}:\ + ${libs.junit_4.classpath} +javac.test.processorpath=\ + ${javac.test.classpath} +javadoc.additionalparam= +javadoc.author=false +javadoc.encoding=${source.encoding} +javadoc.noindex=false +javadoc.nonavbar=false +javadoc.notree=false +javadoc.private=false +javadoc.splitindex=true +javadoc.use=true +javadoc.version=false +javadoc.windowtitle= +main.class=path_05.Main +manifest.file=manifest.mf +meta.inf.dir=${src.dir}/META-INF +mkdist.disabled=false +platform.active=default_platform +run.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +# Space-separated list of JVM arguments used when running the project +# (you may also define separate properties like run-sys-prop.name=value instead of -Dname=value +# or test-sys-prop.name=value to set system properties for unit tests): +run.jvmargs= +run.test.classpath=\ + ${javac.test.classpath}:\ + ${build.test.classes.dir} +source.encoding=UTF-8 +src.dir=src +test.src.dir=test diff --git a/Pro Java 7 NIO.2/Chapter01/path/path_05/nbproject/project.xml b/Pro Java 7 NIO.2/Chapter01/path/path_05/nbproject/project.xml new file mode 100644 index 0000000..3067fea --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter01/path/path_05/nbproject/project.xml @@ -0,0 +1,18 @@ + + + org.netbeans.modules.java.j2seproject + + + path_05 + + + + + + + + + .\lib\nblibraries.properties + + + diff --git a/Pro Java 7 NIO.2/Chapter01/path/path_05/src/path_05/Main.java b/Pro Java 7 NIO.2/Chapter01/path/path_05/src/path_05/Main.java new file mode 100644 index 0000000..03d6a0f --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter01/path/path_05/src/path_05/Main.java @@ -0,0 +1,32 @@ +package path_05; + +import java.nio.file.Path; +import java.nio.file.Paths; + +/** + * + * @author Apress + */ +public class Main { + + public static void main(String[] args) { + + Path path01 = Paths.get("BNP.txt"); + Path path02 = Paths.get("AEGON.txt"); + Path path03 = Paths.get("/tournaments/2009/BNP.txt"); + Path path04 = Paths.get("/tournaments/2011"); + + Path path01_to_path02 = path01.relativize(path02); + System.out.println(path01_to_path02); + + Path path02_to_path01 = path02.relativize(path01); + System.out.println(path02_to_path01); + + Path path03_to_path04 = path03.relativize(path04); + System.out.println(path03_to_path04); + + Path path04_to_path03 = path04.relativize(path03); + System.out.println(path04_to_path03); + } + +} diff --git a/Pro Java 7 NIO.2/Chapter01/path/path_06/build.xml b/Pro Java 7 NIO.2/Chapter01/path/path_06/build.xml new file mode 100644 index 0000000..f1a7ae9 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter01/path/path_06/build.xml @@ -0,0 +1,74 @@ + + + + + + + + + + + Builds, tests, and runs the project path_06. + + + diff --git a/Pro Java 7 NIO.2/Chapter01/path/path_06/build/built-jar.properties b/Pro Java 7 NIO.2/Chapter01/path/path_06/build/built-jar.properties new file mode 100644 index 0000000..c2156e7 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter01/path/path_06/build/built-jar.properties @@ -0,0 +1,4 @@ +#Sun, 16 Oct 2011 15:57:03 +0200 + + +C\:\\NIO\\path\\path_06= diff --git a/Pro Java 7 NIO.2/Chapter01/path/path_06/build/classes/.netbeans_automatic_build b/Pro Java 7 NIO.2/Chapter01/path/path_06/build/classes/.netbeans_automatic_build new file mode 100644 index 0000000..e69de29 diff --git a/Pro Java 7 NIO.2/Chapter01/path/path_06/build/classes/path_06/Main.class b/Pro Java 7 NIO.2/Chapter01/path/path_06/build/classes/path_06/Main.class new file mode 100644 index 0000000..2e83a66 Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter01/path/path_06/build/classes/path_06/Main.class differ diff --git a/Pro Java 7 NIO.2/Chapter01/path/path_06/dist/README.TXT b/Pro Java 7 NIO.2/Chapter01/path/path_06/dist/README.TXT new file mode 100644 index 0000000..d941fd3 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter01/path/path_06/dist/README.TXT @@ -0,0 +1,33 @@ +======================== +BUILD OUTPUT DESCRIPTION +======================== + +When you build an Java application project that has a main class, the IDE +automatically copies all of the JAR +files on the projects classpath to your projects dist/lib folder. The IDE +also adds each of the JAR files to the Class-Path element in the application +JAR files manifest file (MANIFEST.MF). + +To run the project from the command line, go to the dist folder and +type the following: + +java -jar "path_06.jar" + +To distribute this project, zip up the dist folder (including the lib folder) +and distribute the ZIP file. + +Notes: + +* If two JAR files on the project classpath have the same name, only the first +JAR file is copied to the lib folder. +* Only JAR files are copied to the lib folder. +If the classpath contains other types of files or folders, none of the +classpath elements are copied to the lib folder. In such a case, +you need to copy the classpath elements to the lib folder manually after the build. +* If a library on the projects classpath also has a Class-Path element +specified in the manifest,the content of the Class-Path element has to be on +the projects runtime path. +* To set a main class in a standard Java project, right-click the project node +in the Projects window and choose Properties. Then click Run and enter the +class name in the Main Class field. Alternatively, you can manually type the +class name in the manifest Main-Class element. diff --git a/Pro Java 7 NIO.2/Chapter01/path/path_06/dist/path_06.jar b/Pro Java 7 NIO.2/Chapter01/path/path_06/dist/path_06.jar new file mode 100644 index 0000000..3b5cae9 Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter01/path/path_06/dist/path_06.jar differ diff --git a/Pro Java 7 NIO.2/Chapter01/path/path_06/lib/CopyLibs/org-netbeans-modules-java-j2seproject-copylibstask.jar b/Pro Java 7 NIO.2/Chapter01/path/path_06/lib/CopyLibs/org-netbeans-modules-java-j2seproject-copylibstask.jar new file mode 100644 index 0000000..5ee71d2 Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter01/path/path_06/lib/CopyLibs/org-netbeans-modules-java-j2seproject-copylibstask.jar differ diff --git a/Pro Java 7 NIO.2/Chapter01/path/path_06/lib/junit/junit-3.8.2-api.zip b/Pro Java 7 NIO.2/Chapter01/path/path_06/lib/junit/junit-3.8.2-api.zip new file mode 100644 index 0000000..6d792fd Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter01/path/path_06/lib/junit/junit-3.8.2-api.zip differ diff --git a/Pro Java 7 NIO.2/Chapter01/path/path_06/lib/junit/junit-3.8.2.jar b/Pro Java 7 NIO.2/Chapter01/path/path_06/lib/junit/junit-3.8.2.jar new file mode 100644 index 0000000..d835872 Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter01/path/path_06/lib/junit/junit-3.8.2.jar differ diff --git a/Pro Java 7 NIO.2/Chapter01/path/path_06/lib/junit_4/junit-4.5-api.zip b/Pro Java 7 NIO.2/Chapter01/path/path_06/lib/junit_4/junit-4.5-api.zip new file mode 100644 index 0000000..5748c44 Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter01/path/path_06/lib/junit_4/junit-4.5-api.zip differ diff --git a/Pro Java 7 NIO.2/Chapter01/path/path_06/lib/junit_4/junit-4.5-src.jar b/Pro Java 7 NIO.2/Chapter01/path/path_06/lib/junit_4/junit-4.5-src.jar new file mode 100644 index 0000000..18774a5 Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter01/path/path_06/lib/junit_4/junit-4.5-src.jar differ diff --git a/Pro Java 7 NIO.2/Chapter01/path/path_06/lib/junit_4/junit-4.5.jar b/Pro Java 7 NIO.2/Chapter01/path/path_06/lib/junit_4/junit-4.5.jar new file mode 100644 index 0000000..83f8bc7 Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter01/path/path_06/lib/junit_4/junit-4.5.jar differ diff --git a/Pro Java 7 NIO.2/Chapter01/path/path_06/lib/nblibraries.properties b/Pro Java 7 NIO.2/Chapter01/path/path_06/lib/nblibraries.properties new file mode 100644 index 0000000..9137b06 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter01/path/path_06/lib/nblibraries.properties @@ -0,0 +1,12 @@ +libs.CopyLibs.classpath=\ + ${base}/CopyLibs/org-netbeans-modules-java-j2seproject-copylibstask.jar +libs.junit.classpath=\ + ${base}/junit/junit-3.8.2.jar +libs.junit.javadoc=\ + ${base}/junit/junit-3.8.2-api.zip +libs.junit_4.classpath=\ + ${base}/junit_4/junit-4.5.jar +libs.junit_4.javadoc=\ + ${base}/junit_4/junit-4.5-api.zip +libs.junit_4.src=\ + ${base}/junit_4/junit-4.5-src.jar diff --git a/Pro Java 7 NIO.2/Chapter01/path/path_06/manifest.mf b/Pro Java 7 NIO.2/Chapter01/path/path_06/manifest.mf new file mode 100644 index 0000000..328e8e5 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter01/path/path_06/manifest.mf @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +X-COMMENT: Main-Class will be added automatically by build + diff --git a/Pro Java 7 NIO.2/Chapter01/path/path_06/nbproject/build-impl.xml b/Pro Java 7 NIO.2/Chapter01/path/path_06/nbproject/build-impl.xml new file mode 100644 index 0000000..8fe273f --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter01/path/path_06/nbproject/build-impl.xml @@ -0,0 +1,1099 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set platform.home + Must set platform.bootcp + Must set platform.java + Must set platform.javac + + The J2SE Platform is not correctly set up. + Your active platform is: ${platform.active}, but the corresponding property "platforms.${platform.active}.home" is not found in the project's properties files. + Either open the project in the IDE and setup the Platform with the same name or add it manually. + For example like this: + ant -Duser.properties.file=<path_to_property_file> jar (where you put the property "platforms.${platform.active}.home" in a .properties file) + or ant -Dplatforms.${platform.active}.home=<path_to_JDK_home> jar (where no properties file is used) + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set src.dir + Must set test.src.dir + Must set build.dir + Must set dist.dir + Must set build.classes.dir + Must set dist.javadoc.dir + Must set build.test.classes.dir + Must set build.test.results.dir + Must set build.classes.excludes + Must set dist.jar + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set JVM to use for profiling in profiler.info.jvm + Must set profiler agent JVM arguments in profiler.info.jvmargs.agent + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + + + + + + ${platform.java} -cp "${run.classpath.with.dist.jar}" ${main.class} + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + ${platform.java} -jar "${dist.jar.resolved}" + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set run.class + + + + Must select one file in the IDE or set run.class + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set debug.class + + + + + Must select one file in the IDE or set debug.class + + + + + Must set fix.includes + + + + + + + + + + + + + + + + + Must select one file in the IDE or set profile.class + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + Some tests failed; see details above. + + + + + + + + + Must select some files in the IDE or set test.includes + + + + Some tests failed; see details above. + + + + + Must select one file in the IDE or set test.class + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Pro Java 7 NIO.2/Chapter01/path/path_06/nbproject/genfiles.properties b/Pro Java 7 NIO.2/Chapter01/path/path_06/nbproject/genfiles.properties new file mode 100644 index 0000000..1473c2e --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter01/path/path_06/nbproject/genfiles.properties @@ -0,0 +1,8 @@ +build.xml.data.CRC32=8cdae392 +build.xml.script.CRC32=0ebb09e1 +build.xml.stylesheet.CRC32=28e38971@1.38.2.45 +# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. +# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. +nbproject/build-impl.xml.data.CRC32=8cdae392 +nbproject/build-impl.xml.script.CRC32=ccf964ca +nbproject/build-impl.xml.stylesheet.CRC32=0c01fd8e@1.43.1.45 diff --git a/Pro Java 7 NIO.2/Chapter01/path/path_06/nbproject/private/config.properties b/Pro Java 7 NIO.2/Chapter01/path/path_06/nbproject/private/config.properties new file mode 100644 index 0000000..e69de29 diff --git a/Pro Java 7 NIO.2/Chapter01/path/path_06/nbproject/private/private.properties b/Pro Java 7 NIO.2/Chapter01/path/path_06/nbproject/private/private.properties new file mode 100644 index 0000000..a5ab360 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter01/path/path_06/nbproject/private/private.properties @@ -0,0 +1,6 @@ +compile.on.save=true +do.depend=false +do.jar=true +javac.debug=true +javadoc.preview=true +user.properties.file=C:\\Users\\Leo\\.netbeans\\7.0\\build.properties diff --git a/Pro Java 7 NIO.2/Chapter01/path/path_06/nbproject/private/private.xml b/Pro Java 7 NIO.2/Chapter01/path/path_06/nbproject/private/private.xml new file mode 100644 index 0000000..c1f155a --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter01/path/path_06/nbproject/private/private.xml @@ -0,0 +1,4 @@ + + + + diff --git a/Pro Java 7 NIO.2/Chapter01/path/path_06/nbproject/project.properties b/Pro Java 7 NIO.2/Chapter01/path/path_06/nbproject/project.properties new file mode 100644 index 0000000..8f40920 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter01/path/path_06/nbproject/project.properties @@ -0,0 +1,74 @@ +annotation.processing.enabled=true +annotation.processing.enabled.in.editor=false +annotation.processing.run.all.processors=true +annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output +application.title=path_06 +application.vendor=Leo +build.classes.dir=${build.dir}/classes +build.classes.excludes=**/*.java,**/*.form +# This directory is removed when the project is cleaned: +build.dir=build +build.generated.dir=${build.dir}/generated +build.generated.sources.dir=${build.dir}/generated-sources +# Only compile against the classpath explicitly listed here: +build.sysclasspath=ignore +build.test.classes.dir=${build.dir}/test/classes +build.test.results.dir=${build.dir}/test/results +# Uncomment to specify the preferred debugger connection transport: +#debug.transport=dt_socket +debug.classpath=\ + ${run.classpath} +debug.test.classpath=\ + ${run.test.classpath} +# This directory is removed when the project is cleaned: +dist.dir=dist +dist.jar=${dist.dir}/path_06.jar +dist.javadoc.dir=${dist.dir}/javadoc +endorsed.classpath= +excludes= +includes=** +jar.compress=false +javac.classpath= +# Space-separated list of extra javac options +javac.compilerargs= +javac.deprecation=false +javac.processorpath=\ + ${javac.classpath} +javac.source=1.7 +javac.target=1.7 +javac.test.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir}:\ + ${libs.junit.classpath}:\ + ${libs.junit_4.classpath} +javac.test.processorpath=\ + ${javac.test.classpath} +javadoc.additionalparam= +javadoc.author=false +javadoc.encoding=${source.encoding} +javadoc.noindex=false +javadoc.nonavbar=false +javadoc.notree=false +javadoc.private=false +javadoc.splitindex=true +javadoc.use=true +javadoc.version=false +javadoc.windowtitle= +main.class=path_06.Main +manifest.file=manifest.mf +meta.inf.dir=${src.dir}/META-INF +mkdist.disabled=false +platform.active=JDK_1.7 +run.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +# Space-separated list of JVM arguments used when running the project +# (you may also define separate properties like run-sys-prop.name=value instead of -Dname=value +# or test-sys-prop.name=value to set system properties for unit tests): +run.jvmargs= +run.test.classpath=\ + ${javac.test.classpath}:\ + ${build.test.classes.dir} +source.encoding=UTF-8 +src.dir=src +test.src.dir=test diff --git a/Pro Java 7 NIO.2/Chapter01/path/path_06/nbproject/project.xml b/Pro Java 7 NIO.2/Chapter01/path/path_06/nbproject/project.xml new file mode 100644 index 0000000..a5fd6b5 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter01/path/path_06/nbproject/project.xml @@ -0,0 +1,19 @@ + + + org.netbeans.modules.java.j2seproject + + + path_06 + + + + + + + + + + .\lib\nblibraries.properties + + + diff --git a/Pro Java 7 NIO.2/Chapter01/path/path_06/src/path_06/Main.java b/Pro Java 7 NIO.2/Chapter01/path/path_06/src/path_06/Main.java new file mode 100644 index 0000000..30a7f29 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter01/path/path_06/src/path_06/Main.java @@ -0,0 +1,48 @@ +package path_06; + +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; + +/** + * + * @author Apress + */ +public class Main { + + public static void main(String[] args) { + + Path path01 = Paths.get("/rafaelnadal/tournaments/2009/BNP.txt"); + Path path02 = Paths.get("C:/rafaelnadal/tournaments/2009/BNP.txt"); + + //compare using Path.equals + if (path01.equals(path02)) { + System.out.println("The paths are equal!"); + } else { + System.out.println("The paths are not equal!"); + } + + //compare using Files.isSameFile + try { + boolean check = Files.isSameFile(path01, path02); + if (check) { + System.out.println("The paths locate the same file!"); + } else { + System.out.println("The paths does not locate the same file!"); + } + } catch (IOException e) { + System.out.println(e); + } + + //compare using Path.compareTo + int compare = path01.compareTo(path02); + System.out.println(compare); + + //compare using startsWith and endsWith + boolean sw = path01.startsWith("/rafaelnadal/tournaments"); + boolean ew = path01.endsWith("BNP.txt"); + System.out.println(sw); + System.out.println(ew); + } +} diff --git a/Pro Java 7 NIO.2/Chapter01/path/path_07/build.xml b/Pro Java 7 NIO.2/Chapter01/path/path_07/build.xml new file mode 100644 index 0000000..20c01c1 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter01/path/path_07/build.xml @@ -0,0 +1,74 @@ + + + + + + + + + + + Builds, tests, and runs the project path_07. + + + diff --git a/Pro Java 7 NIO.2/Chapter01/path/path_07/build/built-jar.properties b/Pro Java 7 NIO.2/Chapter01/path/path_07/build/built-jar.properties new file mode 100644 index 0000000..a9bdb0b --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter01/path/path_07/build/built-jar.properties @@ -0,0 +1,4 @@ +#Sun, 16 Oct 2011 15:58:18 +0200 + + +C\:\\NIO\\path\\path_07= diff --git a/Pro Java 7 NIO.2/Chapter01/path/path_07/build/classes/.netbeans_automatic_build b/Pro Java 7 NIO.2/Chapter01/path/path_07/build/classes/.netbeans_automatic_build new file mode 100644 index 0000000..e69de29 diff --git a/Pro Java 7 NIO.2/Chapter01/path/path_07/build/classes/path_07/Main.class b/Pro Java 7 NIO.2/Chapter01/path/path_07/build/classes/path_07/Main.class new file mode 100644 index 0000000..02aa450 Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter01/path/path_07/build/classes/path_07/Main.class differ diff --git a/Pro Java 7 NIO.2/Chapter01/path/path_07/dist/README.TXT b/Pro Java 7 NIO.2/Chapter01/path/path_07/dist/README.TXT new file mode 100644 index 0000000..648276c --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter01/path/path_07/dist/README.TXT @@ -0,0 +1,33 @@ +======================== +BUILD OUTPUT DESCRIPTION +======================== + +When you build an Java application project that has a main class, the IDE +automatically copies all of the JAR +files on the projects classpath to your projects dist/lib folder. The IDE +also adds each of the JAR files to the Class-Path element in the application +JAR files manifest file (MANIFEST.MF). + +To run the project from the command line, go to the dist folder and +type the following: + +java -jar "path_07.jar" + +To distribute this project, zip up the dist folder (including the lib folder) +and distribute the ZIP file. + +Notes: + +* If two JAR files on the project classpath have the same name, only the first +JAR file is copied to the lib folder. +* Only JAR files are copied to the lib folder. +If the classpath contains other types of files or folders, none of the +classpath elements are copied to the lib folder. In such a case, +you need to copy the classpath elements to the lib folder manually after the build. +* If a library on the projects classpath also has a Class-Path element +specified in the manifest,the content of the Class-Path element has to be on +the projects runtime path. +* To set a main class in a standard Java project, right-click the project node +in the Projects window and choose Properties. Then click Run and enter the +class name in the Main Class field. Alternatively, you can manually type the +class name in the manifest Main-Class element. diff --git a/Pro Java 7 NIO.2/Chapter01/path/path_07/dist/path_07.jar b/Pro Java 7 NIO.2/Chapter01/path/path_07/dist/path_07.jar new file mode 100644 index 0000000..04fde0a Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter01/path/path_07/dist/path_07.jar differ diff --git a/Pro Java 7 NIO.2/Chapter01/path/path_07/lib/CopyLibs/org-netbeans-modules-java-j2seproject-copylibstask.jar b/Pro Java 7 NIO.2/Chapter01/path/path_07/lib/CopyLibs/org-netbeans-modules-java-j2seproject-copylibstask.jar new file mode 100644 index 0000000..5ee71d2 Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter01/path/path_07/lib/CopyLibs/org-netbeans-modules-java-j2seproject-copylibstask.jar differ diff --git a/Pro Java 7 NIO.2/Chapter01/path/path_07/lib/junit/junit-3.8.2-api.zip b/Pro Java 7 NIO.2/Chapter01/path/path_07/lib/junit/junit-3.8.2-api.zip new file mode 100644 index 0000000..6d792fd Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter01/path/path_07/lib/junit/junit-3.8.2-api.zip differ diff --git a/Pro Java 7 NIO.2/Chapter01/path/path_07/lib/junit/junit-3.8.2.jar b/Pro Java 7 NIO.2/Chapter01/path/path_07/lib/junit/junit-3.8.2.jar new file mode 100644 index 0000000..d835872 Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter01/path/path_07/lib/junit/junit-3.8.2.jar differ diff --git a/Pro Java 7 NIO.2/Chapter01/path/path_07/lib/junit_4/junit-4.5-api.zip b/Pro Java 7 NIO.2/Chapter01/path/path_07/lib/junit_4/junit-4.5-api.zip new file mode 100644 index 0000000..5748c44 Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter01/path/path_07/lib/junit_4/junit-4.5-api.zip differ diff --git a/Pro Java 7 NIO.2/Chapter01/path/path_07/lib/junit_4/junit-4.5-src.jar b/Pro Java 7 NIO.2/Chapter01/path/path_07/lib/junit_4/junit-4.5-src.jar new file mode 100644 index 0000000..18774a5 Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter01/path/path_07/lib/junit_4/junit-4.5-src.jar differ diff --git a/Pro Java 7 NIO.2/Chapter01/path/path_07/lib/junit_4/junit-4.5.jar b/Pro Java 7 NIO.2/Chapter01/path/path_07/lib/junit_4/junit-4.5.jar new file mode 100644 index 0000000..83f8bc7 Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter01/path/path_07/lib/junit_4/junit-4.5.jar differ diff --git a/Pro Java 7 NIO.2/Chapter01/path/path_07/lib/nblibraries.properties b/Pro Java 7 NIO.2/Chapter01/path/path_07/lib/nblibraries.properties new file mode 100644 index 0000000..9137b06 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter01/path/path_07/lib/nblibraries.properties @@ -0,0 +1,12 @@ +libs.CopyLibs.classpath=\ + ${base}/CopyLibs/org-netbeans-modules-java-j2seproject-copylibstask.jar +libs.junit.classpath=\ + ${base}/junit/junit-3.8.2.jar +libs.junit.javadoc=\ + ${base}/junit/junit-3.8.2-api.zip +libs.junit_4.classpath=\ + ${base}/junit_4/junit-4.5.jar +libs.junit_4.javadoc=\ + ${base}/junit_4/junit-4.5-api.zip +libs.junit_4.src=\ + ${base}/junit_4/junit-4.5-src.jar diff --git a/Pro Java 7 NIO.2/Chapter01/path/path_07/manifest.mf b/Pro Java 7 NIO.2/Chapter01/path/path_07/manifest.mf new file mode 100644 index 0000000..328e8e5 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter01/path/path_07/manifest.mf @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +X-COMMENT: Main-Class will be added automatically by build + diff --git a/Pro Java 7 NIO.2/Chapter01/path/path_07/nbproject/build-impl.xml b/Pro Java 7 NIO.2/Chapter01/path/path_07/nbproject/build-impl.xml new file mode 100644 index 0000000..875d69d --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter01/path/path_07/nbproject/build-impl.xml @@ -0,0 +1,1099 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set platform.home + Must set platform.bootcp + Must set platform.java + Must set platform.javac + + The J2SE Platform is not correctly set up. + Your active platform is: ${platform.active}, but the corresponding property "platforms.${platform.active}.home" is not found in the project's properties files. + Either open the project in the IDE and setup the Platform with the same name or add it manually. + For example like this: + ant -Duser.properties.file=<path_to_property_file> jar (where you put the property "platforms.${platform.active}.home" in a .properties file) + or ant -Dplatforms.${platform.active}.home=<path_to_JDK_home> jar (where no properties file is used) + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set src.dir + Must set test.src.dir + Must set build.dir + Must set dist.dir + Must set build.classes.dir + Must set dist.javadoc.dir + Must set build.test.classes.dir + Must set build.test.results.dir + Must set build.classes.excludes + Must set dist.jar + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set JVM to use for profiling in profiler.info.jvm + Must set profiler agent JVM arguments in profiler.info.jvmargs.agent + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + + + + + + ${platform.java} -cp "${run.classpath.with.dist.jar}" ${main.class} + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + ${platform.java} -jar "${dist.jar.resolved}" + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set run.class + + + + Must select one file in the IDE or set run.class + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set debug.class + + + + + Must select one file in the IDE or set debug.class + + + + + Must set fix.includes + + + + + + + + + + + + + + + + + Must select one file in the IDE or set profile.class + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + Some tests failed; see details above. + + + + + + + + + Must select some files in the IDE or set test.includes + + + + Some tests failed; see details above. + + + + + Must select one file in the IDE or set test.class + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Pro Java 7 NIO.2/Chapter01/path/path_07/nbproject/genfiles.properties b/Pro Java 7 NIO.2/Chapter01/path/path_07/nbproject/genfiles.properties new file mode 100644 index 0000000..9195660 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter01/path/path_07/nbproject/genfiles.properties @@ -0,0 +1,8 @@ +build.xml.data.CRC32=42c96363 +build.xml.script.CRC32=0598b0a2 +build.xml.stylesheet.CRC32=28e38971@1.38.2.45 +# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. +# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. +nbproject/build-impl.xml.data.CRC32=42c96363 +nbproject/build-impl.xml.script.CRC32=9cbcbc39 +nbproject/build-impl.xml.stylesheet.CRC32=0c01fd8e@1.43.1.45 diff --git a/Pro Java 7 NIO.2/Chapter01/path/path_07/nbproject/private/config.properties b/Pro Java 7 NIO.2/Chapter01/path/path_07/nbproject/private/config.properties new file mode 100644 index 0000000..e69de29 diff --git a/Pro Java 7 NIO.2/Chapter01/path/path_07/nbproject/private/private.properties b/Pro Java 7 NIO.2/Chapter01/path/path_07/nbproject/private/private.properties new file mode 100644 index 0000000..a5ab360 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter01/path/path_07/nbproject/private/private.properties @@ -0,0 +1,6 @@ +compile.on.save=true +do.depend=false +do.jar=true +javac.debug=true +javadoc.preview=true +user.properties.file=C:\\Users\\Leo\\.netbeans\\7.0\\build.properties diff --git a/Pro Java 7 NIO.2/Chapter01/path/path_07/nbproject/private/private.xml b/Pro Java 7 NIO.2/Chapter01/path/path_07/nbproject/private/private.xml new file mode 100644 index 0000000..c1f155a --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter01/path/path_07/nbproject/private/private.xml @@ -0,0 +1,4 @@ + + + + diff --git a/Pro Java 7 NIO.2/Chapter01/path/path_07/nbproject/project.properties b/Pro Java 7 NIO.2/Chapter01/path/path_07/nbproject/project.properties new file mode 100644 index 0000000..4c8be5b --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter01/path/path_07/nbproject/project.properties @@ -0,0 +1,74 @@ +annotation.processing.enabled=true +annotation.processing.enabled.in.editor=false +annotation.processing.run.all.processors=true +annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output +application.title=path_07 +application.vendor=Leo +build.classes.dir=${build.dir}/classes +build.classes.excludes=**/*.java,**/*.form +# This directory is removed when the project is cleaned: +build.dir=build +build.generated.dir=${build.dir}/generated +build.generated.sources.dir=${build.dir}/generated-sources +# Only compile against the classpath explicitly listed here: +build.sysclasspath=ignore +build.test.classes.dir=${build.dir}/test/classes +build.test.results.dir=${build.dir}/test/results +# Uncomment to specify the preferred debugger connection transport: +#debug.transport=dt_socket +debug.classpath=\ + ${run.classpath} +debug.test.classpath=\ + ${run.test.classpath} +# This directory is removed when the project is cleaned: +dist.dir=dist +dist.jar=${dist.dir}/path_07.jar +dist.javadoc.dir=${dist.dir}/javadoc +endorsed.classpath= +excludes= +includes=** +jar.compress=false +javac.classpath= +# Space-separated list of extra javac options +javac.compilerargs= +javac.deprecation=false +javac.processorpath=\ + ${javac.classpath} +javac.source=1.7 +javac.target=1.7 +javac.test.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir}:\ + ${libs.junit.classpath}:\ + ${libs.junit_4.classpath} +javac.test.processorpath=\ + ${javac.test.classpath} +javadoc.additionalparam= +javadoc.author=false +javadoc.encoding=${source.encoding} +javadoc.noindex=false +javadoc.nonavbar=false +javadoc.notree=false +javadoc.private=false +javadoc.splitindex=true +javadoc.use=true +javadoc.version=false +javadoc.windowtitle= +main.class=path_07.Main +manifest.file=manifest.mf +meta.inf.dir=${src.dir}/META-INF +mkdist.disabled=false +platform.active=JDK_1.7 +run.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +# Space-separated list of JVM arguments used when running the project +# (you may also define separate properties like run-sys-prop.name=value instead of -Dname=value +# or test-sys-prop.name=value to set system properties for unit tests): +run.jvmargs= +run.test.classpath=\ + ${javac.test.classpath}:\ + ${build.test.classes.dir} +source.encoding=UTF-8 +src.dir=src +test.src.dir=test diff --git a/Pro Java 7 NIO.2/Chapter01/path/path_07/nbproject/project.xml b/Pro Java 7 NIO.2/Chapter01/path/path_07/nbproject/project.xml new file mode 100644 index 0000000..88eea17 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter01/path/path_07/nbproject/project.xml @@ -0,0 +1,19 @@ + + + org.netbeans.modules.java.j2seproject + + + path_07 + + + + + + + + + + .\lib\nblibraries.properties + + + diff --git a/Pro Java 7 NIO.2/Chapter01/path/path_07/src/path_07/Main.java b/Pro Java 7 NIO.2/Chapter01/path/path_07/src/path_07/Main.java new file mode 100644 index 0000000..48c3d6a --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter01/path/path_07/src/path_07/Main.java @@ -0,0 +1,20 @@ +package path_07; + +import java.nio.file.Path; +import java.nio.file.Paths; + +/** + * + * @author Apress + */ +public class Main { + + public static void main(String[] args) { + + Path path = Paths.get("C:", "rafaelnadal/tournaments/2009", "BNP.txt"); + + for (Path name : path) { + System.out.println(name); + } + } +} diff --git a/Pro Java 7 NIO.2/Chapter02/attrs/atrrs_1/build.xml b/Pro Java 7 NIO.2/Chapter02/attrs/atrrs_1/build.xml new file mode 100644 index 0000000..5fe1f9d --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter02/attrs/atrrs_1/build.xml @@ -0,0 +1,74 @@ + + + + + + + + + + + Builds, tests, and runs the project atrrs_1. + + + diff --git a/Pro Java 7 NIO.2/Chapter02/attrs/atrrs_1/build/built-jar.properties b/Pro Java 7 NIO.2/Chapter02/attrs/atrrs_1/build/built-jar.properties new file mode 100644 index 0000000..50bfc53 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter02/attrs/atrrs_1/build/built-jar.properties @@ -0,0 +1,4 @@ +#Sun, 16 Oct 2011 16:07:04 +0200 + + +C\:\\NIO\\attrs\\atrrs_1= diff --git a/Pro Java 7 NIO.2/Chapter02/attrs/atrrs_1/build/classes/.netbeans_automatic_build b/Pro Java 7 NIO.2/Chapter02/attrs/atrrs_1/build/classes/.netbeans_automatic_build new file mode 100644 index 0000000..e69de29 diff --git a/Pro Java 7 NIO.2/Chapter02/attrs/atrrs_1/build/classes/atrrs_1/Main.class b/Pro Java 7 NIO.2/Chapter02/attrs/atrrs_1/build/classes/atrrs_1/Main.class new file mode 100644 index 0000000..115687e Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter02/attrs/atrrs_1/build/classes/atrrs_1/Main.class differ diff --git a/Pro Java 7 NIO.2/Chapter02/attrs/atrrs_1/dist/README.TXT b/Pro Java 7 NIO.2/Chapter02/attrs/atrrs_1/dist/README.TXT new file mode 100644 index 0000000..78bed7d --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter02/attrs/atrrs_1/dist/README.TXT @@ -0,0 +1,32 @@ +======================== +BUILD OUTPUT DESCRIPTION +======================== + +When you build an Java application project that has a main class, the IDE +automatically copies all of the JAR +files on the projects classpath to your projects dist/lib folder. The IDE +also adds each of the JAR files to the Class-Path element in the application +JAR files manifest file (MANIFEST.MF). + +To run the project from the command line, go to the dist folder and +type the following: + +java -jar "atrrs_1.jar" + +To distribute this project, zip up the dist folder (including the lib folder) +and distribute the ZIP file. + +Notes: + +* If two JAR files on the project classpath have the same name, only the first +JAR file is copied to the lib folder. +* Only JAR files are copied to the lib folder. +If the classpath contains other types of files or folders, these files (folders) +are not copied. +* If a library on the projects classpath also has a Class-Path element +specified in the manifest,the content of the Class-Path element has to be on +the projects runtime path. +* To set a main class in a standard Java project, right-click the project node +in the Projects window and choose Properties. Then click Run and enter the +class name in the Main Class field. Alternatively, you can manually type the +class name in the manifest Main-Class element. diff --git a/Pro Java 7 NIO.2/Chapter02/attrs/atrrs_1/dist/atrrs_1.jar b/Pro Java 7 NIO.2/Chapter02/attrs/atrrs_1/dist/atrrs_1.jar new file mode 100644 index 0000000..ec52001 Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter02/attrs/atrrs_1/dist/atrrs_1.jar differ diff --git a/Pro Java 7 NIO.2/Chapter02/attrs/atrrs_1/manifest.mf b/Pro Java 7 NIO.2/Chapter02/attrs/atrrs_1/manifest.mf new file mode 100644 index 0000000..328e8e5 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter02/attrs/atrrs_1/manifest.mf @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +X-COMMENT: Main-Class will be added automatically by build + diff --git a/Pro Java 7 NIO.2/Chapter02/attrs/atrrs_1/nbproject/build-impl.xml b/Pro Java 7 NIO.2/Chapter02/attrs/atrrs_1/nbproject/build-impl.xml new file mode 100644 index 0000000..63a6e8c --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter02/attrs/atrrs_1/nbproject/build-impl.xml @@ -0,0 +1,1041 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set src.dir + Must set test.src.dir + Must set build.dir + Must set dist.dir + Must set build.classes.dir + Must set dist.javadoc.dir + Must set build.test.classes.dir + Must set build.test.results.dir + Must set build.classes.excludes + Must set dist.jar + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set JVM to use for profiling in profiler.info.jvm + Must set profiler agent JVM arguments in profiler.info.jvmargs.agent + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + + + + + + java -cp "${run.classpath.with.dist.jar}" ${main.class} + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + java -jar "${dist.jar.resolved}" + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set run.class + + + + Must select one file in the IDE or set run.class + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set debug.class + + + + + Must select one file in the IDE or set debug.class + + + + + Must set fix.includes + + + + + + + + + + + + + + + + + Must select one file in the IDE or set profile.class + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + Some tests failed; see details above. + + + + + + + + + Must select some files in the IDE or set test.includes + + + + Some tests failed; see details above. + + + + + Must select one file in the IDE or set test.class + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Pro Java 7 NIO.2/Chapter02/attrs/atrrs_1/nbproject/genfiles.properties b/Pro Java 7 NIO.2/Chapter02/attrs/atrrs_1/nbproject/genfiles.properties new file mode 100644 index 0000000..52efacf --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter02/attrs/atrrs_1/nbproject/genfiles.properties @@ -0,0 +1,8 @@ +build.xml.data.CRC32=265f20ee +build.xml.script.CRC32=6e59121c +build.xml.stylesheet.CRC32=28e38971@1.43.1.45 +# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. +# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. +nbproject/build-impl.xml.data.CRC32=265f20ee +nbproject/build-impl.xml.script.CRC32=21d2e3e3 +nbproject/build-impl.xml.stylesheet.CRC32=0c01fd8e@1.43.1.45 diff --git a/Pro Java 7 NIO.2/Chapter02/attrs/atrrs_1/nbproject/private/config.properties b/Pro Java 7 NIO.2/Chapter02/attrs/atrrs_1/nbproject/private/config.properties new file mode 100644 index 0000000..e69de29 diff --git a/Pro Java 7 NIO.2/Chapter02/attrs/atrrs_1/nbproject/private/private.properties b/Pro Java 7 NIO.2/Chapter02/attrs/atrrs_1/nbproject/private/private.properties new file mode 100644 index 0000000..a5ab360 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter02/attrs/atrrs_1/nbproject/private/private.properties @@ -0,0 +1,6 @@ +compile.on.save=true +do.depend=false +do.jar=true +javac.debug=true +javadoc.preview=true +user.properties.file=C:\\Users\\Leo\\.netbeans\\7.0\\build.properties diff --git a/Pro Java 7 NIO.2/Chapter02/attrs/atrrs_1/nbproject/private/private.xml b/Pro Java 7 NIO.2/Chapter02/attrs/atrrs_1/nbproject/private/private.xml new file mode 100644 index 0000000..c1f155a --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter02/attrs/atrrs_1/nbproject/private/private.xml @@ -0,0 +1,4 @@ + + + + diff --git a/Pro Java 7 NIO.2/Chapter02/attrs/atrrs_1/nbproject/project.properties b/Pro Java 7 NIO.2/Chapter02/attrs/atrrs_1/nbproject/project.properties new file mode 100644 index 0000000..55a793d --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter02/attrs/atrrs_1/nbproject/project.properties @@ -0,0 +1,72 @@ +annotation.processing.enabled=true +annotation.processing.enabled.in.editor=false +annotation.processing.run.all.processors=true +annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output +application.title=atrrs_1 +application.vendor=Leo +build.classes.dir=${build.dir}/classes +build.classes.excludes=**/*.java,**/*.form +# This directory is removed when the project is cleaned: +build.dir=build +build.generated.dir=${build.dir}/generated +build.generated.sources.dir=${build.dir}/generated-sources +# Only compile against the classpath explicitly listed here: +build.sysclasspath=ignore +build.test.classes.dir=${build.dir}/test/classes +build.test.results.dir=${build.dir}/test/results +# Uncomment to specify the preferred debugger connection transport: +#debug.transport=dt_socket +debug.classpath=\ + ${run.classpath} +debug.test.classpath=\ + ${run.test.classpath} +# This directory is removed when the project is cleaned: +dist.dir=dist +dist.jar=${dist.dir}/atrrs_1.jar +dist.javadoc.dir=${dist.dir}/javadoc +endorsed.classpath= +excludes= +includes=** +jar.compress=false +javac.classpath= +# Space-separated list of extra javac options +javac.compilerargs= +javac.deprecation=false +javac.processorpath=\ + ${javac.classpath} +javac.source=1.7 +javac.target=1.7 +javac.test.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +javac.test.processorpath=\ + ${javac.test.classpath} +javadoc.additionalparam= +javadoc.author=false +javadoc.encoding=${source.encoding} +javadoc.noindex=false +javadoc.nonavbar=false +javadoc.notree=false +javadoc.private=false +javadoc.splitindex=true +javadoc.use=true +javadoc.version=false +javadoc.windowtitle= +main.class=atrrs_1.Main +manifest.file=manifest.mf +meta.inf.dir=${src.dir}/META-INF +mkdist.disabled=false +platform.active=default_platform +run.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +# Space-separated list of JVM arguments used when running the project +# (you may also define separate properties like run-sys-prop.name=value instead of -Dname=value +# or test-sys-prop.name=value to set system properties for unit tests): +run.jvmargs= +run.test.classpath=\ + ${javac.test.classpath}:\ + ${build.test.classes.dir} +source.encoding=UTF-8 +src.dir=src +test.src.dir=test diff --git a/Pro Java 7 NIO.2/Chapter02/attrs/atrrs_1/nbproject/project.xml b/Pro Java 7 NIO.2/Chapter02/attrs/atrrs_1/nbproject/project.xml new file mode 100644 index 0000000..2beba75 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter02/attrs/atrrs_1/nbproject/project.xml @@ -0,0 +1,15 @@ + + + org.netbeans.modules.java.j2seproject + + + atrrs_1 + + + + + + + + + diff --git a/Pro Java 7 NIO.2/Chapter02/attrs/atrrs_1/src/atrrs_1/Main.java b/Pro Java 7 NIO.2/Chapter02/attrs/atrrs_1/src/atrrs_1/Main.java new file mode 100644 index 0000000..780ace7 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter02/attrs/atrrs_1/src/atrrs_1/Main.java @@ -0,0 +1,73 @@ +package atrrs_1; + +import java.nio.file.attribute.BasicFileAttributeView; +import java.nio.file.attribute.FileTime; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.nio.file.attribute.BasicFileAttributes; +import static java.nio.file.LinkOption.NOFOLLOW_LINKS; + +/** + * + * @author Apress + */ +public class Main { + + public static void main(String[] args) { + + BasicFileAttributes attr = null; + Path path = Paths.get("C:/rafaelnadal/tournaments/2009", "BNP.txt"); + + //extract attributes as bulk with readAttributes + try { + attr = Files.readAttributes(path, BasicFileAttributes.class); + } catch (IOException e) { + System.err.println(e); + } + + System.out.println("File size: " + attr.size()); + System.out.println("File creation time: " + attr.creationTime()); + System.out.println("File was last time accessed at: " + attr.lastAccessTime()); + System.out.println("File was last time modified at: " + attr.lastModifiedTime()); + + System.out.println("Is directory ? " + attr.isDirectory()); + System.out.println("Is regular file ? " + attr.isRegularFile()); + System.out.println("Is symbolic link ? " + attr.isSymbolicLink()); + System.out.println("Is other ? " + attr.isOther()); + + //extract a single attribute with getAttribute + try { + long size = (Long) Files.getAttribute(path, "basic:size", NOFOLLOW_LINKS); + System.out.println("Size: " + size); + } catch (IOException e) { + System.err.println(e); + } + + //update any or all of the file's last modified time, last access time, and create time attributes + long time = System.currentTimeMillis(); + FileTime fileTime = FileTime.fromMillis(time); + try { + Files.getFileAttributeView(path, BasicFileAttributeView.class).setTimes(fileTime, fileTime, fileTime); + } catch (IOException e) { + System.err.println(e); + } + + //update the file's last modified time with the setLastModifiedTime method + try { + Files.setLastModifiedTime(path, fileTime); + } catch (IOException e) { + System.err.println(e); + } + + //update the file's last modified time with the setAttribute method + try { + Files.setAttribute(path, "basic:lastModifiedTime", fileTime, NOFOLLOW_LINKS); + Files.setAttribute(path, "basic:creationTime", fileTime, NOFOLLOW_LINKS); + Files.setAttribute(path, "basic:lastAccessTime", fileTime, NOFOLLOW_LINKS); + } catch (IOException e) { + System.err.println(e); + } + } +} diff --git a/Pro Java 7 NIO.2/Chapter02/attrs/attrs_2/build.xml b/Pro Java 7 NIO.2/Chapter02/attrs/attrs_2/build.xml new file mode 100644 index 0000000..51dd300 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter02/attrs/attrs_2/build.xml @@ -0,0 +1,74 @@ + + + + + + + + + + + Builds, tests, and runs the project attrs_2. + + + diff --git a/Pro Java 7 NIO.2/Chapter02/attrs/attrs_2/build/built-jar.properties b/Pro Java 7 NIO.2/Chapter02/attrs/attrs_2/build/built-jar.properties new file mode 100644 index 0000000..8553034 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter02/attrs/attrs_2/build/built-jar.properties @@ -0,0 +1,4 @@ +#Sun, 16 Oct 2011 16:08:59 +0200 + + +C\:\\NIO\\attrs\\attrs_2= diff --git a/Pro Java 7 NIO.2/Chapter02/attrs/attrs_2/build/classes/attrs_2/Main.class b/Pro Java 7 NIO.2/Chapter02/attrs/attrs_2/build/classes/attrs_2/Main.class new file mode 100644 index 0000000..ed2913e Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter02/attrs/attrs_2/build/classes/attrs_2/Main.class differ diff --git a/Pro Java 7 NIO.2/Chapter02/attrs/attrs_2/dist/README.TXT b/Pro Java 7 NIO.2/Chapter02/attrs/attrs_2/dist/README.TXT new file mode 100644 index 0000000..251582b --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter02/attrs/attrs_2/dist/README.TXT @@ -0,0 +1,32 @@ +======================== +BUILD OUTPUT DESCRIPTION +======================== + +When you build an Java application project that has a main class, the IDE +automatically copies all of the JAR +files on the projects classpath to your projects dist/lib folder. The IDE +also adds each of the JAR files to the Class-Path element in the application +JAR files manifest file (MANIFEST.MF). + +To run the project from the command line, go to the dist folder and +type the following: + +java -jar "attrs_2.jar" + +To distribute this project, zip up the dist folder (including the lib folder) +and distribute the ZIP file. + +Notes: + +* If two JAR files on the project classpath have the same name, only the first +JAR file is copied to the lib folder. +* Only JAR files are copied to the lib folder. +If the classpath contains other types of files or folders, these files (folders) +are not copied. +* If a library on the projects classpath also has a Class-Path element +specified in the manifest,the content of the Class-Path element has to be on +the projects runtime path. +* To set a main class in a standard Java project, right-click the project node +in the Projects window and choose Properties. Then click Run and enter the +class name in the Main Class field. Alternatively, you can manually type the +class name in the manifest Main-Class element. diff --git a/Pro Java 7 NIO.2/Chapter02/attrs/attrs_2/dist/attrs_2.jar b/Pro Java 7 NIO.2/Chapter02/attrs/attrs_2/dist/attrs_2.jar new file mode 100644 index 0000000..425f213 Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter02/attrs/attrs_2/dist/attrs_2.jar differ diff --git a/Pro Java 7 NIO.2/Chapter02/attrs/attrs_2/manifest.mf b/Pro Java 7 NIO.2/Chapter02/attrs/attrs_2/manifest.mf new file mode 100644 index 0000000..328e8e5 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter02/attrs/attrs_2/manifest.mf @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +X-COMMENT: Main-Class will be added automatically by build + diff --git a/Pro Java 7 NIO.2/Chapter02/attrs/attrs_2/nbproject/build-impl.xml b/Pro Java 7 NIO.2/Chapter02/attrs/attrs_2/nbproject/build-impl.xml new file mode 100644 index 0000000..9996bbc --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter02/attrs/attrs_2/nbproject/build-impl.xml @@ -0,0 +1,1041 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set src.dir + Must set test.src.dir + Must set build.dir + Must set dist.dir + Must set build.classes.dir + Must set dist.javadoc.dir + Must set build.test.classes.dir + Must set build.test.results.dir + Must set build.classes.excludes + Must set dist.jar + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set JVM to use for profiling in profiler.info.jvm + Must set profiler agent JVM arguments in profiler.info.jvmargs.agent + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + + + + + + java -cp "${run.classpath.with.dist.jar}" ${main.class} + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + java -jar "${dist.jar.resolved}" + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set run.class + + + + Must select one file in the IDE or set run.class + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set debug.class + + + + + Must select one file in the IDE or set debug.class + + + + + Must set fix.includes + + + + + + + + + + + + + + + + + Must select one file in the IDE or set profile.class + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + Some tests failed; see details above. + + + + + + + + + Must select some files in the IDE or set test.includes + + + + Some tests failed; see details above. + + + + + Must select one file in the IDE or set test.class + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Pro Java 7 NIO.2/Chapter02/attrs/attrs_2/nbproject/genfiles.properties b/Pro Java 7 NIO.2/Chapter02/attrs/attrs_2/nbproject/genfiles.properties new file mode 100644 index 0000000..5afea89 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter02/attrs/attrs_2/nbproject/genfiles.properties @@ -0,0 +1,8 @@ +build.xml.data.CRC32=33e56d50 +build.xml.script.CRC32=d5b19446 +build.xml.stylesheet.CRC32=28e38971@1.43.1.45 +# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. +# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. +nbproject/build-impl.xml.data.CRC32=33e56d50 +nbproject/build-impl.xml.script.CRC32=68126a8f +nbproject/build-impl.xml.stylesheet.CRC32=0c01fd8e@1.43.1.45 diff --git a/Pro Java 7 NIO.2/Chapter02/attrs/attrs_2/nbproject/private/config.properties b/Pro Java 7 NIO.2/Chapter02/attrs/attrs_2/nbproject/private/config.properties new file mode 100644 index 0000000..e69de29 diff --git a/Pro Java 7 NIO.2/Chapter02/attrs/attrs_2/nbproject/private/private.properties b/Pro Java 7 NIO.2/Chapter02/attrs/attrs_2/nbproject/private/private.properties new file mode 100644 index 0000000..a5ab360 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter02/attrs/attrs_2/nbproject/private/private.properties @@ -0,0 +1,6 @@ +compile.on.save=true +do.depend=false +do.jar=true +javac.debug=true +javadoc.preview=true +user.properties.file=C:\\Users\\Leo\\.netbeans\\7.0\\build.properties diff --git a/Pro Java 7 NIO.2/Chapter02/attrs/attrs_2/nbproject/private/private.xml b/Pro Java 7 NIO.2/Chapter02/attrs/attrs_2/nbproject/private/private.xml new file mode 100644 index 0000000..c1f155a --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter02/attrs/attrs_2/nbproject/private/private.xml @@ -0,0 +1,4 @@ + + + + diff --git a/Pro Java 7 NIO.2/Chapter02/attrs/attrs_2/nbproject/project.properties b/Pro Java 7 NIO.2/Chapter02/attrs/attrs_2/nbproject/project.properties new file mode 100644 index 0000000..71a75ea --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter02/attrs/attrs_2/nbproject/project.properties @@ -0,0 +1,72 @@ +annotation.processing.enabled=true +annotation.processing.enabled.in.editor=false +annotation.processing.run.all.processors=true +annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output +application.title=attrs_2 +application.vendor=Leo +build.classes.dir=${build.dir}/classes +build.classes.excludes=**/*.java,**/*.form +# This directory is removed when the project is cleaned: +build.dir=build +build.generated.dir=${build.dir}/generated +build.generated.sources.dir=${build.dir}/generated-sources +# Only compile against the classpath explicitly listed here: +build.sysclasspath=ignore +build.test.classes.dir=${build.dir}/test/classes +build.test.results.dir=${build.dir}/test/results +# Uncomment to specify the preferred debugger connection transport: +#debug.transport=dt_socket +debug.classpath=\ + ${run.classpath} +debug.test.classpath=\ + ${run.test.classpath} +# This directory is removed when the project is cleaned: +dist.dir=dist +dist.jar=${dist.dir}/attrs_2.jar +dist.javadoc.dir=${dist.dir}/javadoc +endorsed.classpath= +excludes= +includes=** +jar.compress=false +javac.classpath= +# Space-separated list of extra javac options +javac.compilerargs= +javac.deprecation=false +javac.processorpath=\ + ${javac.classpath} +javac.source=1.7 +javac.target=1.7 +javac.test.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +javac.test.processorpath=\ + ${javac.test.classpath} +javadoc.additionalparam= +javadoc.author=false +javadoc.encoding=${source.encoding} +javadoc.noindex=false +javadoc.nonavbar=false +javadoc.notree=false +javadoc.private=false +javadoc.splitindex=true +javadoc.use=true +javadoc.version=false +javadoc.windowtitle= +main.class=attrs_2.Main +manifest.file=manifest.mf +meta.inf.dir=${src.dir}/META-INF +mkdist.disabled=false +platform.active=default_platform +run.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +# Space-separated list of JVM arguments used when running the project +# (you may also define separate properties like run-sys-prop.name=value instead of -Dname=value +# or test-sys-prop.name=value to set system properties for unit tests): +run.jvmargs= +run.test.classpath=\ + ${javac.test.classpath}:\ + ${build.test.classes.dir} +source.encoding=UTF-8 +src.dir=src +test.src.dir=test diff --git a/Pro Java 7 NIO.2/Chapter02/attrs/attrs_2/nbproject/project.xml b/Pro Java 7 NIO.2/Chapter02/attrs/attrs_2/nbproject/project.xml new file mode 100644 index 0000000..428e053 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter02/attrs/attrs_2/nbproject/project.xml @@ -0,0 +1,15 @@ + + + org.netbeans.modules.java.j2seproject + + + attrs_2 + + + + + + + + + diff --git a/Pro Java 7 NIO.2/Chapter02/attrs/attrs_2/src/attrs_2/Main.java b/Pro Java 7 NIO.2/Chapter02/attrs/attrs_2/src/attrs_2/Main.java new file mode 100644 index 0000000..7397b34 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter02/attrs/attrs_2/src/attrs_2/Main.java @@ -0,0 +1,46 @@ +package attrs_2; + +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.nio.file.attribute.DosFileAttributes; +import static java.nio.file.LinkOption.NOFOLLOW_LINKS; + +/** + * + * @author Apress + */ +public class Main { + + public static void main(String[] args) { + + DosFileAttributes attr = null; + Path path = Paths.get("C:/rafaelnadal/tournaments/2009", "BNP.txt"); + + try { + attr = Files.readAttributes(path, DosFileAttributes.class); + } catch (IOException e) { + System.err.println(e); + } + System.out.println("Is read only ? " + attr.isReadOnly()); + System.out.println("Is Hidden ? " + attr.isHidden()); + System.out.println("Is archive ? " + attr.isArchive()); + System.out.println("Is system ? " + attr.isSystem()); + + //setting the hidden attribute to true + try { + Files.setAttribute(path, "dos:hidden", true, NOFOLLOW_LINKS); + } catch (IOException e) { + System.err.println(e); + } + + //getting the hidden attribute + try { + boolean hidden = (Boolean) Files.getAttribute(path, "dos:hidden", NOFOLLOW_LINKS); + System.out.println("Is hidden ? " + hidden); + } catch (IOException e) { + System.err.println(e); + } + } +} diff --git a/Pro Java 7 NIO.2/Chapter02/attrs/attrs_3/build.xml b/Pro Java 7 NIO.2/Chapter02/attrs/attrs_3/build.xml new file mode 100644 index 0000000..945010e --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter02/attrs/attrs_3/build.xml @@ -0,0 +1,74 @@ + + + + + + + + + + + Builds, tests, and runs the project attrs_3. + + + diff --git a/Pro Java 7 NIO.2/Chapter02/attrs/attrs_3/build/built-jar.properties b/Pro Java 7 NIO.2/Chapter02/attrs/attrs_3/build/built-jar.properties new file mode 100644 index 0000000..6a504f2 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter02/attrs/attrs_3/build/built-jar.properties @@ -0,0 +1,4 @@ +#Sun, 16 Oct 2011 16:10:35 +0200 + + +C\:\\NIO\\attrs\\attrs_3= diff --git a/Pro Java 7 NIO.2/Chapter02/attrs/attrs_3/build/classes/attrs_3/Main.class b/Pro Java 7 NIO.2/Chapter02/attrs/attrs_3/build/classes/attrs_3/Main.class new file mode 100644 index 0000000..3faae0e Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter02/attrs/attrs_3/build/classes/attrs_3/Main.class differ diff --git a/Pro Java 7 NIO.2/Chapter02/attrs/attrs_3/dist/README.TXT b/Pro Java 7 NIO.2/Chapter02/attrs/attrs_3/dist/README.TXT new file mode 100644 index 0000000..78b2dbc --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter02/attrs/attrs_3/dist/README.TXT @@ -0,0 +1,32 @@ +======================== +BUILD OUTPUT DESCRIPTION +======================== + +When you build an Java application project that has a main class, the IDE +automatically copies all of the JAR +files on the projects classpath to your projects dist/lib folder. The IDE +also adds each of the JAR files to the Class-Path element in the application +JAR files manifest file (MANIFEST.MF). + +To run the project from the command line, go to the dist folder and +type the following: + +java -jar "attrs_3.jar" + +To distribute this project, zip up the dist folder (including the lib folder) +and distribute the ZIP file. + +Notes: + +* If two JAR files on the project classpath have the same name, only the first +JAR file is copied to the lib folder. +* Only JAR files are copied to the lib folder. +If the classpath contains other types of files or folders, these files (folders) +are not copied. +* If a library on the projects classpath also has a Class-Path element +specified in the manifest,the content of the Class-Path element has to be on +the projects runtime path. +* To set a main class in a standard Java project, right-click the project node +in the Projects window and choose Properties. Then click Run and enter the +class name in the Main Class field. Alternatively, you can manually type the +class name in the manifest Main-Class element. diff --git a/Pro Java 7 NIO.2/Chapter02/attrs/attrs_3/dist/attrs_3.jar b/Pro Java 7 NIO.2/Chapter02/attrs/attrs_3/dist/attrs_3.jar new file mode 100644 index 0000000..e8a8385 Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter02/attrs/attrs_3/dist/attrs_3.jar differ diff --git a/Pro Java 7 NIO.2/Chapter02/attrs/attrs_3/manifest.mf b/Pro Java 7 NIO.2/Chapter02/attrs/attrs_3/manifest.mf new file mode 100644 index 0000000..328e8e5 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter02/attrs/attrs_3/manifest.mf @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +X-COMMENT: Main-Class will be added automatically by build + diff --git a/Pro Java 7 NIO.2/Chapter02/attrs/attrs_3/nbproject/build-impl.xml b/Pro Java 7 NIO.2/Chapter02/attrs/attrs_3/nbproject/build-impl.xml new file mode 100644 index 0000000..d5bc0c7 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter02/attrs/attrs_3/nbproject/build-impl.xml @@ -0,0 +1,1041 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set src.dir + Must set test.src.dir + Must set build.dir + Must set dist.dir + Must set build.classes.dir + Must set dist.javadoc.dir + Must set build.test.classes.dir + Must set build.test.results.dir + Must set build.classes.excludes + Must set dist.jar + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set JVM to use for profiling in profiler.info.jvm + Must set profiler agent JVM arguments in profiler.info.jvmargs.agent + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + + + + + + java -cp "${run.classpath.with.dist.jar}" ${main.class} + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + java -jar "${dist.jar.resolved}" + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set run.class + + + + Must select one file in the IDE or set run.class + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set debug.class + + + + + Must select one file in the IDE or set debug.class + + + + + Must set fix.includes + + + + + + + + + + + + + + + + + Must select one file in the IDE or set profile.class + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + Some tests failed; see details above. + + + + + + + + + Must select some files in the IDE or set test.includes + + + + Some tests failed; see details above. + + + + + Must select one file in the IDE or set test.class + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Pro Java 7 NIO.2/Chapter02/attrs/attrs_3/nbproject/genfiles.properties b/Pro Java 7 NIO.2/Chapter02/attrs/attrs_3/nbproject/genfiles.properties new file mode 100644 index 0000000..e883d82 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter02/attrs/attrs_3/nbproject/genfiles.properties @@ -0,0 +1,8 @@ +build.xml.data.CRC32=3bf6e176 +build.xml.script.CRC32=de922d05 +build.xml.stylesheet.CRC32=28e38971@1.43.1.45 +# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. +# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. +nbproject/build-impl.xml.data.CRC32=3bf6e176 +nbproject/build-impl.xml.script.CRC32=d230553c +nbproject/build-impl.xml.stylesheet.CRC32=0c01fd8e@1.43.1.45 diff --git a/Pro Java 7 NIO.2/Chapter02/attrs/attrs_3/nbproject/private/config.properties b/Pro Java 7 NIO.2/Chapter02/attrs/attrs_3/nbproject/private/config.properties new file mode 100644 index 0000000..e69de29 diff --git a/Pro Java 7 NIO.2/Chapter02/attrs/attrs_3/nbproject/private/private.properties b/Pro Java 7 NIO.2/Chapter02/attrs/attrs_3/nbproject/private/private.properties new file mode 100644 index 0000000..a5ab360 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter02/attrs/attrs_3/nbproject/private/private.properties @@ -0,0 +1,6 @@ +compile.on.save=true +do.depend=false +do.jar=true +javac.debug=true +javadoc.preview=true +user.properties.file=C:\\Users\\Leo\\.netbeans\\7.0\\build.properties diff --git a/Pro Java 7 NIO.2/Chapter02/attrs/attrs_3/nbproject/private/private.xml b/Pro Java 7 NIO.2/Chapter02/attrs/attrs_3/nbproject/private/private.xml new file mode 100644 index 0000000..c1f155a --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter02/attrs/attrs_3/nbproject/private/private.xml @@ -0,0 +1,4 @@ + + + + diff --git a/Pro Java 7 NIO.2/Chapter02/attrs/attrs_3/nbproject/project.properties b/Pro Java 7 NIO.2/Chapter02/attrs/attrs_3/nbproject/project.properties new file mode 100644 index 0000000..96baaec --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter02/attrs/attrs_3/nbproject/project.properties @@ -0,0 +1,72 @@ +annotation.processing.enabled=true +annotation.processing.enabled.in.editor=false +annotation.processing.run.all.processors=true +annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output +application.title=attrs_3 +application.vendor=Leo +build.classes.dir=${build.dir}/classes +build.classes.excludes=**/*.java,**/*.form +# This directory is removed when the project is cleaned: +build.dir=build +build.generated.dir=${build.dir}/generated +build.generated.sources.dir=${build.dir}/generated-sources +# Only compile against the classpath explicitly listed here: +build.sysclasspath=ignore +build.test.classes.dir=${build.dir}/test/classes +build.test.results.dir=${build.dir}/test/results +# Uncomment to specify the preferred debugger connection transport: +#debug.transport=dt_socket +debug.classpath=\ + ${run.classpath} +debug.test.classpath=\ + ${run.test.classpath} +# This directory is removed when the project is cleaned: +dist.dir=dist +dist.jar=${dist.dir}/attrs_3.jar +dist.javadoc.dir=${dist.dir}/javadoc +endorsed.classpath= +excludes= +includes=** +jar.compress=false +javac.classpath= +# Space-separated list of extra javac options +javac.compilerargs= +javac.deprecation=false +javac.processorpath=\ + ${javac.classpath} +javac.source=1.7 +javac.target=1.7 +javac.test.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +javac.test.processorpath=\ + ${javac.test.classpath} +javadoc.additionalparam= +javadoc.author=false +javadoc.encoding=${source.encoding} +javadoc.noindex=false +javadoc.nonavbar=false +javadoc.notree=false +javadoc.private=false +javadoc.splitindex=true +javadoc.use=true +javadoc.version=false +javadoc.windowtitle= +main.class=attrs_3.Main +manifest.file=manifest.mf +meta.inf.dir=${src.dir}/META-INF +mkdist.disabled=false +platform.active=default_platform +run.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +# Space-separated list of JVM arguments used when running the project +# (you may also define separate properties like run-sys-prop.name=value instead of -Dname=value +# or test-sys-prop.name=value to set system properties for unit tests): +run.jvmargs= +run.test.classpath=\ + ${javac.test.classpath}:\ + ${build.test.classes.dir} +source.encoding=UTF-8 +src.dir=src +test.src.dir=test diff --git a/Pro Java 7 NIO.2/Chapter02/attrs/attrs_3/nbproject/project.xml b/Pro Java 7 NIO.2/Chapter02/attrs/attrs_3/nbproject/project.xml new file mode 100644 index 0000000..57f4631 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter02/attrs/attrs_3/nbproject/project.xml @@ -0,0 +1,15 @@ + + + org.netbeans.modules.java.j2seproject + + + attrs_3 + + + + + + + + + diff --git a/Pro Java 7 NIO.2/Chapter02/attrs/attrs_3/src/attrs_3/Main.java b/Pro Java 7 NIO.2/Chapter02/attrs/attrs_3/src/attrs_3/Main.java new file mode 100644 index 0000000..9eec8ab --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter02/attrs/attrs_3/src/attrs_3/Main.java @@ -0,0 +1,78 @@ +package attrs_3; + +import java.nio.file.attribute.GroupPrincipal; +import java.nio.file.attribute.PosixFileAttributeView; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.nio.file.attribute.FileAttribute; +import java.nio.file.attribute.PosixFileAttributes; +import java.nio.file.attribute.PosixFilePermission; +import java.nio.file.attribute.PosixFilePermissions; +import java.util.Set; +import static java.nio.file.LinkOption.NOFOLLOW_LINKS; + +/** + * + * @author Apress + */ +public class Main { + + public static void main(String[] args) { + + PosixFileAttributes attr = null; + Path path = Paths.get("/home/rafaelnadal/tournaments/2009/BNP.txt"); + Path new_path = Paths.get("/home/rafaelnadal/tournaments/2009/new_BNP.txt"); + + //get POSIX attributes using Files.readAttributes + try { + attr = Files.readAttributes(path, PosixFileAttributes.class); + } catch (IOException e) { + System.err.println(e); + } + + //get POSIX attributes using the Files.getFileAttributeView + try { + attr = Files.getFileAttributeView(path, PosixFileAttributeView.class).readAttributes(); + } catch (IOException e) { + System.err.println(e); + } + + System.out.println("File owner: " + attr.owner().getName()); + System.out.println("File group: " + attr.group().getName()); + System.out.println("File permissions: " + attr.permissions().toString()); + + //use of asFileAttribute + FileAttribute> posixattrs = PosixFilePermissions.asFileAttribute(attr.permissions()); + try { + Files.createFile(new_path, posixattrs); + } catch (IOException e) { + System.err.println(e); + } + + //use of fromString + Set permissions = PosixFilePermissions.fromString("rw-r--r--"); + try { + Files.setPosixFilePermissions(new_path, permissions); + } catch (IOException e) { + System.err.println(e); + } + + //set the file group owner + try { + GroupPrincipal group = path.getFileSystem().getUserPrincipalLookupService().lookupPrincipalByGroupName("apressteam"); + Files.getFileAttributeView(path, PosixFileAttributeView.class).setGroup(group); + } catch (IOException e) { + System.err.println(e); + } + + //get the file group owner + try { + GroupPrincipal group = (GroupPrincipal) Files.getAttribute(path, "posix:group", NOFOLLOW_LINKS); + System.out.println(group.getName()); + } catch (IOException e) { + System.err.println(e); + } + } +} diff --git a/Pro Java 7 NIO.2/Chapter02/attrs/attrs_4/build.xml b/Pro Java 7 NIO.2/Chapter02/attrs/attrs_4/build.xml new file mode 100644 index 0000000..aaeb143 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter02/attrs/attrs_4/build.xml @@ -0,0 +1,74 @@ + + + + + + + + + + + Builds, tests, and runs the project attrs_4. + + + diff --git a/Pro Java 7 NIO.2/Chapter02/attrs/attrs_4/build/built-jar.properties b/Pro Java 7 NIO.2/Chapter02/attrs/attrs_4/build/built-jar.properties new file mode 100644 index 0000000..3f42b52 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter02/attrs/attrs_4/build/built-jar.properties @@ -0,0 +1,4 @@ +#Sun, 16 Oct 2011 16:11:18 +0200 + + +C\:\\NIO\\attrs\\attrs_4= diff --git a/Pro Java 7 NIO.2/Chapter02/attrs/attrs_4/build/classes/.netbeans_automatic_build b/Pro Java 7 NIO.2/Chapter02/attrs/attrs_4/build/classes/.netbeans_automatic_build new file mode 100644 index 0000000..e69de29 diff --git a/Pro Java 7 NIO.2/Chapter02/attrs/attrs_4/build/classes/attrs_4/Main.class b/Pro Java 7 NIO.2/Chapter02/attrs/attrs_4/build/classes/attrs_4/Main.class new file mode 100644 index 0000000..8a0dc26 Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter02/attrs/attrs_4/build/classes/attrs_4/Main.class differ diff --git a/Pro Java 7 NIO.2/Chapter02/attrs/attrs_4/dist/README.TXT b/Pro Java 7 NIO.2/Chapter02/attrs/attrs_4/dist/README.TXT new file mode 100644 index 0000000..ad160dd --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter02/attrs/attrs_4/dist/README.TXT @@ -0,0 +1,32 @@ +======================== +BUILD OUTPUT DESCRIPTION +======================== + +When you build an Java application project that has a main class, the IDE +automatically copies all of the JAR +files on the projects classpath to your projects dist/lib folder. The IDE +also adds each of the JAR files to the Class-Path element in the application +JAR files manifest file (MANIFEST.MF). + +To run the project from the command line, go to the dist folder and +type the following: + +java -jar "attrs_4.jar" + +To distribute this project, zip up the dist folder (including the lib folder) +and distribute the ZIP file. + +Notes: + +* If two JAR files on the project classpath have the same name, only the first +JAR file is copied to the lib folder. +* Only JAR files are copied to the lib folder. +If the classpath contains other types of files or folders, these files (folders) +are not copied. +* If a library on the projects classpath also has a Class-Path element +specified in the manifest,the content of the Class-Path element has to be on +the projects runtime path. +* To set a main class in a standard Java project, right-click the project node +in the Projects window and choose Properties. Then click Run and enter the +class name in the Main Class field. Alternatively, you can manually type the +class name in the manifest Main-Class element. diff --git a/Pro Java 7 NIO.2/Chapter02/attrs/attrs_4/dist/attrs_4.jar b/Pro Java 7 NIO.2/Chapter02/attrs/attrs_4/dist/attrs_4.jar new file mode 100644 index 0000000..d1dc06f Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter02/attrs/attrs_4/dist/attrs_4.jar differ diff --git a/Pro Java 7 NIO.2/Chapter02/attrs/attrs_4/manifest.mf b/Pro Java 7 NIO.2/Chapter02/attrs/attrs_4/manifest.mf new file mode 100644 index 0000000..328e8e5 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter02/attrs/attrs_4/manifest.mf @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +X-COMMENT: Main-Class will be added automatically by build + diff --git a/Pro Java 7 NIO.2/Chapter02/attrs/attrs_4/nbproject/build-impl.xml b/Pro Java 7 NIO.2/Chapter02/attrs/attrs_4/nbproject/build-impl.xml new file mode 100644 index 0000000..9abcdef --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter02/attrs/attrs_4/nbproject/build-impl.xml @@ -0,0 +1,1041 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set src.dir + Must set test.src.dir + Must set build.dir + Must set dist.dir + Must set build.classes.dir + Must set dist.javadoc.dir + Must set build.test.classes.dir + Must set build.test.results.dir + Must set build.classes.excludes + Must set dist.jar + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set JVM to use for profiling in profiler.info.jvm + Must set profiler agent JVM arguments in profiler.info.jvmargs.agent + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + + + + + + java -cp "${run.classpath.with.dist.jar}" ${main.class} + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + java -jar "${dist.jar.resolved}" + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set run.class + + + + Must select one file in the IDE or set run.class + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set debug.class + + + + + Must select one file in the IDE or set debug.class + + + + + Must set fix.includes + + + + + + + + + + + + + + + + + Must select one file in the IDE or set profile.class + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + Some tests failed; see details above. + + + + + + + + + Must select some files in the IDE or set test.includes + + + + Some tests failed; see details above. + + + + + Must select one file in the IDE or set test.class + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Pro Java 7 NIO.2/Chapter02/attrs/attrs_4/nbproject/genfiles.properties b/Pro Java 7 NIO.2/Chapter02/attrs/attrs_4/nbproject/genfiles.properties new file mode 100644 index 0000000..679269f --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter02/attrs/attrs_4/nbproject/genfiles.properties @@ -0,0 +1,8 @@ +build.xml.data.CRC32=038c4584 +build.xml.script.CRC32=ef7803cc +build.xml.stylesheet.CRC32=28e38971@1.43.1.45 +# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. +# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. +nbproject/build-impl.xml.data.CRC32=038c4584 +nbproject/build-impl.xml.script.CRC32=423ce7a7 +nbproject/build-impl.xml.stylesheet.CRC32=0c01fd8e@1.43.1.45 diff --git a/Pro Java 7 NIO.2/Chapter02/attrs/attrs_4/nbproject/private/config.properties b/Pro Java 7 NIO.2/Chapter02/attrs/attrs_4/nbproject/private/config.properties new file mode 100644 index 0000000..e69de29 diff --git a/Pro Java 7 NIO.2/Chapter02/attrs/attrs_4/nbproject/private/private.properties b/Pro Java 7 NIO.2/Chapter02/attrs/attrs_4/nbproject/private/private.properties new file mode 100644 index 0000000..a5ab360 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter02/attrs/attrs_4/nbproject/private/private.properties @@ -0,0 +1,6 @@ +compile.on.save=true +do.depend=false +do.jar=true +javac.debug=true +javadoc.preview=true +user.properties.file=C:\\Users\\Leo\\.netbeans\\7.0\\build.properties diff --git a/Pro Java 7 NIO.2/Chapter02/attrs/attrs_4/nbproject/private/private.xml b/Pro Java 7 NIO.2/Chapter02/attrs/attrs_4/nbproject/private/private.xml new file mode 100644 index 0000000..c1f155a --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter02/attrs/attrs_4/nbproject/private/private.xml @@ -0,0 +1,4 @@ + + + + diff --git a/Pro Java 7 NIO.2/Chapter02/attrs/attrs_4/nbproject/project.properties b/Pro Java 7 NIO.2/Chapter02/attrs/attrs_4/nbproject/project.properties new file mode 100644 index 0000000..e577fb3 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter02/attrs/attrs_4/nbproject/project.properties @@ -0,0 +1,72 @@ +annotation.processing.enabled=true +annotation.processing.enabled.in.editor=false +annotation.processing.run.all.processors=true +annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output +application.title=attrs_4 +application.vendor=Leo +build.classes.dir=${build.dir}/classes +build.classes.excludes=**/*.java,**/*.form +# This directory is removed when the project is cleaned: +build.dir=build +build.generated.dir=${build.dir}/generated +build.generated.sources.dir=${build.dir}/generated-sources +# Only compile against the classpath explicitly listed here: +build.sysclasspath=ignore +build.test.classes.dir=${build.dir}/test/classes +build.test.results.dir=${build.dir}/test/results +# Uncomment to specify the preferred debugger connection transport: +#debug.transport=dt_socket +debug.classpath=\ + ${run.classpath} +debug.test.classpath=\ + ${run.test.classpath} +# This directory is removed when the project is cleaned: +dist.dir=dist +dist.jar=${dist.dir}/attrs_4.jar +dist.javadoc.dir=${dist.dir}/javadoc +endorsed.classpath= +excludes= +includes=** +jar.compress=false +javac.classpath= +# Space-separated list of extra javac options +javac.compilerargs= +javac.deprecation=false +javac.processorpath=\ + ${javac.classpath} +javac.source=1.7 +javac.target=1.7 +javac.test.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +javac.test.processorpath=\ + ${javac.test.classpath} +javadoc.additionalparam= +javadoc.author=false +javadoc.encoding=${source.encoding} +javadoc.noindex=false +javadoc.nonavbar=false +javadoc.notree=false +javadoc.private=false +javadoc.splitindex=true +javadoc.use=true +javadoc.version=false +javadoc.windowtitle= +main.class=attrs_4.Main +manifest.file=manifest.mf +meta.inf.dir=${src.dir}/META-INF +mkdist.disabled=false +platform.active=default_platform +run.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +# Space-separated list of JVM arguments used when running the project +# (you may also define separate properties like run-sys-prop.name=value instead of -Dname=value +# or test-sys-prop.name=value to set system properties for unit tests): +run.jvmargs= +run.test.classpath=\ + ${javac.test.classpath}:\ + ${build.test.classes.dir} +source.encoding=UTF-8 +src.dir=src +test.src.dir=test diff --git a/Pro Java 7 NIO.2/Chapter02/attrs/attrs_4/nbproject/project.xml b/Pro Java 7 NIO.2/Chapter02/attrs/attrs_4/nbproject/project.xml new file mode 100644 index 0000000..0369a7e --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter02/attrs/attrs_4/nbproject/project.xml @@ -0,0 +1,15 @@ + + + org.netbeans.modules.java.j2seproject + + + attrs_4 + + + + + + + + + diff --git a/Pro Java 7 NIO.2/Chapter02/attrs/attrs_4/src/attrs_4/Main.java b/Pro Java 7 NIO.2/Chapter02/attrs/attrs_4/src/attrs_4/Main.java new file mode 100644 index 0000000..95ba84b --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter02/attrs/attrs_4/src/attrs_4/Main.java @@ -0,0 +1,64 @@ +package attrs_4; + +import java.io.IOException; +import java.nio.file.FileStore; +import java.nio.file.FileSystem; +import java.nio.file.FileSystems; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.nio.file.attribute.FileStoreAttributeView; + +/** + * + * @author Apress + */ +public class Main { + + public static void main(String[] args) { + + //get information for all the stores in the default file system + FileSystem fs = FileSystems.getDefault(); + for (FileStore store : fs.getFileStores()) { + try { + long total_space = store.getTotalSpace() / 1024; + long used_space = (store.getTotalSpace() - store.getUnallocatedSpace()) / 1024; + long available_space = store.getUsableSpace() / 1024; + boolean is_read_only = store.isReadOnly(); + + System.out.println("--- " + store.name() + " --- " + store.type()); + System.out.println("Total space: " + total_space); + System.out.println("Used space: " + used_space); + System.out.println("Available space: " + available_space); + System.out.println("Is read only? " + is_read_only); + } catch (IOException e) { + System.err.println(e); + } + } + + //get information about a file store where a particular file resides + Path path = Paths.get("C:/rafaelnadal/tournaments/2009", "BNP.txt"); + try { + FileStore store = Files.getFileStore(path); + + long total_space = store.getTotalSpace() / 1024; + long used_space = (store.getTotalSpace() - store.getUnallocatedSpace()) / 1024; + long available_space = store.getUsableSpace() / 1024; + boolean is_read_only = store.isReadOnly(); + + System.out.println("--- " + store.name() + " --- " + store.type()); + System.out.println("Total space: " + total_space); + System.out.println("Used space: " + used_space); + System.out.println("Available space: " + available_space); + System.out.println("Is read only? " + is_read_only); + } catch (IOException e) { + System.err.println(e); + } + + //get the FileStoreAttributeView + for (FileStore store : fs.getFileStores()) { + FileStoreAttributeView fsav = store.getFileStoreAttributeView(FileStoreAttributeView.class); + System.out.println(fsav); + } + } +} \ No newline at end of file diff --git a/Pro Java 7 NIO.2/Chapter02/attrs/attrs_5/build.xml b/Pro Java 7 NIO.2/Chapter02/attrs/attrs_5/build.xml new file mode 100644 index 0000000..c9d3b2a --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter02/attrs/attrs_5/build.xml @@ -0,0 +1,74 @@ + + + + + + + + + + + Builds, tests, and runs the project attrs_5. + + + diff --git a/Pro Java 7 NIO.2/Chapter02/attrs/attrs_5/build/built-jar.properties b/Pro Java 7 NIO.2/Chapter02/attrs/attrs_5/build/built-jar.properties new file mode 100644 index 0000000..3e73fef --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter02/attrs/attrs_5/build/built-jar.properties @@ -0,0 +1,4 @@ +#Sun, 16 Oct 2011 16:12:54 +0200 + + +C\:\\NIO\\attrs\\attrs_5= diff --git a/Pro Java 7 NIO.2/Chapter02/attrs/attrs_5/build/classes/attrs_5/Main.class b/Pro Java 7 NIO.2/Chapter02/attrs/attrs_5/build/classes/attrs_5/Main.class new file mode 100644 index 0000000..d18eda2 Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter02/attrs/attrs_5/build/classes/attrs_5/Main.class differ diff --git a/Pro Java 7 NIO.2/Chapter02/attrs/attrs_5/dist/README.TXT b/Pro Java 7 NIO.2/Chapter02/attrs/attrs_5/dist/README.TXT new file mode 100644 index 0000000..6215f54 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter02/attrs/attrs_5/dist/README.TXT @@ -0,0 +1,32 @@ +======================== +BUILD OUTPUT DESCRIPTION +======================== + +When you build an Java application project that has a main class, the IDE +automatically copies all of the JAR +files on the projects classpath to your projects dist/lib folder. The IDE +also adds each of the JAR files to the Class-Path element in the application +JAR files manifest file (MANIFEST.MF). + +To run the project from the command line, go to the dist folder and +type the following: + +java -jar "attrs_5.jar" + +To distribute this project, zip up the dist folder (including the lib folder) +and distribute the ZIP file. + +Notes: + +* If two JAR files on the project classpath have the same name, only the first +JAR file is copied to the lib folder. +* Only JAR files are copied to the lib folder. +If the classpath contains other types of files or folders, these files (folders) +are not copied. +* If a library on the projects classpath also has a Class-Path element +specified in the manifest,the content of the Class-Path element has to be on +the projects runtime path. +* To set a main class in a standard Java project, right-click the project node +in the Projects window and choose Properties. Then click Run and enter the +class name in the Main Class field. Alternatively, you can manually type the +class name in the manifest Main-Class element. diff --git a/Pro Java 7 NIO.2/Chapter02/attrs/attrs_5/dist/attrs_5.jar b/Pro Java 7 NIO.2/Chapter02/attrs/attrs_5/dist/attrs_5.jar new file mode 100644 index 0000000..335f164 Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter02/attrs/attrs_5/dist/attrs_5.jar differ diff --git a/Pro Java 7 NIO.2/Chapter02/attrs/attrs_5/manifest.mf b/Pro Java 7 NIO.2/Chapter02/attrs/attrs_5/manifest.mf new file mode 100644 index 0000000..328e8e5 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter02/attrs/attrs_5/manifest.mf @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +X-COMMENT: Main-Class will be added automatically by build + diff --git a/Pro Java 7 NIO.2/Chapter02/attrs/attrs_5/nbproject/build-impl.xml b/Pro Java 7 NIO.2/Chapter02/attrs/attrs_5/nbproject/build-impl.xml new file mode 100644 index 0000000..751a26a --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter02/attrs/attrs_5/nbproject/build-impl.xml @@ -0,0 +1,1041 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set src.dir + Must set test.src.dir + Must set build.dir + Must set dist.dir + Must set build.classes.dir + Must set dist.javadoc.dir + Must set build.test.classes.dir + Must set build.test.results.dir + Must set build.classes.excludes + Must set dist.jar + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set JVM to use for profiling in profiler.info.jvm + Must set profiler agent JVM arguments in profiler.info.jvmargs.agent + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + + + + + + java -cp "${run.classpath.with.dist.jar}" ${main.class} + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + java -jar "${dist.jar.resolved}" + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set run.class + + + + Must select one file in the IDE or set run.class + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set debug.class + + + + + Must select one file in the IDE or set debug.class + + + + + Must set fix.includes + + + + + + + + + + + + + + + + + Must select one file in the IDE or set profile.class + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + Some tests failed; see details above. + + + + + + + + + Must select some files in the IDE or set test.includes + + + + Some tests failed; see details above. + + + + + Must select one file in the IDE or set test.class + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Pro Java 7 NIO.2/Chapter02/attrs/attrs_5/nbproject/genfiles.properties b/Pro Java 7 NIO.2/Chapter02/attrs/attrs_5/nbproject/genfiles.properties new file mode 100644 index 0000000..8f2c509 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter02/attrs/attrs_5/nbproject/genfiles.properties @@ -0,0 +1,8 @@ +build.xml.data.CRC32=0b9fc9a2 +build.xml.script.CRC32=e45bba8f +build.xml.stylesheet.CRC32=28e38971@1.43.1.45 +# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. +# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. +nbproject/build-impl.xml.data.CRC32=0b9fc9a2 +nbproject/build-impl.xml.script.CRC32=f81ed814 +nbproject/build-impl.xml.stylesheet.CRC32=0c01fd8e@1.43.1.45 diff --git a/Pro Java 7 NIO.2/Chapter02/attrs/attrs_5/nbproject/private/config.properties b/Pro Java 7 NIO.2/Chapter02/attrs/attrs_5/nbproject/private/config.properties new file mode 100644 index 0000000..e69de29 diff --git a/Pro Java 7 NIO.2/Chapter02/attrs/attrs_5/nbproject/private/private.properties b/Pro Java 7 NIO.2/Chapter02/attrs/attrs_5/nbproject/private/private.properties new file mode 100644 index 0000000..a5ab360 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter02/attrs/attrs_5/nbproject/private/private.properties @@ -0,0 +1,6 @@ +compile.on.save=true +do.depend=false +do.jar=true +javac.debug=true +javadoc.preview=true +user.properties.file=C:\\Users\\Leo\\.netbeans\\7.0\\build.properties diff --git a/Pro Java 7 NIO.2/Chapter02/attrs/attrs_5/nbproject/private/private.xml b/Pro Java 7 NIO.2/Chapter02/attrs/attrs_5/nbproject/private/private.xml new file mode 100644 index 0000000..c1f155a --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter02/attrs/attrs_5/nbproject/private/private.xml @@ -0,0 +1,4 @@ + + + + diff --git a/Pro Java 7 NIO.2/Chapter02/attrs/attrs_5/nbproject/project.properties b/Pro Java 7 NIO.2/Chapter02/attrs/attrs_5/nbproject/project.properties new file mode 100644 index 0000000..95e56ad --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter02/attrs/attrs_5/nbproject/project.properties @@ -0,0 +1,72 @@ +annotation.processing.enabled=true +annotation.processing.enabled.in.editor=false +annotation.processing.run.all.processors=true +annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output +application.title=attrs_5 +application.vendor=Leo +build.classes.dir=${build.dir}/classes +build.classes.excludes=**/*.java,**/*.form +# This directory is removed when the project is cleaned: +build.dir=build +build.generated.dir=${build.dir}/generated +build.generated.sources.dir=${build.dir}/generated-sources +# Only compile against the classpath explicitly listed here: +build.sysclasspath=ignore +build.test.classes.dir=${build.dir}/test/classes +build.test.results.dir=${build.dir}/test/results +# Uncomment to specify the preferred debugger connection transport: +#debug.transport=dt_socket +debug.classpath=\ + ${run.classpath} +debug.test.classpath=\ + ${run.test.classpath} +# This directory is removed when the project is cleaned: +dist.dir=dist +dist.jar=${dist.dir}/attrs_5.jar +dist.javadoc.dir=${dist.dir}/javadoc +endorsed.classpath= +excludes= +includes=** +jar.compress=false +javac.classpath= +# Space-separated list of extra javac options +javac.compilerargs= +javac.deprecation=false +javac.processorpath=\ + ${javac.classpath} +javac.source=1.7 +javac.target=1.7 +javac.test.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +javac.test.processorpath=\ + ${javac.test.classpath} +javadoc.additionalparam= +javadoc.author=false +javadoc.encoding=${source.encoding} +javadoc.noindex=false +javadoc.nonavbar=false +javadoc.notree=false +javadoc.private=false +javadoc.splitindex=true +javadoc.use=true +javadoc.version=false +javadoc.windowtitle= +main.class=attrs_5.Main +manifest.file=manifest.mf +meta.inf.dir=${src.dir}/META-INF +mkdist.disabled=false +platform.active=default_platform +run.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +# Space-separated list of JVM arguments used when running the project +# (you may also define separate properties like run-sys-prop.name=value instead of -Dname=value +# or test-sys-prop.name=value to set system properties for unit tests): +run.jvmargs= +run.test.classpath=\ + ${javac.test.classpath}:\ + ${build.test.classes.dir} +source.encoding=UTF-8 +src.dir=src +test.src.dir=test diff --git a/Pro Java 7 NIO.2/Chapter02/attrs/attrs_5/nbproject/project.xml b/Pro Java 7 NIO.2/Chapter02/attrs/attrs_5/nbproject/project.xml new file mode 100644 index 0000000..2207405 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter02/attrs/attrs_5/nbproject/project.xml @@ -0,0 +1,15 @@ + + + org.netbeans.modules.java.j2seproject + + + attrs_5 + + + + + + + + + diff --git a/Pro Java 7 NIO.2/Chapter02/attrs/attrs_5/src/attrs_5/Main.java b/Pro Java 7 NIO.2/Chapter02/attrs/attrs_5/src/attrs_5/Main.java new file mode 100644 index 0000000..b80287e --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter02/attrs/attrs_5/src/attrs_5/Main.java @@ -0,0 +1,45 @@ +package attrs_5; + +import java.io.IOException; +import java.nio.file.FileStore; +import java.nio.file.FileSystem; +import java.nio.file.FileSystems; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.nio.file.attribute.BasicFileAttributeView; +import java.util.Set; + +/** + * + * @author Apress + */ +public class Main { + + public static void main(String[] args) { + + //list all the supported views in the current file system + FileSystem fs = FileSystems.getDefault(); + Set views = fs.supportedFileAttributeViews(); + + for (String view : views) { + System.out.println(view); + } + + //test if a all file store supports a particular view - in this case, basic view + for (FileStore store : fs.getFileStores()) { + boolean supported = store.supportsFileAttributeView(BasicFileAttributeView.class); + System.out.println(store.name() + " ---" + supported); + } + + //check view on a file store where a particular file resides - in this case, basic view + Path path = Paths.get("C:/rafaelnadal/tournaments/2009", "BNP.txt"); + try { + FileStore store = Files.getFileStore(path); + boolean supported = store.supportsFileAttributeView("basic"); + System.out.println(store.name() + " ---" + supported); + } catch (IOException e) { + System.err.println(e); + } + } +} diff --git a/Pro Java 7 NIO.2/Chapter02/attrs/attrs_6/build.xml b/Pro Java 7 NIO.2/Chapter02/attrs/attrs_6/build.xml new file mode 100644 index 0000000..95bad7b --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter02/attrs/attrs_6/build.xml @@ -0,0 +1,74 @@ + + + + + + + + + + + Builds, tests, and runs the project attrs_6. + + + diff --git a/Pro Java 7 NIO.2/Chapter02/attrs/attrs_6/build/built-jar.properties b/Pro Java 7 NIO.2/Chapter02/attrs/attrs_6/build/built-jar.properties new file mode 100644 index 0000000..e134a93 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter02/attrs/attrs_6/build/built-jar.properties @@ -0,0 +1,4 @@ +#Sun, 16 Oct 2011 16:13:50 +0200 + + +C\:\\NIO\\attrs\\attrs_6= diff --git a/Pro Java 7 NIO.2/Chapter02/attrs/attrs_6/build/classes/attrs_6/Main.class b/Pro Java 7 NIO.2/Chapter02/attrs/attrs_6/build/classes/attrs_6/Main.class new file mode 100644 index 0000000..784af66 Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter02/attrs/attrs_6/build/classes/attrs_6/Main.class differ diff --git a/Pro Java 7 NIO.2/Chapter02/attrs/attrs_6/dist/README.TXT b/Pro Java 7 NIO.2/Chapter02/attrs/attrs_6/dist/README.TXT new file mode 100644 index 0000000..a69315d --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter02/attrs/attrs_6/dist/README.TXT @@ -0,0 +1,32 @@ +======================== +BUILD OUTPUT DESCRIPTION +======================== + +When you build an Java application project that has a main class, the IDE +automatically copies all of the JAR +files on the projects classpath to your projects dist/lib folder. The IDE +also adds each of the JAR files to the Class-Path element in the application +JAR files manifest file (MANIFEST.MF). + +To run the project from the command line, go to the dist folder and +type the following: + +java -jar "attrs_6.jar" + +To distribute this project, zip up the dist folder (including the lib folder) +and distribute the ZIP file. + +Notes: + +* If two JAR files on the project classpath have the same name, only the first +JAR file is copied to the lib folder. +* Only JAR files are copied to the lib folder. +If the classpath contains other types of files or folders, these files (folders) +are not copied. +* If a library on the projects classpath also has a Class-Path element +specified in the manifest,the content of the Class-Path element has to be on +the projects runtime path. +* To set a main class in a standard Java project, right-click the project node +in the Projects window and choose Properties. Then click Run and enter the +class name in the Main Class field. Alternatively, you can manually type the +class name in the manifest Main-Class element. diff --git a/Pro Java 7 NIO.2/Chapter02/attrs/attrs_6/dist/attrs_6.jar b/Pro Java 7 NIO.2/Chapter02/attrs/attrs_6/dist/attrs_6.jar new file mode 100644 index 0000000..49c0821 Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter02/attrs/attrs_6/dist/attrs_6.jar differ diff --git a/Pro Java 7 NIO.2/Chapter02/attrs/attrs_6/manifest.mf b/Pro Java 7 NIO.2/Chapter02/attrs/attrs_6/manifest.mf new file mode 100644 index 0000000..328e8e5 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter02/attrs/attrs_6/manifest.mf @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +X-COMMENT: Main-Class will be added automatically by build + diff --git a/Pro Java 7 NIO.2/Chapter02/attrs/attrs_6/nbproject/build-impl.xml b/Pro Java 7 NIO.2/Chapter02/attrs/attrs_6/nbproject/build-impl.xml new file mode 100644 index 0000000..7f5927c --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter02/attrs/attrs_6/nbproject/build-impl.xml @@ -0,0 +1,1041 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set src.dir + Must set test.src.dir + Must set build.dir + Must set dist.dir + Must set build.classes.dir + Must set dist.javadoc.dir + Must set build.test.classes.dir + Must set build.test.results.dir + Must set build.classes.excludes + Must set dist.jar + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set JVM to use for profiling in profiler.info.jvm + Must set profiler agent JVM arguments in profiler.info.jvmargs.agent + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + + + + + + java -cp "${run.classpath.with.dist.jar}" ${main.class} + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + java -jar "${dist.jar.resolved}" + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set run.class + + + + Must select one file in the IDE or set run.class + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set debug.class + + + + + Must select one file in the IDE or set debug.class + + + + + Must set fix.includes + + + + + + + + + + + + + + + + + Must select one file in the IDE or set profile.class + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + Some tests failed; see details above. + + + + + + + + + Must select some files in the IDE or set test.includes + + + + Some tests failed; see details above. + + + + + Must select one file in the IDE or set test.class + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Pro Java 7 NIO.2/Chapter02/attrs/attrs_6/nbproject/genfiles.properties b/Pro Java 7 NIO.2/Chapter02/attrs/attrs_6/nbproject/genfiles.properties new file mode 100644 index 0000000..3efb2e5 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter02/attrs/attrs_6/nbproject/genfiles.properties @@ -0,0 +1,8 @@ +build.xml.data.CRC32=13ab5dc8 +build.xml.script.CRC32=f93f714a +build.xml.stylesheet.CRC32=28e38971@1.43.1.45 +# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. +# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. +nbproject/build-impl.xml.data.CRC32=13ab5dc8 +nbproject/build-impl.xml.script.CRC32=ed099e80 +nbproject/build-impl.xml.stylesheet.CRC32=0c01fd8e@1.43.1.45 diff --git a/Pro Java 7 NIO.2/Chapter02/attrs/attrs_6/nbproject/private/config.properties b/Pro Java 7 NIO.2/Chapter02/attrs/attrs_6/nbproject/private/config.properties new file mode 100644 index 0000000..e69de29 diff --git a/Pro Java 7 NIO.2/Chapter02/attrs/attrs_6/nbproject/private/private.properties b/Pro Java 7 NIO.2/Chapter02/attrs/attrs_6/nbproject/private/private.properties new file mode 100644 index 0000000..a5ab360 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter02/attrs/attrs_6/nbproject/private/private.properties @@ -0,0 +1,6 @@ +compile.on.save=true +do.depend=false +do.jar=true +javac.debug=true +javadoc.preview=true +user.properties.file=C:\\Users\\Leo\\.netbeans\\7.0\\build.properties diff --git a/Pro Java 7 NIO.2/Chapter02/attrs/attrs_6/nbproject/private/private.xml b/Pro Java 7 NIO.2/Chapter02/attrs/attrs_6/nbproject/private/private.xml new file mode 100644 index 0000000..c1f155a --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter02/attrs/attrs_6/nbproject/private/private.xml @@ -0,0 +1,4 @@ + + + + diff --git a/Pro Java 7 NIO.2/Chapter02/attrs/attrs_6/nbproject/project.properties b/Pro Java 7 NIO.2/Chapter02/attrs/attrs_6/nbproject/project.properties new file mode 100644 index 0000000..3b9f057 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter02/attrs/attrs_6/nbproject/project.properties @@ -0,0 +1,72 @@ +annotation.processing.enabled=true +annotation.processing.enabled.in.editor=false +annotation.processing.run.all.processors=true +annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output +application.title=attrs_6 +application.vendor=Leo +build.classes.dir=${build.dir}/classes +build.classes.excludes=**/*.java,**/*.form +# This directory is removed when the project is cleaned: +build.dir=build +build.generated.dir=${build.dir}/generated +build.generated.sources.dir=${build.dir}/generated-sources +# Only compile against the classpath explicitly listed here: +build.sysclasspath=ignore +build.test.classes.dir=${build.dir}/test/classes +build.test.results.dir=${build.dir}/test/results +# Uncomment to specify the preferred debugger connection transport: +#debug.transport=dt_socket +debug.classpath=\ + ${run.classpath} +debug.test.classpath=\ + ${run.test.classpath} +# This directory is removed when the project is cleaned: +dist.dir=dist +dist.jar=${dist.dir}/attrs_6.jar +dist.javadoc.dir=${dist.dir}/javadoc +endorsed.classpath= +excludes= +includes=** +jar.compress=false +javac.classpath= +# Space-separated list of extra javac options +javac.compilerargs= +javac.deprecation=false +javac.processorpath=\ + ${javac.classpath} +javac.source=1.7 +javac.target=1.7 +javac.test.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +javac.test.processorpath=\ + ${javac.test.classpath} +javadoc.additionalparam= +javadoc.author=false +javadoc.encoding=${source.encoding} +javadoc.noindex=false +javadoc.nonavbar=false +javadoc.notree=false +javadoc.private=false +javadoc.splitindex=true +javadoc.use=true +javadoc.version=false +javadoc.windowtitle= +main.class=attrs_6.Main +manifest.file=manifest.mf +meta.inf.dir=${src.dir}/META-INF +mkdist.disabled=false +platform.active=default_platform +run.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +# Space-separated list of JVM arguments used when running the project +# (you may also define separate properties like run-sys-prop.name=value instead of -Dname=value +# or test-sys-prop.name=value to set system properties for unit tests): +run.jvmargs= +run.test.classpath=\ + ${javac.test.classpath}:\ + ${build.test.classes.dir} +source.encoding=UTF-8 +src.dir=src +test.src.dir=test diff --git a/Pro Java 7 NIO.2/Chapter02/attrs/attrs_6/nbproject/project.xml b/Pro Java 7 NIO.2/Chapter02/attrs/attrs_6/nbproject/project.xml new file mode 100644 index 0000000..bf28274 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter02/attrs/attrs_6/nbproject/project.xml @@ -0,0 +1,15 @@ + + + org.netbeans.modules.java.j2seproject + + + attrs_6 + + + + + + + + + diff --git a/Pro Java 7 NIO.2/Chapter02/attrs/attrs_6/src/attrs_6/Main.java b/Pro Java 7 NIO.2/Chapter02/attrs/attrs_6/src/attrs_6/Main.java new file mode 100644 index 0000000..950df81 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter02/attrs/attrs_6/src/attrs_6/Main.java @@ -0,0 +1,72 @@ +package attrs_6; + +import java.io.IOException; +import java.nio.ByteBuffer; +import java.nio.charset.Charset; +import java.nio.file.FileStore; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.nio.file.attribute.UserDefinedFileAttributeView; + +/** + * + * @author Apress + */ +public class Main { + + public static void main(String[] args) { + + Path path = Paths.get("C:/rafaelnadal/tournaments/2009", "BNP.txt"); + + //check if your your file system implementation supports user defined file attributes + try { + FileStore store = Files.getFileStore(path); + if (!store.supportsFileAttributeView(UserDefinedFileAttributeView.class)) { + System.out.println("The user defined attributes are not supported on: " + store); + } else { + System.out.println("The user defined attributes are supported on: " + store); + } + } catch (IOException e) { + System.err.println(e); + } + + //use the UserDefinedAttributeView + UserDefinedFileAttributeView udfav = Files.getFileAttributeView(path, UserDefinedFileAttributeView.class); + + //set a user defined attribute + try { + udfav.write("file.description", Charset.defaultCharset().encode("This file contains private information!")); + } catch (IOException e) { + System.err.println(e); + } + + //list the available user file attributes + try { + for (String name : udfav.list()) { + System.out.println(udfav.size(name) + " " + name); + } + } catch (IOException e) { + System.err.println(e); + } + + //get the value of an user defined attribute + try { + int size = udfav.size("file.description"); + ByteBuffer bb = ByteBuffer.allocateDirect(size); + udfav.read("file.description", bb); + bb.flip(); + System.out.println(Charset.defaultCharset().decode(bb).toString()); + } catch (IOException e) { + System.err.println(e); + } + + //Delete a file's user defined attribute + try { + udfav.delete("file.description"); + } catch (IOException e) { + System.err.println(e); + } + + } +} diff --git a/Pro Java 7 NIO.2/Chapter02/attrs/attrs_7/build.xml b/Pro Java 7 NIO.2/Chapter02/attrs/attrs_7/build.xml new file mode 100644 index 0000000..8e22803 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter02/attrs/attrs_7/build.xml @@ -0,0 +1,74 @@ + + + + + + + + + + + Builds, tests, and runs the project attrs_7. + + + diff --git a/Pro Java 7 NIO.2/Chapter02/attrs/attrs_7/build/built-jar.properties b/Pro Java 7 NIO.2/Chapter02/attrs/attrs_7/build/built-jar.properties new file mode 100644 index 0000000..ebf9e3b --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter02/attrs/attrs_7/build/built-jar.properties @@ -0,0 +1,4 @@ +#Sun, 16 Oct 2011 16:14:38 +0200 + + +C\:\\NIO\\attrs\\attrs_7= diff --git a/Pro Java 7 NIO.2/Chapter02/attrs/attrs_7/build/classes/attrs_7/Main.class b/Pro Java 7 NIO.2/Chapter02/attrs/attrs_7/build/classes/attrs_7/Main.class new file mode 100644 index 0000000..b2d2c6b Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter02/attrs/attrs_7/build/classes/attrs_7/Main.class differ diff --git a/Pro Java 7 NIO.2/Chapter02/attrs/attrs_7/dist/README.TXT b/Pro Java 7 NIO.2/Chapter02/attrs/attrs_7/dist/README.TXT new file mode 100644 index 0000000..babc468 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter02/attrs/attrs_7/dist/README.TXT @@ -0,0 +1,32 @@ +======================== +BUILD OUTPUT DESCRIPTION +======================== + +When you build an Java application project that has a main class, the IDE +automatically copies all of the JAR +files on the projects classpath to your projects dist/lib folder. The IDE +also adds each of the JAR files to the Class-Path element in the application +JAR files manifest file (MANIFEST.MF). + +To run the project from the command line, go to the dist folder and +type the following: + +java -jar "attrs_7.jar" + +To distribute this project, zip up the dist folder (including the lib folder) +and distribute the ZIP file. + +Notes: + +* If two JAR files on the project classpath have the same name, only the first +JAR file is copied to the lib folder. +* Only JAR files are copied to the lib folder. +If the classpath contains other types of files or folders, these files (folders) +are not copied. +* If a library on the projects classpath also has a Class-Path element +specified in the manifest,the content of the Class-Path element has to be on +the projects runtime path. +* To set a main class in a standard Java project, right-click the project node +in the Projects window and choose Properties. Then click Run and enter the +class name in the Main Class field. Alternatively, you can manually type the +class name in the manifest Main-Class element. diff --git a/Pro Java 7 NIO.2/Chapter02/attrs/attrs_7/dist/attrs_7.jar b/Pro Java 7 NIO.2/Chapter02/attrs/attrs_7/dist/attrs_7.jar new file mode 100644 index 0000000..e3772ff Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter02/attrs/attrs_7/dist/attrs_7.jar differ diff --git a/Pro Java 7 NIO.2/Chapter02/attrs/attrs_7/manifest.mf b/Pro Java 7 NIO.2/Chapter02/attrs/attrs_7/manifest.mf new file mode 100644 index 0000000..328e8e5 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter02/attrs/attrs_7/manifest.mf @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +X-COMMENT: Main-Class will be added automatically by build + diff --git a/Pro Java 7 NIO.2/Chapter02/attrs/attrs_7/nbproject/build-impl.xml b/Pro Java 7 NIO.2/Chapter02/attrs/attrs_7/nbproject/build-impl.xml new file mode 100644 index 0000000..6dde740 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter02/attrs/attrs_7/nbproject/build-impl.xml @@ -0,0 +1,1041 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set src.dir + Must set test.src.dir + Must set build.dir + Must set dist.dir + Must set build.classes.dir + Must set dist.javadoc.dir + Must set build.test.classes.dir + Must set build.test.results.dir + Must set build.classes.excludes + Must set dist.jar + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set JVM to use for profiling in profiler.info.jvm + Must set profiler agent JVM arguments in profiler.info.jvmargs.agent + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + + + + + + java -cp "${run.classpath.with.dist.jar}" ${main.class} + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + java -jar "${dist.jar.resolved}" + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set run.class + + + + Must select one file in the IDE or set run.class + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set debug.class + + + + + Must select one file in the IDE or set debug.class + + + + + Must set fix.includes + + + + + + + + + + + + + + + + + Must select one file in the IDE or set profile.class + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + Some tests failed; see details above. + + + + + + + + + Must select some files in the IDE or set test.includes + + + + Some tests failed; see details above. + + + + + Must select one file in the IDE or set test.class + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Pro Java 7 NIO.2/Chapter02/attrs/attrs_7/nbproject/genfiles.properties b/Pro Java 7 NIO.2/Chapter02/attrs/attrs_7/nbproject/genfiles.properties new file mode 100644 index 0000000..fdab0b5 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter02/attrs/attrs_7/nbproject/genfiles.properties @@ -0,0 +1,8 @@ +build.xml.data.CRC32=1bb8d1ee +build.xml.script.CRC32=f21cc809 +build.xml.stylesheet.CRC32=28e38971@1.43.1.45 +# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. +# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. +nbproject/build-impl.xml.data.CRC32=1bb8d1ee +nbproject/build-impl.xml.script.CRC32=572ba133 +nbproject/build-impl.xml.stylesheet.CRC32=0c01fd8e@1.43.1.45 diff --git a/Pro Java 7 NIO.2/Chapter02/attrs/attrs_7/nbproject/private/config.properties b/Pro Java 7 NIO.2/Chapter02/attrs/attrs_7/nbproject/private/config.properties new file mode 100644 index 0000000..e69de29 diff --git a/Pro Java 7 NIO.2/Chapter02/attrs/attrs_7/nbproject/private/private.properties b/Pro Java 7 NIO.2/Chapter02/attrs/attrs_7/nbproject/private/private.properties new file mode 100644 index 0000000..a5ab360 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter02/attrs/attrs_7/nbproject/private/private.properties @@ -0,0 +1,6 @@ +compile.on.save=true +do.depend=false +do.jar=true +javac.debug=true +javadoc.preview=true +user.properties.file=C:\\Users\\Leo\\.netbeans\\7.0\\build.properties diff --git a/Pro Java 7 NIO.2/Chapter02/attrs/attrs_7/nbproject/private/private.xml b/Pro Java 7 NIO.2/Chapter02/attrs/attrs_7/nbproject/private/private.xml new file mode 100644 index 0000000..c1f155a --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter02/attrs/attrs_7/nbproject/private/private.xml @@ -0,0 +1,4 @@ + + + + diff --git a/Pro Java 7 NIO.2/Chapter02/attrs/attrs_7/nbproject/project.properties b/Pro Java 7 NIO.2/Chapter02/attrs/attrs_7/nbproject/project.properties new file mode 100644 index 0000000..d350e26 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter02/attrs/attrs_7/nbproject/project.properties @@ -0,0 +1,72 @@ +annotation.processing.enabled=true +annotation.processing.enabled.in.editor=false +annotation.processing.run.all.processors=true +annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output +application.title=attrs_7 +application.vendor=Leo +build.classes.dir=${build.dir}/classes +build.classes.excludes=**/*.java,**/*.form +# This directory is removed when the project is cleaned: +build.dir=build +build.generated.dir=${build.dir}/generated +build.generated.sources.dir=${build.dir}/generated-sources +# Only compile against the classpath explicitly listed here: +build.sysclasspath=ignore +build.test.classes.dir=${build.dir}/test/classes +build.test.results.dir=${build.dir}/test/results +# Uncomment to specify the preferred debugger connection transport: +#debug.transport=dt_socket +debug.classpath=\ + ${run.classpath} +debug.test.classpath=\ + ${run.test.classpath} +# This directory is removed when the project is cleaned: +dist.dir=dist +dist.jar=${dist.dir}/attrs_7.jar +dist.javadoc.dir=${dist.dir}/javadoc +endorsed.classpath= +excludes= +includes=** +jar.compress=false +javac.classpath= +# Space-separated list of extra javac options +javac.compilerargs= +javac.deprecation=false +javac.processorpath=\ + ${javac.classpath} +javac.source=1.7 +javac.target=1.7 +javac.test.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +javac.test.processorpath=\ + ${javac.test.classpath} +javadoc.additionalparam= +javadoc.author=false +javadoc.encoding=${source.encoding} +javadoc.noindex=false +javadoc.nonavbar=false +javadoc.notree=false +javadoc.private=false +javadoc.splitindex=true +javadoc.use=true +javadoc.version=false +javadoc.windowtitle= +main.class=attrs_7.Main +manifest.file=manifest.mf +meta.inf.dir=${src.dir}/META-INF +mkdist.disabled=false +platform.active=default_platform +run.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +# Space-separated list of JVM arguments used when running the project +# (you may also define separate properties like run-sys-prop.name=value instead of -Dname=value +# or test-sys-prop.name=value to set system properties for unit tests): +run.jvmargs= +run.test.classpath=\ + ${javac.test.classpath}:\ + ${build.test.classes.dir} +source.encoding=UTF-8 +src.dir=src +test.src.dir=test diff --git a/Pro Java 7 NIO.2/Chapter02/attrs/attrs_7/nbproject/project.xml b/Pro Java 7 NIO.2/Chapter02/attrs/attrs_7/nbproject/project.xml new file mode 100644 index 0000000..89846b2 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter02/attrs/attrs_7/nbproject/project.xml @@ -0,0 +1,15 @@ + + + org.netbeans.modules.java.j2seproject + + + attrs_7 + + + + + + + + + diff --git a/Pro Java 7 NIO.2/Chapter02/attrs/attrs_7/src/attrs_7/Main.java b/Pro Java 7 NIO.2/Chapter02/attrs/attrs_7/src/attrs_7/Main.java new file mode 100644 index 0000000..252ac42 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter02/attrs/attrs_7/src/attrs_7/Main.java @@ -0,0 +1,62 @@ +package attrs_7; + +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.nio.file.attribute.FileOwnerAttributeView; +import java.nio.file.attribute.UserPrincipal; +import static java.nio.file.LinkOption.NOFOLLOW_LINKS; + +/** + * + * @author Apress + */ +public class Main { + + public static void main(String[] args) { + + UserPrincipal owner = null; + Path path = Paths.get("C:/rafaelnadal/tournaments/2009", "BNP.txt"); + + //set owner using Files.setOwner + try { + owner = path.getFileSystem().getUserPrincipalLookupService().lookupPrincipalByName("apress"); + Files.setOwner(path, owner); + } catch (IOException e) { + System.err.println(e); + } + + //set owner using FileOwnerAttributeView.setOwner + FileOwnerAttributeView foav = Files.getFileAttributeView(path, FileOwnerAttributeView.class); + try { + foav.setOwner(owner); + } catch (IOException e) { + System.err.println(e); + } + + //set owner using Files.setAttribute + try { + Files.setAttribute(path, "owner:owner", owner, NOFOLLOW_LINKS); + } catch (IOException e) { + System.err.println(e); + } + + //get owner with FileOwnerAttributeView.getOwner + try { + String get_owner_1 = foav.getOwner().getName(); + System.out.println(get_owner_1); + } catch (IOException e) { + System.err.println(e); + } + + //get owner with Files.getAttribute + try { + UserPrincipal get_owner_2 = (UserPrincipal) Files.getAttribute(path, "owner:owner", NOFOLLOW_LINKS); + System.out.println(get_owner_2.getName()); + } catch (IOException e) { + System.err.println(e); + } + + } +} diff --git a/Pro Java 7 NIO.2/Chapter02/attrs/attrs_8/build.xml b/Pro Java 7 NIO.2/Chapter02/attrs/attrs_8/build.xml new file mode 100644 index 0000000..2bcd3d8 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter02/attrs/attrs_8/build.xml @@ -0,0 +1,74 @@ + + + + + + + + + + + Builds, tests, and runs the project attrs_8. + + + diff --git a/Pro Java 7 NIO.2/Chapter02/attrs/attrs_8/build/built-jar.properties b/Pro Java 7 NIO.2/Chapter02/attrs/attrs_8/build/built-jar.properties new file mode 100644 index 0000000..caa2bab --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter02/attrs/attrs_8/build/built-jar.properties @@ -0,0 +1,4 @@ +#Sun, 16 Oct 2011 16:15:42 +0200 + + +C\:\\NIO\\attrs\\attrs_8= diff --git a/Pro Java 7 NIO.2/Chapter02/attrs/attrs_8/build/classes/attrs_8/Main.class b/Pro Java 7 NIO.2/Chapter02/attrs/attrs_8/build/classes/attrs_8/Main.class new file mode 100644 index 0000000..ed2882d Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter02/attrs/attrs_8/build/classes/attrs_8/Main.class differ diff --git a/Pro Java 7 NIO.2/Chapter02/attrs/attrs_8/dist/README.TXT b/Pro Java 7 NIO.2/Chapter02/attrs/attrs_8/dist/README.TXT new file mode 100644 index 0000000..9568220 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter02/attrs/attrs_8/dist/README.TXT @@ -0,0 +1,32 @@ +======================== +BUILD OUTPUT DESCRIPTION +======================== + +When you build an Java application project that has a main class, the IDE +automatically copies all of the JAR +files on the projects classpath to your projects dist/lib folder. The IDE +also adds each of the JAR files to the Class-Path element in the application +JAR files manifest file (MANIFEST.MF). + +To run the project from the command line, go to the dist folder and +type the following: + +java -jar "attrs_8.jar" + +To distribute this project, zip up the dist folder (including the lib folder) +and distribute the ZIP file. + +Notes: + +* If two JAR files on the project classpath have the same name, only the first +JAR file is copied to the lib folder. +* Only JAR files are copied to the lib folder. +If the classpath contains other types of files or folders, these files (folders) +are not copied. +* If a library on the projects classpath also has a Class-Path element +specified in the manifest,the content of the Class-Path element has to be on +the projects runtime path. +* To set a main class in a standard Java project, right-click the project node +in the Projects window and choose Properties. Then click Run and enter the +class name in the Main Class field. Alternatively, you can manually type the +class name in the manifest Main-Class element. diff --git a/Pro Java 7 NIO.2/Chapter02/attrs/attrs_8/dist/attrs_8.jar b/Pro Java 7 NIO.2/Chapter02/attrs/attrs_8/dist/attrs_8.jar new file mode 100644 index 0000000..4d0d88c Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter02/attrs/attrs_8/dist/attrs_8.jar differ diff --git a/Pro Java 7 NIO.2/Chapter02/attrs/attrs_8/manifest.mf b/Pro Java 7 NIO.2/Chapter02/attrs/attrs_8/manifest.mf new file mode 100644 index 0000000..328e8e5 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter02/attrs/attrs_8/manifest.mf @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +X-COMMENT: Main-Class will be added automatically by build + diff --git a/Pro Java 7 NIO.2/Chapter02/attrs/attrs_8/nbproject/build-impl.xml b/Pro Java 7 NIO.2/Chapter02/attrs/attrs_8/nbproject/build-impl.xml new file mode 100644 index 0000000..51b6838 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter02/attrs/attrs_8/nbproject/build-impl.xml @@ -0,0 +1,1041 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set src.dir + Must set test.src.dir + Must set build.dir + Must set dist.dir + Must set build.classes.dir + Must set dist.javadoc.dir + Must set build.test.classes.dir + Must set build.test.results.dir + Must set build.classes.excludes + Must set dist.jar + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set JVM to use for profiling in profiler.info.jvm + Must set profiler agent JVM arguments in profiler.info.jvmargs.agent + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + + + + + + java -cp "${run.classpath.with.dist.jar}" ${main.class} + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + java -jar "${dist.jar.resolved}" + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set run.class + + + + Must select one file in the IDE or set run.class + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set debug.class + + + + + Must select one file in the IDE or set debug.class + + + + + Must set fix.includes + + + + + + + + + + + + + + + + + Must select one file in the IDE or set profile.class + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + Some tests failed; see details above. + + + + + + + + + Must select some files in the IDE or set test.includes + + + + Some tests failed; see details above. + + + + + Must select one file in the IDE or set test.class + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Pro Java 7 NIO.2/Chapter02/attrs/attrs_8/nbproject/genfiles.properties b/Pro Java 7 NIO.2/Chapter02/attrs/attrs_8/nbproject/genfiles.properties new file mode 100644 index 0000000..308078e --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter02/attrs/attrs_8/nbproject/genfiles.properties @@ -0,0 +1,8 @@ +build.xml.data.CRC32=635e142c +build.xml.script.CRC32=9aeb2cd8 +build.xml.stylesheet.CRC32=28e38971@1.43.1.45 +# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. +# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. +nbproject/build-impl.xml.data.CRC32=635e142c +nbproject/build-impl.xml.script.CRC32=1661fdf7 +nbproject/build-impl.xml.stylesheet.CRC32=0c01fd8e@1.43.1.45 diff --git a/Pro Java 7 NIO.2/Chapter02/attrs/attrs_8/nbproject/private/config.properties b/Pro Java 7 NIO.2/Chapter02/attrs/attrs_8/nbproject/private/config.properties new file mode 100644 index 0000000..e69de29 diff --git a/Pro Java 7 NIO.2/Chapter02/attrs/attrs_8/nbproject/private/private.properties b/Pro Java 7 NIO.2/Chapter02/attrs/attrs_8/nbproject/private/private.properties new file mode 100644 index 0000000..a5ab360 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter02/attrs/attrs_8/nbproject/private/private.properties @@ -0,0 +1,6 @@ +compile.on.save=true +do.depend=false +do.jar=true +javac.debug=true +javadoc.preview=true +user.properties.file=C:\\Users\\Leo\\.netbeans\\7.0\\build.properties diff --git a/Pro Java 7 NIO.2/Chapter02/attrs/attrs_8/nbproject/private/private.xml b/Pro Java 7 NIO.2/Chapter02/attrs/attrs_8/nbproject/private/private.xml new file mode 100644 index 0000000..c1f155a --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter02/attrs/attrs_8/nbproject/private/private.xml @@ -0,0 +1,4 @@ + + + + diff --git a/Pro Java 7 NIO.2/Chapter02/attrs/attrs_8/nbproject/project.properties b/Pro Java 7 NIO.2/Chapter02/attrs/attrs_8/nbproject/project.properties new file mode 100644 index 0000000..973e30d --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter02/attrs/attrs_8/nbproject/project.properties @@ -0,0 +1,72 @@ +annotation.processing.enabled=true +annotation.processing.enabled.in.editor=false +annotation.processing.run.all.processors=true +annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output +application.title=attrs_8 +application.vendor=Leo +build.classes.dir=${build.dir}/classes +build.classes.excludes=**/*.java,**/*.form +# This directory is removed when the project is cleaned: +build.dir=build +build.generated.dir=${build.dir}/generated +build.generated.sources.dir=${build.dir}/generated-sources +# Only compile against the classpath explicitly listed here: +build.sysclasspath=ignore +build.test.classes.dir=${build.dir}/test/classes +build.test.results.dir=${build.dir}/test/results +# Uncomment to specify the preferred debugger connection transport: +#debug.transport=dt_socket +debug.classpath=\ + ${run.classpath} +debug.test.classpath=\ + ${run.test.classpath} +# This directory is removed when the project is cleaned: +dist.dir=dist +dist.jar=${dist.dir}/attrs_8.jar +dist.javadoc.dir=${dist.dir}/javadoc +endorsed.classpath= +excludes= +includes=** +jar.compress=false +javac.classpath= +# Space-separated list of extra javac options +javac.compilerargs= +javac.deprecation=false +javac.processorpath=\ + ${javac.classpath} +javac.source=1.7 +javac.target=1.7 +javac.test.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +javac.test.processorpath=\ + ${javac.test.classpath} +javadoc.additionalparam= +javadoc.author=false +javadoc.encoding=${source.encoding} +javadoc.noindex=false +javadoc.nonavbar=false +javadoc.notree=false +javadoc.private=false +javadoc.splitindex=true +javadoc.use=true +javadoc.version=false +javadoc.windowtitle= +main.class=attrs_8.Main +manifest.file=manifest.mf +meta.inf.dir=${src.dir}/META-INF +mkdist.disabled=false +platform.active=default_platform +run.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +# Space-separated list of JVM arguments used when running the project +# (you may also define separate properties like run-sys-prop.name=value instead of -Dname=value +# or test-sys-prop.name=value to set system properties for unit tests): +run.jvmargs= +run.test.classpath=\ + ${javac.test.classpath}:\ + ${build.test.classes.dir} +source.encoding=UTF-8 +src.dir=src +test.src.dir=test diff --git a/Pro Java 7 NIO.2/Chapter02/attrs/attrs_8/nbproject/project.xml b/Pro Java 7 NIO.2/Chapter02/attrs/attrs_8/nbproject/project.xml new file mode 100644 index 0000000..3b0ebaa --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter02/attrs/attrs_8/nbproject/project.xml @@ -0,0 +1,15 @@ + + + org.netbeans.modules.java.j2seproject + + + attrs_8 + + + + + + + + + diff --git a/Pro Java 7 NIO.2/Chapter02/attrs/attrs_8/src/attrs_8/Main.java b/Pro Java 7 NIO.2/Chapter02/attrs/attrs_8/src/attrs_8/Main.java new file mode 100644 index 0000000..8d988ab --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter02/attrs/attrs_8/src/attrs_8/Main.java @@ -0,0 +1,79 @@ +package attrs_8; + +import java.nio.file.attribute.AclEntryPermission; +import java.nio.file.attribute.AclEntryType; +import java.nio.file.attribute.UserPrincipal; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.nio.file.attribute.AclEntry; +import java.nio.file.attribute.AclFileAttributeView; +import java.util.List; +import static java.nio.file.LinkOption.NOFOLLOW_LINKS; + +/** + * + * @author Apress + */ +public class Main { + + public static void main(String[] args) { + + List acllist = null; + Path path = Paths.get("C:/rafaelnadal/tournaments/2009", "BNP.txt"); + + //read ACL using Files.getFileAttributeView + AclFileAttributeView aclview = Files.getFileAttributeView(path, AclFileAttributeView.class); + + try { + acllist = aclview.getAcl(); + } catch (IOException e) { + System.err.println(e); + } + + //read ACL using Files.getAttribute + try { + acllist = (List) Files.getAttribute(path, "acl:acl", NOFOLLOW_LINKS); + } catch (IOException e) { + System.err.println(e); + } + + //see the ACL entries + for (AclEntry aclentry : acllist) { + System.out.println("++++++++++++++++++++++++++++++++++++++++++++++++++++"); + System.out.println("Principal: " + aclentry.principal().getName()); + System.out.println("Type: " + aclentry.type().toString()); + System.out.println("Permissions: " + aclentry.permissions().toString()); + System.out.println("Flags: " + aclentry.flags().toString()); + } + + //grant a new access + try { + //Lookup for the principal + UserPrincipal user = path.getFileSystem().getUserPrincipalLookupService().lookupPrincipalByName("aprees"); + + //Get the ACL view + AclFileAttributeView view = Files.getFileAttributeView(path, AclFileAttributeView.class); + + //Create a new entry + AclEntry entry = AclEntry.newBuilder().setType(AclEntryType.ALLOW).setPrincipal(user).setPermissions(AclEntryPermission.READ_DATA, AclEntryPermission.APPEND_DATA).build(); + + //read ACL + List acl = view.getAcl(); + + //Insert the new entry + acl.add(0, entry); + + //re-write ACL + view.setAcl(acl); + //or, like this + //Files.setAttribute(path, "acl:acl", acl, NOFOLLOW_LINKS); + + } catch (IOException e) { + System.err.println(e); + } + + + } +} diff --git a/Pro Java 7 NIO.2/Chapter03/links/link_01/build.xml b/Pro Java 7 NIO.2/Chapter03/links/link_01/build.xml new file mode 100644 index 0000000..616083c --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter03/links/link_01/build.xml @@ -0,0 +1,74 @@ + + + + + + + + + + + Builds, tests, and runs the project link_01. + + + diff --git a/Pro Java 7 NIO.2/Chapter03/links/link_01/build/built-jar.properties b/Pro Java 7 NIO.2/Chapter03/links/link_01/build/built-jar.properties new file mode 100644 index 0000000..1bdc38e --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter03/links/link_01/build/built-jar.properties @@ -0,0 +1,4 @@ +#Sun, 16 Oct 2011 16:37:43 +0200 + + +C\:\\NIO\\links\\link_01= diff --git a/Pro Java 7 NIO.2/Chapter03/links/link_01/build/classes/link_01/Main.class b/Pro Java 7 NIO.2/Chapter03/links/link_01/build/classes/link_01/Main.class new file mode 100644 index 0000000..89182fe Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter03/links/link_01/build/classes/link_01/Main.class differ diff --git a/Pro Java 7 NIO.2/Chapter03/links/link_01/dist/README.TXT b/Pro Java 7 NIO.2/Chapter03/links/link_01/dist/README.TXT new file mode 100644 index 0000000..9fef1af --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter03/links/link_01/dist/README.TXT @@ -0,0 +1,33 @@ +======================== +BUILD OUTPUT DESCRIPTION +======================== + +When you build an Java application project that has a main class, the IDE +automatically copies all of the JAR +files on the projects classpath to your projects dist/lib folder. The IDE +also adds each of the JAR files to the Class-Path element in the application +JAR files manifest file (MANIFEST.MF). + +To run the project from the command line, go to the dist folder and +type the following: + +java -jar "link_01.jar" + +To distribute this project, zip up the dist folder (including the lib folder) +and distribute the ZIP file. + +Notes: + +* If two JAR files on the project classpath have the same name, only the first +JAR file is copied to the lib folder. +* Only JAR files are copied to the lib folder. +If the classpath contains other types of files or folders, none of the +classpath elements are copied to the lib folder. In such a case, +you need to copy the classpath elements to the lib folder manually after the build. +* If a library on the projects classpath also has a Class-Path element +specified in the manifest,the content of the Class-Path element has to be on +the projects runtime path. +* To set a main class in a standard Java project, right-click the project node +in the Projects window and choose Properties. Then click Run and enter the +class name in the Main Class field. Alternatively, you can manually type the +class name in the manifest Main-Class element. diff --git a/Pro Java 7 NIO.2/Chapter03/links/link_01/dist/link_01.jar b/Pro Java 7 NIO.2/Chapter03/links/link_01/dist/link_01.jar new file mode 100644 index 0000000..0ef400f Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter03/links/link_01/dist/link_01.jar differ diff --git a/Pro Java 7 NIO.2/Chapter03/links/link_01/lib/CopyLibs/org-netbeans-modules-java-j2seproject-copylibstask.jar b/Pro Java 7 NIO.2/Chapter03/links/link_01/lib/CopyLibs/org-netbeans-modules-java-j2seproject-copylibstask.jar new file mode 100644 index 0000000..5ee71d2 Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter03/links/link_01/lib/CopyLibs/org-netbeans-modules-java-j2seproject-copylibstask.jar differ diff --git a/Pro Java 7 NIO.2/Chapter03/links/link_01/lib/junit/junit-3.8.2-api.zip b/Pro Java 7 NIO.2/Chapter03/links/link_01/lib/junit/junit-3.8.2-api.zip new file mode 100644 index 0000000..6d792fd Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter03/links/link_01/lib/junit/junit-3.8.2-api.zip differ diff --git a/Pro Java 7 NIO.2/Chapter03/links/link_01/lib/junit/junit-3.8.2.jar b/Pro Java 7 NIO.2/Chapter03/links/link_01/lib/junit/junit-3.8.2.jar new file mode 100644 index 0000000..d835872 Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter03/links/link_01/lib/junit/junit-3.8.2.jar differ diff --git a/Pro Java 7 NIO.2/Chapter03/links/link_01/lib/junit_4/junit-4.5-api.zip b/Pro Java 7 NIO.2/Chapter03/links/link_01/lib/junit_4/junit-4.5-api.zip new file mode 100644 index 0000000..5748c44 Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter03/links/link_01/lib/junit_4/junit-4.5-api.zip differ diff --git a/Pro Java 7 NIO.2/Chapter03/links/link_01/lib/junit_4/junit-4.5-src.jar b/Pro Java 7 NIO.2/Chapter03/links/link_01/lib/junit_4/junit-4.5-src.jar new file mode 100644 index 0000000..18774a5 Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter03/links/link_01/lib/junit_4/junit-4.5-src.jar differ diff --git a/Pro Java 7 NIO.2/Chapter03/links/link_01/lib/junit_4/junit-4.5.jar b/Pro Java 7 NIO.2/Chapter03/links/link_01/lib/junit_4/junit-4.5.jar new file mode 100644 index 0000000..83f8bc7 Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter03/links/link_01/lib/junit_4/junit-4.5.jar differ diff --git a/Pro Java 7 NIO.2/Chapter03/links/link_01/lib/nblibraries.properties b/Pro Java 7 NIO.2/Chapter03/links/link_01/lib/nblibraries.properties new file mode 100644 index 0000000..9137b06 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter03/links/link_01/lib/nblibraries.properties @@ -0,0 +1,12 @@ +libs.CopyLibs.classpath=\ + ${base}/CopyLibs/org-netbeans-modules-java-j2seproject-copylibstask.jar +libs.junit.classpath=\ + ${base}/junit/junit-3.8.2.jar +libs.junit.javadoc=\ + ${base}/junit/junit-3.8.2-api.zip +libs.junit_4.classpath=\ + ${base}/junit_4/junit-4.5.jar +libs.junit_4.javadoc=\ + ${base}/junit_4/junit-4.5-api.zip +libs.junit_4.src=\ + ${base}/junit_4/junit-4.5-src.jar diff --git a/Pro Java 7 NIO.2/Chapter03/links/link_01/manifest.mf b/Pro Java 7 NIO.2/Chapter03/links/link_01/manifest.mf new file mode 100644 index 0000000..328e8e5 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter03/links/link_01/manifest.mf @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +X-COMMENT: Main-Class will be added automatically by build + diff --git a/Pro Java 7 NIO.2/Chapter03/links/link_01/nbproject/build-impl.xml b/Pro Java 7 NIO.2/Chapter03/links/link_01/nbproject/build-impl.xml new file mode 100644 index 0000000..61c6ec0 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter03/links/link_01/nbproject/build-impl.xml @@ -0,0 +1,1066 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set src.dir + Must set test.src.dir + Must set build.dir + Must set dist.dir + Must set build.classes.dir + Must set dist.javadoc.dir + Must set build.test.classes.dir + Must set build.test.results.dir + Must set build.classes.excludes + Must set dist.jar + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set JVM to use for profiling in profiler.info.jvm + Must set profiler agent JVM arguments in profiler.info.jvmargs.agent + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + + + + + + java -cp "${run.classpath.with.dist.jar}" ${main.class} + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + java -jar "${dist.jar.resolved}" + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set run.class + + + + Must select one file in the IDE or set run.class + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set debug.class + + + + + Must select one file in the IDE or set debug.class + + + + + Must set fix.includes + + + + + + + + + + + + + + + + + Must select one file in the IDE or set profile.class + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + Some tests failed; see details above. + + + + + + + + + Must select some files in the IDE or set test.includes + + + + Some tests failed; see details above. + + + + + Must select one file in the IDE or set test.class + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Pro Java 7 NIO.2/Chapter03/links/link_01/nbproject/genfiles.properties b/Pro Java 7 NIO.2/Chapter03/links/link_01/nbproject/genfiles.properties new file mode 100644 index 0000000..fd03b7d --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter03/links/link_01/nbproject/genfiles.properties @@ -0,0 +1,8 @@ +build.xml.data.CRC32=fbd4bd82 +build.xml.script.CRC32=381f16ba +build.xml.stylesheet.CRC32=28e38971@1.43.1.45 +# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. +# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. +nbproject/build-impl.xml.data.CRC32=fbd4bd82 +nbproject/build-impl.xml.script.CRC32=67d2a047 +nbproject/build-impl.xml.stylesheet.CRC32=0c01fd8e@1.43.1.45 diff --git a/Pro Java 7 NIO.2/Chapter03/links/link_01/nbproject/private/config.properties b/Pro Java 7 NIO.2/Chapter03/links/link_01/nbproject/private/config.properties new file mode 100644 index 0000000..e69de29 diff --git a/Pro Java 7 NIO.2/Chapter03/links/link_01/nbproject/private/private.properties b/Pro Java 7 NIO.2/Chapter03/links/link_01/nbproject/private/private.properties new file mode 100644 index 0000000..a5ab360 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter03/links/link_01/nbproject/private/private.properties @@ -0,0 +1,6 @@ +compile.on.save=true +do.depend=false +do.jar=true +javac.debug=true +javadoc.preview=true +user.properties.file=C:\\Users\\Leo\\.netbeans\\7.0\\build.properties diff --git a/Pro Java 7 NIO.2/Chapter03/links/link_01/nbproject/private/private.xml b/Pro Java 7 NIO.2/Chapter03/links/link_01/nbproject/private/private.xml new file mode 100644 index 0000000..c1f155a --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter03/links/link_01/nbproject/private/private.xml @@ -0,0 +1,4 @@ + + + + diff --git a/Pro Java 7 NIO.2/Chapter03/links/link_01/nbproject/project.properties b/Pro Java 7 NIO.2/Chapter03/links/link_01/nbproject/project.properties new file mode 100644 index 0000000..99eb937 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter03/links/link_01/nbproject/project.properties @@ -0,0 +1,74 @@ +annotation.processing.enabled=true +annotation.processing.enabled.in.editor=false +annotation.processing.run.all.processors=true +annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output +application.title=link_01 +application.vendor=Leo +build.classes.dir=${build.dir}/classes +build.classes.excludes=**/*.java,**/*.form +# This directory is removed when the project is cleaned: +build.dir=build +build.generated.dir=${build.dir}/generated +build.generated.sources.dir=${build.dir}/generated-sources +# Only compile against the classpath explicitly listed here: +build.sysclasspath=ignore +build.test.classes.dir=${build.dir}/test/classes +build.test.results.dir=${build.dir}/test/results +# Uncomment to specify the preferred debugger connection transport: +#debug.transport=dt_socket +debug.classpath=\ + ${run.classpath} +debug.test.classpath=\ + ${run.test.classpath} +# This directory is removed when the project is cleaned: +dist.dir=dist +dist.jar=${dist.dir}/link_01.jar +dist.javadoc.dir=${dist.dir}/javadoc +endorsed.classpath= +excludes= +includes=** +jar.compress=false +javac.classpath= +# Space-separated list of extra javac options +javac.compilerargs= +javac.deprecation=false +javac.processorpath=\ + ${javac.classpath} +javac.source=1.7 +javac.target=1.7 +javac.test.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir}:\ + ${libs.junit.classpath}:\ + ${libs.junit_4.classpath} +javac.test.processorpath=\ + ${javac.test.classpath} +javadoc.additionalparam= +javadoc.author=false +javadoc.encoding=${source.encoding} +javadoc.noindex=false +javadoc.nonavbar=false +javadoc.notree=false +javadoc.private=false +javadoc.splitindex=true +javadoc.use=true +javadoc.version=false +javadoc.windowtitle= +main.class=link_01.Main +manifest.file=manifest.mf +meta.inf.dir=${src.dir}/META-INF +mkdist.disabled=false +platform.active=default_platform +run.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +# Space-separated list of JVM arguments used when running the project +# (you may also define separate properties like run-sys-prop.name=value instead of -Dname=value +# or test-sys-prop.name=value to set system properties for unit tests): +run.jvmargs= +run.test.classpath=\ + ${javac.test.classpath}:\ + ${build.test.classes.dir} +source.encoding=UTF-8 +src.dir=src +test.src.dir=test diff --git a/Pro Java 7 NIO.2/Chapter03/links/link_01/nbproject/project.xml b/Pro Java 7 NIO.2/Chapter03/links/link_01/nbproject/project.xml new file mode 100644 index 0000000..9f2aeda --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter03/links/link_01/nbproject/project.xml @@ -0,0 +1,18 @@ + + + org.netbeans.modules.java.j2seproject + + + link_01 + + + + + + + + + .\lib\nblibraries.properties + + + diff --git a/Pro Java 7 NIO.2/Chapter03/links/link_01/src/link_01/Main.java b/Pro Java 7 NIO.2/Chapter03/links/link_01/src/link_01/Main.java new file mode 100644 index 0000000..582f2fe --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter03/links/link_01/src/link_01/Main.java @@ -0,0 +1,35 @@ +package link_01; + +import java.io.IOException; +import java.nio.file.FileSystems; +import java.nio.file.Files; +import java.nio.file.Path; + +/** + * + * @author Apress + */ +public class Main { + + public static void main(String[] args) { + + Path link = FileSystems.getDefault().getPath("rafael.nadal.4"); + Path target = FileSystems.getDefault().getPath("C:/rafaelnadal/photos", "rafa_winner.jpg"); + + try { + Files.createLink(link, target); + System.out.println("The link was successfully created!"); + } catch (IOException | UnsupportedOperationException | SecurityException e) { + if (e instanceof SecurityException) { + System.err.println("Permission denied!"); + } + if (e instanceof UnsupportedOperationException) { + System.err.println("An unsupported operation was detected!"); + } + if (e instanceof IOException) { + System.err.println("An I/O error occured!"); + } + System.err.println(e); + } + } +} diff --git a/Pro Java 7 NIO.2/Chapter03/links/link_02/build.xml b/Pro Java 7 NIO.2/Chapter03/links/link_02/build.xml new file mode 100644 index 0000000..3f7c8fd --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter03/links/link_02/build.xml @@ -0,0 +1,74 @@ + + + + + + + + + + + Builds, tests, and runs the project link_02. + + + diff --git a/Pro Java 7 NIO.2/Chapter03/links/link_02/build/built-jar.properties b/Pro Java 7 NIO.2/Chapter03/links/link_02/build/built-jar.properties new file mode 100644 index 0000000..8858f66 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter03/links/link_02/build/built-jar.properties @@ -0,0 +1,4 @@ +#Sun, 16 Oct 2011 16:36:23 +0200 + + +C\:\\NIO\\links\\link_02= diff --git a/Pro Java 7 NIO.2/Chapter03/links/link_02/build/classes/.netbeans_automatic_build b/Pro Java 7 NIO.2/Chapter03/links/link_02/build/classes/.netbeans_automatic_build new file mode 100644 index 0000000..e69de29 diff --git a/Pro Java 7 NIO.2/Chapter03/links/link_02/build/classes/link_02/Main.class b/Pro Java 7 NIO.2/Chapter03/links/link_02/build/classes/link_02/Main.class new file mode 100644 index 0000000..9486e82 Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter03/links/link_02/build/classes/link_02/Main.class differ diff --git a/Pro Java 7 NIO.2/Chapter03/links/link_02/dist/README.TXT b/Pro Java 7 NIO.2/Chapter03/links/link_02/dist/README.TXT new file mode 100644 index 0000000..0f3fa30 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter03/links/link_02/dist/README.TXT @@ -0,0 +1,32 @@ +======================== +BUILD OUTPUT DESCRIPTION +======================== + +When you build an Java application project that has a main class, the IDE +automatically copies all of the JAR +files on the projects classpath to your projects dist/lib folder. The IDE +also adds each of the JAR files to the Class-Path element in the application +JAR files manifest file (MANIFEST.MF). + +To run the project from the command line, go to the dist folder and +type the following: + +java -jar "link_02.jar" + +To distribute this project, zip up the dist folder (including the lib folder) +and distribute the ZIP file. + +Notes: + +* If two JAR files on the project classpath have the same name, only the first +JAR file is copied to the lib folder. +* Only JAR files are copied to the lib folder. +If the classpath contains other types of files or folders, these files (folders) +are not copied. +* If a library on the projects classpath also has a Class-Path element +specified in the manifest,the content of the Class-Path element has to be on +the projects runtime path. +* To set a main class in a standard Java project, right-click the project node +in the Projects window and choose Properties. Then click Run and enter the +class name in the Main Class field. Alternatively, you can manually type the +class name in the manifest Main-Class element. diff --git a/Pro Java 7 NIO.2/Chapter03/links/link_02/dist/link_02.jar b/Pro Java 7 NIO.2/Chapter03/links/link_02/dist/link_02.jar new file mode 100644 index 0000000..b992a8e Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter03/links/link_02/dist/link_02.jar differ diff --git a/Pro Java 7 NIO.2/Chapter03/links/link_02/manifest.mf b/Pro Java 7 NIO.2/Chapter03/links/link_02/manifest.mf new file mode 100644 index 0000000..328e8e5 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter03/links/link_02/manifest.mf @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +X-COMMENT: Main-Class will be added automatically by build + diff --git a/Pro Java 7 NIO.2/Chapter03/links/link_02/nbproject/build-impl.xml b/Pro Java 7 NIO.2/Chapter03/links/link_02/nbproject/build-impl.xml new file mode 100644 index 0000000..564ac2f --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter03/links/link_02/nbproject/build-impl.xml @@ -0,0 +1,1041 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set src.dir + Must set test.src.dir + Must set build.dir + Must set dist.dir + Must set build.classes.dir + Must set dist.javadoc.dir + Must set build.test.classes.dir + Must set build.test.results.dir + Must set build.classes.excludes + Must set dist.jar + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set JVM to use for profiling in profiler.info.jvm + Must set profiler agent JVM arguments in profiler.info.jvmargs.agent + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + + + + + + java -cp "${run.classpath.with.dist.jar}" ${main.class} + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + java -jar "${dist.jar.resolved}" + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set run.class + + + + Must select one file in the IDE or set run.class + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set debug.class + + + + + Must select one file in the IDE or set debug.class + + + + + Must set fix.includes + + + + + + + + + + + + + + + + + Must select one file in the IDE or set profile.class + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + Some tests failed; see details above. + + + + + + + + + Must select some files in the IDE or set test.includes + + + + Some tests failed; see details above. + + + + + Must select one file in the IDE or set test.class + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Pro Java 7 NIO.2/Chapter03/links/link_02/nbproject/genfiles.properties b/Pro Java 7 NIO.2/Chapter03/links/link_02/nbproject/genfiles.properties new file mode 100644 index 0000000..db03c7b --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter03/links/link_02/nbproject/genfiles.properties @@ -0,0 +1,8 @@ +build.xml.data.CRC32=3ab76700 +build.xml.script.CRC32=257bdd7f +build.xml.stylesheet.CRC32=28e38971@1.43.1.45 +# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. +# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. +nbproject/build-impl.xml.data.CRC32=3ab76700 +nbproject/build-impl.xml.script.CRC32=ebe9dacc +nbproject/build-impl.xml.stylesheet.CRC32=0c01fd8e@1.43.1.45 diff --git a/Pro Java 7 NIO.2/Chapter03/links/link_02/nbproject/private/config.properties b/Pro Java 7 NIO.2/Chapter03/links/link_02/nbproject/private/config.properties new file mode 100644 index 0000000..e69de29 diff --git a/Pro Java 7 NIO.2/Chapter03/links/link_02/nbproject/private/private.properties b/Pro Java 7 NIO.2/Chapter03/links/link_02/nbproject/private/private.properties new file mode 100644 index 0000000..a5ab360 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter03/links/link_02/nbproject/private/private.properties @@ -0,0 +1,6 @@ +compile.on.save=true +do.depend=false +do.jar=true +javac.debug=true +javadoc.preview=true +user.properties.file=C:\\Users\\Leo\\.netbeans\\7.0\\build.properties diff --git a/Pro Java 7 NIO.2/Chapter03/links/link_02/nbproject/private/private.xml b/Pro Java 7 NIO.2/Chapter03/links/link_02/nbproject/private/private.xml new file mode 100644 index 0000000..c1f155a --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter03/links/link_02/nbproject/private/private.xml @@ -0,0 +1,4 @@ + + + + diff --git a/Pro Java 7 NIO.2/Chapter03/links/link_02/nbproject/project.properties b/Pro Java 7 NIO.2/Chapter03/links/link_02/nbproject/project.properties new file mode 100644 index 0000000..3dbb592 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter03/links/link_02/nbproject/project.properties @@ -0,0 +1,72 @@ +annotation.processing.enabled=true +annotation.processing.enabled.in.editor=false +annotation.processing.run.all.processors=true +annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output +application.title=link_02 +application.vendor=Leo +build.classes.dir=${build.dir}/classes +build.classes.excludes=**/*.java,**/*.form +# This directory is removed when the project is cleaned: +build.dir=build +build.generated.dir=${build.dir}/generated +build.generated.sources.dir=${build.dir}/generated-sources +# Only compile against the classpath explicitly listed here: +build.sysclasspath=ignore +build.test.classes.dir=${build.dir}/test/classes +build.test.results.dir=${build.dir}/test/results +# Uncomment to specify the preferred debugger connection transport: +#debug.transport=dt_socket +debug.classpath=\ + ${run.classpath} +debug.test.classpath=\ + ${run.test.classpath} +# This directory is removed when the project is cleaned: +dist.dir=dist +dist.jar=${dist.dir}/link_02.jar +dist.javadoc.dir=${dist.dir}/javadoc +endorsed.classpath= +excludes= +includes=** +jar.compress=false +javac.classpath= +# Space-separated list of extra javac options +javac.compilerargs= +javac.deprecation=false +javac.processorpath=\ + ${javac.classpath} +javac.source=1.7 +javac.target=1.7 +javac.test.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +javac.test.processorpath=\ + ${javac.test.classpath} +javadoc.additionalparam= +javadoc.author=false +javadoc.encoding=${source.encoding} +javadoc.noindex=false +javadoc.nonavbar=false +javadoc.notree=false +javadoc.private=false +javadoc.splitindex=true +javadoc.use=true +javadoc.version=false +javadoc.windowtitle= +main.class=link_02.Main +manifest.file=manifest.mf +meta.inf.dir=${src.dir}/META-INF +mkdist.disabled=false +platform.active=default_platform +run.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +# Space-separated list of JVM arguments used when running the project +# (you may also define separate properties like run-sys-prop.name=value instead of -Dname=value +# or test-sys-prop.name=value to set system properties for unit tests): +run.jvmargs= +run.test.classpath=\ + ${javac.test.classpath}:\ + ${build.test.classes.dir} +source.encoding=UTF-8 +src.dir=src +test.src.dir=test diff --git a/Pro Java 7 NIO.2/Chapter03/links/link_02/nbproject/project.xml b/Pro Java 7 NIO.2/Chapter03/links/link_02/nbproject/project.xml new file mode 100644 index 0000000..e88dd27 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter03/links/link_02/nbproject/project.xml @@ -0,0 +1,15 @@ + + + org.netbeans.modules.java.j2seproject + + + link_02 + + + + + + + + + diff --git a/Pro Java 7 NIO.2/Chapter03/links/link_02/src/link_02/Main.java b/Pro Java 7 NIO.2/Chapter03/links/link_02/src/link_02/Main.java new file mode 100644 index 0000000..7cd9c0d --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter03/links/link_02/src/link_02/Main.java @@ -0,0 +1,85 @@ +package link_02; + +import java.nio.file.attribute.FileAttribute; +import java.nio.file.attribute.PosixFileAttributes; +import java.nio.file.attribute.PosixFilePermission; +import java.nio.file.attribute.PosixFilePermissions; +import java.util.Set; +import java.io.IOException; +import java.nio.file.FileSystems; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.attribute.FileTime; +import static java.nio.file.LinkOption.NOFOLLOW_LINKS; + +/** + * + * @author Apress + */ +public class Main { + + public static void main(String[] args) { + + //create a symbolic link with the default attributes + Path link1 = FileSystems.getDefault().getPath("rafael.nadal.1"); + Path target1 = FileSystems.getDefault().getPath("C:/rafaelnadal/photos", "rafa_winner.jpg"); + try { + Files.createSymbolicLink(link1, target1); + } catch (IOException | UnsupportedOperationException | SecurityException e) { + if (e instanceof SecurityException) { + System.err.println("Permision denied!"); + } + if (e instanceof UnsupportedOperationException) { + System.err.println("An unsupported operation was detected!"); + } + if (e instanceof IOException) { + System.err.println("An I/O error occured!"); + } + System.err.println(e); + } + + //create a symbolic link with permissions + Path link2 = FileSystems.getDefault().getPath("rafael.nadal.2"); + Path target2 = FileSystems.getDefault().getPath("C:/rafaelnadal/photos", "rafa_winner.jpg"); + try { + PosixFileAttributes attrs = Files.readAttributes(target2, PosixFileAttributes.class); + FileAttribute> attr = PosixFilePermissions.asFileAttribute(attrs.permissions()); + + Files.createSymbolicLink(link2, target2, attr); + } catch (IOException | UnsupportedOperationException | SecurityException e) { + if (e instanceof SecurityException) { + System.err.println("Permission denied!"); + } + if (e instanceof UnsupportedOperationException) { + System.err.println("An unsupported operation was detected!"); + } + if (e instanceof IOException) { + System.err.println("An I/O error occured!"); + } + System.err.println(e); + } + + //create a symbolic link with the same lastModifiedTime and lastAccessTime as the target + Path link3 = FileSystems.getDefault().getPath("rafael.nadal.3"); + Path target3 = FileSystems.getDefault().getPath("C:/rafaelnadal/photos", "rafa_winner.jpg"); + try { + Files.createSymbolicLink(link3, target3); + + FileTime lm = (FileTime) Files.getAttribute(target3, "basic:lastModifiedTime", NOFOLLOW_LINKS); + FileTime la = (FileTime) Files.getAttribute(target3, "basic:lastAccessTime", NOFOLLOW_LINKS); + Files.setAttribute(link3, "basic:lastModifiedTime", lm, NOFOLLOW_LINKS); + Files.setAttribute(link3, "basic:lastAccessTime", la, NOFOLLOW_LINKS); + } catch (IOException | UnsupportedOperationException | SecurityException e) { + if (e instanceof SecurityException) { + System.err.println("Permision denied!"); + } + if (e instanceof UnsupportedOperationException) { + System.err.println("An unsupported operation was detected!"); + } + if (e instanceof IOException) { + System.err.println("An I/O error occured!"); + } + System.err.println(e); + } + } +} diff --git a/Pro Java 7 NIO.2/Chapter03/links/link_03/build.xml b/Pro Java 7 NIO.2/Chapter03/links/link_03/build.xml new file mode 100644 index 0000000..5046ce1 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter03/links/link_03/build.xml @@ -0,0 +1,74 @@ + + + + + + + + + + + Builds, tests, and runs the project link_03. + + + diff --git a/Pro Java 7 NIO.2/Chapter03/links/link_03/build/built-jar.properties b/Pro Java 7 NIO.2/Chapter03/links/link_03/build/built-jar.properties new file mode 100644 index 0000000..d09d9be --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter03/links/link_03/build/built-jar.properties @@ -0,0 +1,4 @@ +#Sun, 16 Oct 2011 16:40:37 +0200 + + +C\:\\NIO\\links\\link_03= diff --git a/Pro Java 7 NIO.2/Chapter03/links/link_03/build/classes/link_03/Main.class b/Pro Java 7 NIO.2/Chapter03/links/link_03/build/classes/link_03/Main.class new file mode 100644 index 0000000..9af762f Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter03/links/link_03/build/classes/link_03/Main.class differ diff --git a/Pro Java 7 NIO.2/Chapter03/links/link_03/dist/README.TXT b/Pro Java 7 NIO.2/Chapter03/links/link_03/dist/README.TXT new file mode 100644 index 0000000..aa7a470 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter03/links/link_03/dist/README.TXT @@ -0,0 +1,32 @@ +======================== +BUILD OUTPUT DESCRIPTION +======================== + +When you build an Java application project that has a main class, the IDE +automatically copies all of the JAR +files on the projects classpath to your projects dist/lib folder. The IDE +also adds each of the JAR files to the Class-Path element in the application +JAR files manifest file (MANIFEST.MF). + +To run the project from the command line, go to the dist folder and +type the following: + +java -jar "link_03.jar" + +To distribute this project, zip up the dist folder (including the lib folder) +and distribute the ZIP file. + +Notes: + +* If two JAR files on the project classpath have the same name, only the first +JAR file is copied to the lib folder. +* Only JAR files are copied to the lib folder. +If the classpath contains other types of files or folders, these files (folders) +are not copied. +* If a library on the projects classpath also has a Class-Path element +specified in the manifest,the content of the Class-Path element has to be on +the projects runtime path. +* To set a main class in a standard Java project, right-click the project node +in the Projects window and choose Properties. Then click Run and enter the +class name in the Main Class field. Alternatively, you can manually type the +class name in the manifest Main-Class element. diff --git a/Pro Java 7 NIO.2/Chapter03/links/link_03/dist/link_03.jar b/Pro Java 7 NIO.2/Chapter03/links/link_03/dist/link_03.jar new file mode 100644 index 0000000..8319741 Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter03/links/link_03/dist/link_03.jar differ diff --git a/Pro Java 7 NIO.2/Chapter03/links/link_03/manifest.mf b/Pro Java 7 NIO.2/Chapter03/links/link_03/manifest.mf new file mode 100644 index 0000000..328e8e5 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter03/links/link_03/manifest.mf @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +X-COMMENT: Main-Class will be added automatically by build + diff --git a/Pro Java 7 NIO.2/Chapter03/links/link_03/nbproject/build-impl.xml b/Pro Java 7 NIO.2/Chapter03/links/link_03/nbproject/build-impl.xml new file mode 100644 index 0000000..25b0c76 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter03/links/link_03/nbproject/build-impl.xml @@ -0,0 +1,1041 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set src.dir + Must set test.src.dir + Must set build.dir + Must set dist.dir + Must set build.classes.dir + Must set dist.javadoc.dir + Must set build.test.classes.dir + Must set build.test.results.dir + Must set build.classes.excludes + Must set dist.jar + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set JVM to use for profiling in profiler.info.jvm + Must set profiler agent JVM arguments in profiler.info.jvmargs.agent + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + + + + + + java -cp "${run.classpath.with.dist.jar}" ${main.class} + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + java -jar "${dist.jar.resolved}" + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set run.class + + + + Must select one file in the IDE or set run.class + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set debug.class + + + + + Must select one file in the IDE or set debug.class + + + + + Must set fix.includes + + + + + + + + + + + + + + + + + Must select one file in the IDE or set profile.class + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + Some tests failed; see details above. + + + + + + + + + Must select some files in the IDE or set test.includes + + + + Some tests failed; see details above. + + + + + Must select one file in the IDE or set test.class + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Pro Java 7 NIO.2/Chapter03/links/link_03/nbproject/genfiles.properties b/Pro Java 7 NIO.2/Chapter03/links/link_03/nbproject/genfiles.properties new file mode 100644 index 0000000..d668051 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter03/links/link_03/nbproject/genfiles.properties @@ -0,0 +1,8 @@ +build.xml.data.CRC32=32a4eb26 +build.xml.script.CRC32=2e58643c +build.xml.stylesheet.CRC32=28e38971@1.43.1.45 +# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. +# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. +nbproject/build-impl.xml.data.CRC32=32a4eb26 +nbproject/build-impl.xml.script.CRC32=51cbe57f +nbproject/build-impl.xml.stylesheet.CRC32=0c01fd8e@1.43.1.45 diff --git a/Pro Java 7 NIO.2/Chapter03/links/link_03/nbproject/private/config.properties b/Pro Java 7 NIO.2/Chapter03/links/link_03/nbproject/private/config.properties new file mode 100644 index 0000000..e69de29 diff --git a/Pro Java 7 NIO.2/Chapter03/links/link_03/nbproject/private/private.properties b/Pro Java 7 NIO.2/Chapter03/links/link_03/nbproject/private/private.properties new file mode 100644 index 0000000..a5ab360 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter03/links/link_03/nbproject/private/private.properties @@ -0,0 +1,6 @@ +compile.on.save=true +do.depend=false +do.jar=true +javac.debug=true +javadoc.preview=true +user.properties.file=C:\\Users\\Leo\\.netbeans\\7.0\\build.properties diff --git a/Pro Java 7 NIO.2/Chapter03/links/link_03/nbproject/private/private.xml b/Pro Java 7 NIO.2/Chapter03/links/link_03/nbproject/private/private.xml new file mode 100644 index 0000000..c1f155a --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter03/links/link_03/nbproject/private/private.xml @@ -0,0 +1,4 @@ + + + + diff --git a/Pro Java 7 NIO.2/Chapter03/links/link_03/nbproject/project.properties b/Pro Java 7 NIO.2/Chapter03/links/link_03/nbproject/project.properties new file mode 100644 index 0000000..4f124a2 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter03/links/link_03/nbproject/project.properties @@ -0,0 +1,72 @@ +annotation.processing.enabled=true +annotation.processing.enabled.in.editor=false +annotation.processing.run.all.processors=true +annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output +application.title=link_03 +application.vendor=Leo +build.classes.dir=${build.dir}/classes +build.classes.excludes=**/*.java,**/*.form +# This directory is removed when the project is cleaned: +build.dir=build +build.generated.dir=${build.dir}/generated +build.generated.sources.dir=${build.dir}/generated-sources +# Only compile against the classpath explicitly listed here: +build.sysclasspath=ignore +build.test.classes.dir=${build.dir}/test/classes +build.test.results.dir=${build.dir}/test/results +# Uncomment to specify the preferred debugger connection transport: +#debug.transport=dt_socket +debug.classpath=\ + ${run.classpath} +debug.test.classpath=\ + ${run.test.classpath} +# This directory is removed when the project is cleaned: +dist.dir=dist +dist.jar=${dist.dir}/link_03.jar +dist.javadoc.dir=${dist.dir}/javadoc +endorsed.classpath= +excludes= +includes=** +jar.compress=false +javac.classpath= +# Space-separated list of extra javac options +javac.compilerargs= +javac.deprecation=false +javac.processorpath=\ + ${javac.classpath} +javac.source=1.7 +javac.target=1.7 +javac.test.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +javac.test.processorpath=\ + ${javac.test.classpath} +javadoc.additionalparam= +javadoc.author=false +javadoc.encoding=${source.encoding} +javadoc.noindex=false +javadoc.nonavbar=false +javadoc.notree=false +javadoc.private=false +javadoc.splitindex=true +javadoc.use=true +javadoc.version=false +javadoc.windowtitle= +main.class=link_03.Main +manifest.file=manifest.mf +meta.inf.dir=${src.dir}/META-INF +mkdist.disabled=false +platform.active=default_platform +run.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +# Space-separated list of JVM arguments used when running the project +# (you may also define separate properties like run-sys-prop.name=value instead of -Dname=value +# or test-sys-prop.name=value to set system properties for unit tests): +run.jvmargs= +run.test.classpath=\ + ${javac.test.classpath}:\ + ${build.test.classes.dir} +source.encoding=UTF-8 +src.dir=src +test.src.dir=test diff --git a/Pro Java 7 NIO.2/Chapter03/links/link_03/nbproject/project.xml b/Pro Java 7 NIO.2/Chapter03/links/link_03/nbproject/project.xml new file mode 100644 index 0000000..7f9af02 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter03/links/link_03/nbproject/project.xml @@ -0,0 +1,15 @@ + + + org.netbeans.modules.java.j2seproject + + + link_03 + + + + + + + + + diff --git a/Pro Java 7 NIO.2/Chapter03/links/link_03/src/link_03/Main.java b/Pro Java 7 NIO.2/Chapter03/links/link_03/src/link_03/Main.java new file mode 100644 index 0000000..de1ab1a --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter03/links/link_03/src/link_03/Main.java @@ -0,0 +1,53 @@ +package link_03; + +import java.io.IOException; +import java.nio.file.FileSystems; +import java.nio.file.Files; +import java.nio.file.Path; + +/** + * + * @author Apress + */ +public class Main { + + public static void main(String[] args) { + + Path link = FileSystems.getDefault().getPath("rafael.nadal.5"); + Path target = FileSystems.getDefault().getPath("C:/rafaelnadal/photos", "rafa_winner.jpg"); + + try { + Files.createSymbolicLink(link, target); + } catch (IOException | UnsupportedOperationException | SecurityException e) { + if (e instanceof SecurityException) { + System.err.println("Permision denied!"); + } + if (e instanceof UnsupportedOperationException) { + System.err.println("An unsupported operation was detected!"); + } + if (e instanceof IOException) { + System.err.println("An I/O error occured!"); + } + System.err.println(e); + } + + //check if a path is a symbolic link - solution 1 + boolean link_isSymbolicLink_1 = Files.isSymbolicLink(link); + boolean target_isSymbolicLink_1 = Files.isSymbolicLink(target); + System.out.println(link.toString() + " is a symbolic link ? " + link_isSymbolicLink_1); + System.out.println(target.toString() + " is a symbolic link ? " + target_isSymbolicLink_1); + + //check if a path is a symbolic link - solution 2 + try { + Boolean link_isSymbolicLink_2 = (Boolean) Files.getAttribute(link, "basic:isSymbolicLink"); + Boolean target_isSymbolicLink_2 = (Boolean) Files.getAttribute(target, "basic:isSymbolicLink"); + + System.out.println(link.toString() + " is a symbolic link ? " + link_isSymbolicLink_2); + System.out.println(target.toString() + " is a symbolic link ? " + target_isSymbolicLink_2); + } catch (IOException | UnsupportedOperationException e) { + System.err.println(e); + } + + + } +} diff --git a/Pro Java 7 NIO.2/Chapter03/links/link_04/build.xml b/Pro Java 7 NIO.2/Chapter03/links/link_04/build.xml new file mode 100644 index 0000000..627263f --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter03/links/link_04/build.xml @@ -0,0 +1,74 @@ + + + + + + + + + + + Builds, tests, and runs the project link_04. + + + diff --git a/Pro Java 7 NIO.2/Chapter03/links/link_04/build/built-jar.properties b/Pro Java 7 NIO.2/Chapter03/links/link_04/build/built-jar.properties new file mode 100644 index 0000000..1526daf --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter03/links/link_04/build/built-jar.properties @@ -0,0 +1,4 @@ +#Sun, 16 Oct 2011 16:41:58 +0200 + + +C\:\\NIO\\links\\link_04= diff --git a/Pro Java 7 NIO.2/Chapter03/links/link_04/build/classes/link_04/Main.class b/Pro Java 7 NIO.2/Chapter03/links/link_04/build/classes/link_04/Main.class new file mode 100644 index 0000000..b0ce345 Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter03/links/link_04/build/classes/link_04/Main.class differ diff --git a/Pro Java 7 NIO.2/Chapter03/links/link_04/dist/README.TXT b/Pro Java 7 NIO.2/Chapter03/links/link_04/dist/README.TXT new file mode 100644 index 0000000..f5c1aef --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter03/links/link_04/dist/README.TXT @@ -0,0 +1,32 @@ +======================== +BUILD OUTPUT DESCRIPTION +======================== + +When you build an Java application project that has a main class, the IDE +automatically copies all of the JAR +files on the projects classpath to your projects dist/lib folder. The IDE +also adds each of the JAR files to the Class-Path element in the application +JAR files manifest file (MANIFEST.MF). + +To run the project from the command line, go to the dist folder and +type the following: + +java -jar "link_04.jar" + +To distribute this project, zip up the dist folder (including the lib folder) +and distribute the ZIP file. + +Notes: + +* If two JAR files on the project classpath have the same name, only the first +JAR file is copied to the lib folder. +* Only JAR files are copied to the lib folder. +If the classpath contains other types of files or folders, these files (folders) +are not copied. +* If a library on the projects classpath also has a Class-Path element +specified in the manifest,the content of the Class-Path element has to be on +the projects runtime path. +* To set a main class in a standard Java project, right-click the project node +in the Projects window and choose Properties. Then click Run and enter the +class name in the Main Class field. Alternatively, you can manually type the +class name in the manifest Main-Class element. diff --git a/Pro Java 7 NIO.2/Chapter03/links/link_04/dist/link_04.jar b/Pro Java 7 NIO.2/Chapter03/links/link_04/dist/link_04.jar new file mode 100644 index 0000000..58d458b Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter03/links/link_04/dist/link_04.jar differ diff --git a/Pro Java 7 NIO.2/Chapter03/links/link_04/manifest.mf b/Pro Java 7 NIO.2/Chapter03/links/link_04/manifest.mf new file mode 100644 index 0000000..328e8e5 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter03/links/link_04/manifest.mf @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +X-COMMENT: Main-Class will be added automatically by build + diff --git a/Pro Java 7 NIO.2/Chapter03/links/link_04/nbproject/build-impl.xml b/Pro Java 7 NIO.2/Chapter03/links/link_04/nbproject/build-impl.xml new file mode 100644 index 0000000..6ae285c --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter03/links/link_04/nbproject/build-impl.xml @@ -0,0 +1,1041 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set src.dir + Must set test.src.dir + Must set build.dir + Must set dist.dir + Must set build.classes.dir + Must set dist.javadoc.dir + Must set build.test.classes.dir + Must set build.test.results.dir + Must set build.classes.excludes + Must set dist.jar + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set JVM to use for profiling in profiler.info.jvm + Must set profiler agent JVM arguments in profiler.info.jvmargs.agent + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + + + + + + java -cp "${run.classpath.with.dist.jar}" ${main.class} + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + java -jar "${dist.jar.resolved}" + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set run.class + + + + Must select one file in the IDE or set run.class + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set debug.class + + + + + Must select one file in the IDE or set debug.class + + + + + Must set fix.includes + + + + + + + + + + + + + + + + + Must select one file in the IDE or set profile.class + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + Some tests failed; see details above. + + + + + + + + + Must select some files in the IDE or set test.includes + + + + Some tests failed; see details above. + + + + + Must select one file in the IDE or set test.class + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Pro Java 7 NIO.2/Chapter03/links/link_04/nbproject/genfiles.properties b/Pro Java 7 NIO.2/Chapter03/links/link_04/nbproject/genfiles.properties new file mode 100644 index 0000000..ea229f4 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter03/links/link_04/nbproject/genfiles.properties @@ -0,0 +1,8 @@ +build.xml.data.CRC32=0ade4fd4 +build.xml.script.CRC32=1fb24af5 +build.xml.stylesheet.CRC32=28e38971@1.43.1.45 +# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. +# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. +nbproject/build-impl.xml.data.CRC32=0ade4fd4 +nbproject/build-impl.xml.script.CRC32=c1c757e4 +nbproject/build-impl.xml.stylesheet.CRC32=0c01fd8e@1.43.1.45 diff --git a/Pro Java 7 NIO.2/Chapter03/links/link_04/nbproject/private/config.properties b/Pro Java 7 NIO.2/Chapter03/links/link_04/nbproject/private/config.properties new file mode 100644 index 0000000..e69de29 diff --git a/Pro Java 7 NIO.2/Chapter03/links/link_04/nbproject/private/private.properties b/Pro Java 7 NIO.2/Chapter03/links/link_04/nbproject/private/private.properties new file mode 100644 index 0000000..a5ab360 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter03/links/link_04/nbproject/private/private.properties @@ -0,0 +1,6 @@ +compile.on.save=true +do.depend=false +do.jar=true +javac.debug=true +javadoc.preview=true +user.properties.file=C:\\Users\\Leo\\.netbeans\\7.0\\build.properties diff --git a/Pro Java 7 NIO.2/Chapter03/links/link_04/nbproject/private/private.xml b/Pro Java 7 NIO.2/Chapter03/links/link_04/nbproject/private/private.xml new file mode 100644 index 0000000..c1f155a --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter03/links/link_04/nbproject/private/private.xml @@ -0,0 +1,4 @@ + + + + diff --git a/Pro Java 7 NIO.2/Chapter03/links/link_04/nbproject/project.properties b/Pro Java 7 NIO.2/Chapter03/links/link_04/nbproject/project.properties new file mode 100644 index 0000000..347bdaa --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter03/links/link_04/nbproject/project.properties @@ -0,0 +1,72 @@ +annotation.processing.enabled=true +annotation.processing.enabled.in.editor=false +annotation.processing.run.all.processors=true +annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output +application.title=link_04 +application.vendor=Leo +build.classes.dir=${build.dir}/classes +build.classes.excludes=**/*.java,**/*.form +# This directory is removed when the project is cleaned: +build.dir=build +build.generated.dir=${build.dir}/generated +build.generated.sources.dir=${build.dir}/generated-sources +# Only compile against the classpath explicitly listed here: +build.sysclasspath=ignore +build.test.classes.dir=${build.dir}/test/classes +build.test.results.dir=${build.dir}/test/results +# Uncomment to specify the preferred debugger connection transport: +#debug.transport=dt_socket +debug.classpath=\ + ${run.classpath} +debug.test.classpath=\ + ${run.test.classpath} +# This directory is removed when the project is cleaned: +dist.dir=dist +dist.jar=${dist.dir}/link_04.jar +dist.javadoc.dir=${dist.dir}/javadoc +endorsed.classpath= +excludes= +includes=** +jar.compress=false +javac.classpath= +# Space-separated list of extra javac options +javac.compilerargs= +javac.deprecation=false +javac.processorpath=\ + ${javac.classpath} +javac.source=1.7 +javac.target=1.7 +javac.test.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +javac.test.processorpath=\ + ${javac.test.classpath} +javadoc.additionalparam= +javadoc.author=false +javadoc.encoding=${source.encoding} +javadoc.noindex=false +javadoc.nonavbar=false +javadoc.notree=false +javadoc.private=false +javadoc.splitindex=true +javadoc.use=true +javadoc.version=false +javadoc.windowtitle= +main.class=link_04.Main +manifest.file=manifest.mf +meta.inf.dir=${src.dir}/META-INF +mkdist.disabled=false +platform.active=default_platform +run.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +# Space-separated list of JVM arguments used when running the project +# (you may also define separate properties like run-sys-prop.name=value instead of -Dname=value +# or test-sys-prop.name=value to set system properties for unit tests): +run.jvmargs= +run.test.classpath=\ + ${javac.test.classpath}:\ + ${build.test.classes.dir} +source.encoding=UTF-8 +src.dir=src +test.src.dir=test diff --git a/Pro Java 7 NIO.2/Chapter03/links/link_04/nbproject/project.xml b/Pro Java 7 NIO.2/Chapter03/links/link_04/nbproject/project.xml new file mode 100644 index 0000000..d83565f --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter03/links/link_04/nbproject/project.xml @@ -0,0 +1,15 @@ + + + org.netbeans.modules.java.j2seproject + + + link_04 + + + + + + + + + diff --git a/Pro Java 7 NIO.2/Chapter03/links/link_04/src/link_04/Main.java b/Pro Java 7 NIO.2/Chapter03/links/link_04/src/link_04/Main.java new file mode 100644 index 0000000..9c3d8c6 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter03/links/link_04/src/link_04/Main.java @@ -0,0 +1,41 @@ +package link_04; + +import java.io.IOException; +import java.nio.file.FileSystems; +import java.nio.file.Files; +import java.nio.file.Path; + +/** + * + * @author Apress + */ +public class Main { + + public static void main(String[] args) { + + Path link = FileSystems.getDefault().getPath("rafael.nadal.6"); + Path target = FileSystems.getDefault().getPath("C:/rafaelnadal/photos", "rafa_winner.jpg"); + + try { + Files.createSymbolicLink(link, target); + } catch (IOException | UnsupportedOperationException | SecurityException e) { + if (e instanceof SecurityException) { + System.err.println("Permision denied!"); + } + if (e instanceof UnsupportedOperationException) { + System.err.println("An unsupported operation was detected!"); + } + if (e instanceof IOException) { + System.err.println("An I/O error occured!"); + } + System.err.println(e); + } + + try { + Path linkedpath = Files.readSymbolicLink(link); + System.out.println(linkedpath.toString()); + } catch (IOException e) { + System.err.println(e); + } + } +} diff --git a/Pro Java 7 NIO.2/Chapter03/links/link_05/build.xml b/Pro Java 7 NIO.2/Chapter03/links/link_05/build.xml new file mode 100644 index 0000000..bf7c15f --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter03/links/link_05/build.xml @@ -0,0 +1,74 @@ + + + + + + + + + + + Builds, tests, and runs the project link_05. + + + diff --git a/Pro Java 7 NIO.2/Chapter03/links/link_05/build/built-jar.properties b/Pro Java 7 NIO.2/Chapter03/links/link_05/build/built-jar.properties new file mode 100644 index 0000000..adf58b2 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter03/links/link_05/build/built-jar.properties @@ -0,0 +1,4 @@ +#Sun, 16 Oct 2011 16:42:53 +0200 + + +C\:\\NIO\\links\\link_05= diff --git a/Pro Java 7 NIO.2/Chapter03/links/link_05/build/classes/link_05/Main.class b/Pro Java 7 NIO.2/Chapter03/links/link_05/build/classes/link_05/Main.class new file mode 100644 index 0000000..d9de0d3 Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter03/links/link_05/build/classes/link_05/Main.class differ diff --git a/Pro Java 7 NIO.2/Chapter03/links/link_05/dist/README.TXT b/Pro Java 7 NIO.2/Chapter03/links/link_05/dist/README.TXT new file mode 100644 index 0000000..4fd803e --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter03/links/link_05/dist/README.TXT @@ -0,0 +1,32 @@ +======================== +BUILD OUTPUT DESCRIPTION +======================== + +When you build an Java application project that has a main class, the IDE +automatically copies all of the JAR +files on the projects classpath to your projects dist/lib folder. The IDE +also adds each of the JAR files to the Class-Path element in the application +JAR files manifest file (MANIFEST.MF). + +To run the project from the command line, go to the dist folder and +type the following: + +java -jar "link_05.jar" + +To distribute this project, zip up the dist folder (including the lib folder) +and distribute the ZIP file. + +Notes: + +* If two JAR files on the project classpath have the same name, only the first +JAR file is copied to the lib folder. +* Only JAR files are copied to the lib folder. +If the classpath contains other types of files or folders, these files (folders) +are not copied. +* If a library on the projects classpath also has a Class-Path element +specified in the manifest,the content of the Class-Path element has to be on +the projects runtime path. +* To set a main class in a standard Java project, right-click the project node +in the Projects window and choose Properties. Then click Run and enter the +class name in the Main Class field. Alternatively, you can manually type the +class name in the manifest Main-Class element. diff --git a/Pro Java 7 NIO.2/Chapter03/links/link_05/dist/link_05.jar b/Pro Java 7 NIO.2/Chapter03/links/link_05/dist/link_05.jar new file mode 100644 index 0000000..be80421 Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter03/links/link_05/dist/link_05.jar differ diff --git a/Pro Java 7 NIO.2/Chapter03/links/link_05/manifest.mf b/Pro Java 7 NIO.2/Chapter03/links/link_05/manifest.mf new file mode 100644 index 0000000..328e8e5 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter03/links/link_05/manifest.mf @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +X-COMMENT: Main-Class will be added automatically by build + diff --git a/Pro Java 7 NIO.2/Chapter03/links/link_05/nbproject/build-impl.xml b/Pro Java 7 NIO.2/Chapter03/links/link_05/nbproject/build-impl.xml new file mode 100644 index 0000000..03da401 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter03/links/link_05/nbproject/build-impl.xml @@ -0,0 +1,1041 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set src.dir + Must set test.src.dir + Must set build.dir + Must set dist.dir + Must set build.classes.dir + Must set dist.javadoc.dir + Must set build.test.classes.dir + Must set build.test.results.dir + Must set build.classes.excludes + Must set dist.jar + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set JVM to use for profiling in profiler.info.jvm + Must set profiler agent JVM arguments in profiler.info.jvmargs.agent + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + + + + + + java -cp "${run.classpath.with.dist.jar}" ${main.class} + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + java -jar "${dist.jar.resolved}" + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set run.class + + + + Must select one file in the IDE or set run.class + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set debug.class + + + + + Must select one file in the IDE or set debug.class + + + + + Must set fix.includes + + + + + + + + + + + + + + + + + Must select one file in the IDE or set profile.class + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + Some tests failed; see details above. + + + + + + + + + Must select some files in the IDE or set test.includes + + + + Some tests failed; see details above. + + + + + Must select one file in the IDE or set test.class + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Pro Java 7 NIO.2/Chapter03/links/link_05/nbproject/genfiles.properties b/Pro Java 7 NIO.2/Chapter03/links/link_05/nbproject/genfiles.properties new file mode 100644 index 0000000..19f75ee --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter03/links/link_05/nbproject/genfiles.properties @@ -0,0 +1,8 @@ +build.xml.data.CRC32=02cdc3f2 +build.xml.script.CRC32=1491f3b6 +build.xml.stylesheet.CRC32=28e38971@1.43.1.45 +# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. +# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. +nbproject/build-impl.xml.data.CRC32=02cdc3f2 +nbproject/build-impl.xml.script.CRC32=7be56857 +nbproject/build-impl.xml.stylesheet.CRC32=0c01fd8e@1.43.1.45 diff --git a/Pro Java 7 NIO.2/Chapter03/links/link_05/nbproject/private/config.properties b/Pro Java 7 NIO.2/Chapter03/links/link_05/nbproject/private/config.properties new file mode 100644 index 0000000..e69de29 diff --git a/Pro Java 7 NIO.2/Chapter03/links/link_05/nbproject/private/private.properties b/Pro Java 7 NIO.2/Chapter03/links/link_05/nbproject/private/private.properties new file mode 100644 index 0000000..a5ab360 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter03/links/link_05/nbproject/private/private.properties @@ -0,0 +1,6 @@ +compile.on.save=true +do.depend=false +do.jar=true +javac.debug=true +javadoc.preview=true +user.properties.file=C:\\Users\\Leo\\.netbeans\\7.0\\build.properties diff --git a/Pro Java 7 NIO.2/Chapter03/links/link_05/nbproject/private/private.xml b/Pro Java 7 NIO.2/Chapter03/links/link_05/nbproject/private/private.xml new file mode 100644 index 0000000..c1f155a --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter03/links/link_05/nbproject/private/private.xml @@ -0,0 +1,4 @@ + + + + diff --git a/Pro Java 7 NIO.2/Chapter03/links/link_05/nbproject/project.properties b/Pro Java 7 NIO.2/Chapter03/links/link_05/nbproject/project.properties new file mode 100644 index 0000000..31d0e6b --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter03/links/link_05/nbproject/project.properties @@ -0,0 +1,72 @@ +annotation.processing.enabled=true +annotation.processing.enabled.in.editor=false +annotation.processing.run.all.processors=true +annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output +application.title=link_05 +application.vendor=Leo +build.classes.dir=${build.dir}/classes +build.classes.excludes=**/*.java,**/*.form +# This directory is removed when the project is cleaned: +build.dir=build +build.generated.dir=${build.dir}/generated +build.generated.sources.dir=${build.dir}/generated-sources +# Only compile against the classpath explicitly listed here: +build.sysclasspath=ignore +build.test.classes.dir=${build.dir}/test/classes +build.test.results.dir=${build.dir}/test/results +# Uncomment to specify the preferred debugger connection transport: +#debug.transport=dt_socket +debug.classpath=\ + ${run.classpath} +debug.test.classpath=\ + ${run.test.classpath} +# This directory is removed when the project is cleaned: +dist.dir=dist +dist.jar=${dist.dir}/link_05.jar +dist.javadoc.dir=${dist.dir}/javadoc +endorsed.classpath= +excludes= +includes=** +jar.compress=false +javac.classpath= +# Space-separated list of extra javac options +javac.compilerargs= +javac.deprecation=false +javac.processorpath=\ + ${javac.classpath} +javac.source=1.7 +javac.target=1.7 +javac.test.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +javac.test.processorpath=\ + ${javac.test.classpath} +javadoc.additionalparam= +javadoc.author=false +javadoc.encoding=${source.encoding} +javadoc.noindex=false +javadoc.nonavbar=false +javadoc.notree=false +javadoc.private=false +javadoc.splitindex=true +javadoc.use=true +javadoc.version=false +javadoc.windowtitle= +main.class=link_05.Main +manifest.file=manifest.mf +meta.inf.dir=${src.dir}/META-INF +mkdist.disabled=false +platform.active=default_platform +run.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +# Space-separated list of JVM arguments used when running the project +# (you may also define separate properties like run-sys-prop.name=value instead of -Dname=value +# or test-sys-prop.name=value to set system properties for unit tests): +run.jvmargs= +run.test.classpath=\ + ${javac.test.classpath}:\ + ${build.test.classes.dir} +source.encoding=UTF-8 +src.dir=src +test.src.dir=test diff --git a/Pro Java 7 NIO.2/Chapter03/links/link_05/nbproject/project.xml b/Pro Java 7 NIO.2/Chapter03/links/link_05/nbproject/project.xml new file mode 100644 index 0000000..9f985d2 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter03/links/link_05/nbproject/project.xml @@ -0,0 +1,15 @@ + + + org.netbeans.modules.java.j2seproject + + + link_05 + + + + + + + + + diff --git a/Pro Java 7 NIO.2/Chapter03/links/link_05/src/link_05/Main.java b/Pro Java 7 NIO.2/Chapter03/links/link_05/src/link_05/Main.java new file mode 100644 index 0000000..cc5d45b --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter03/links/link_05/src/link_05/Main.java @@ -0,0 +1,40 @@ +package link_05; + +import java.io.IOException; +import java.nio.file.FileSystems; +import java.nio.file.Files; +import java.nio.file.Path; + +/** + * + * @author Apress + */ +public class Main { + + public static void main(String[] args) { + + Path link = FileSystems.getDefault().getPath("rafael.nadal.7"); + Path target = FileSystems.getDefault().getPath("C:/rafaelnadal/photos", "rafa_winner.jpg"); + + try { + Files.createSymbolicLink(link, target); + + if (Files.isSameFile(link, target)) { + System.out.println(link + " and " + target + " point to the same location!"); + } else { + System.out.println(link + " and " + target + " point to different locations!"); + } + } catch (IOException | UnsupportedOperationException | SecurityException e) { + if (e instanceof SecurityException) { + System.err.println("Permision denied!"); + } + if (e instanceof UnsupportedOperationException) { + System.err.println("An unsupported operation was detected!"); + } + if (e instanceof IOException) { + System.err.println("An I/O error occured!"); + } + System.err.println(e); + } + } +} diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_01/build.xml b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_01/build.xml new file mode 100644 index 0000000..8839b34 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_01/build.xml @@ -0,0 +1,74 @@ + + + + + + + + + + + Builds, tests, and runs the project ff_01. + + + diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_01/build/built-jar.properties b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_01/build/built-jar.properties new file mode 100644 index 0000000..9bb10f3 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_01/build/built-jar.properties @@ -0,0 +1,4 @@ +#Mon, 17 Oct 2011 06:26:27 +0200 + + +C\:\\NIO\\filesandfolders\\ff_01= diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_01/build/classes/ff_01/Main.class b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_01/build/classes/ff_01/Main.class new file mode 100644 index 0000000..7cf1c90 Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_01/build/classes/ff_01/Main.class differ diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_01/dist/README.TXT b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_01/dist/README.TXT new file mode 100644 index 0000000..8fbf288 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_01/dist/README.TXT @@ -0,0 +1,33 @@ +======================== +BUILD OUTPUT DESCRIPTION +======================== + +When you build an Java application project that has a main class, the IDE +automatically copies all of the JAR +files on the projects classpath to your projects dist/lib folder. The IDE +also adds each of the JAR files to the Class-Path element in the application +JAR files manifest file (MANIFEST.MF). + +To run the project from the command line, go to the dist folder and +type the following: + +java -jar "ff_01.jar" + +To distribute this project, zip up the dist folder (including the lib folder) +and distribute the ZIP file. + +Notes: + +* If two JAR files on the project classpath have the same name, only the first +JAR file is copied to the lib folder. +* Only JAR files are copied to the lib folder. +If the classpath contains other types of files or folders, none of the +classpath elements are copied to the lib folder. In such a case, +you need to copy the classpath elements to the lib folder manually after the build. +* If a library on the projects classpath also has a Class-Path element +specified in the manifest,the content of the Class-Path element has to be on +the projects runtime path. +* To set a main class in a standard Java project, right-click the project node +in the Projects window and choose Properties. Then click Run and enter the +class name in the Main Class field. Alternatively, you can manually type the +class name in the manifest Main-Class element. diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_01/dist/ff_01.jar b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_01/dist/ff_01.jar new file mode 100644 index 0000000..2a5e489 Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_01/dist/ff_01.jar differ diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_01/lib/CopyLibs/org-netbeans-modules-java-j2seproject-copylibstask.jar b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_01/lib/CopyLibs/org-netbeans-modules-java-j2seproject-copylibstask.jar new file mode 100644 index 0000000..5ee71d2 Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_01/lib/CopyLibs/org-netbeans-modules-java-j2seproject-copylibstask.jar differ diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_01/lib/junit/junit-3.8.2-api.zip b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_01/lib/junit/junit-3.8.2-api.zip new file mode 100644 index 0000000..6d792fd Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_01/lib/junit/junit-3.8.2-api.zip differ diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_01/lib/junit/junit-3.8.2.jar b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_01/lib/junit/junit-3.8.2.jar new file mode 100644 index 0000000..d835872 Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_01/lib/junit/junit-3.8.2.jar differ diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_01/lib/junit_4/junit-4.5-api.zip b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_01/lib/junit_4/junit-4.5-api.zip new file mode 100644 index 0000000..5748c44 Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_01/lib/junit_4/junit-4.5-api.zip differ diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_01/lib/junit_4/junit-4.5-src.jar b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_01/lib/junit_4/junit-4.5-src.jar new file mode 100644 index 0000000..18774a5 Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_01/lib/junit_4/junit-4.5-src.jar differ diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_01/lib/junit_4/junit-4.5.jar b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_01/lib/junit_4/junit-4.5.jar new file mode 100644 index 0000000..83f8bc7 Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_01/lib/junit_4/junit-4.5.jar differ diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_01/lib/nblibraries.properties b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_01/lib/nblibraries.properties new file mode 100644 index 0000000..9137b06 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_01/lib/nblibraries.properties @@ -0,0 +1,12 @@ +libs.CopyLibs.classpath=\ + ${base}/CopyLibs/org-netbeans-modules-java-j2seproject-copylibstask.jar +libs.junit.classpath=\ + ${base}/junit/junit-3.8.2.jar +libs.junit.javadoc=\ + ${base}/junit/junit-3.8.2-api.zip +libs.junit_4.classpath=\ + ${base}/junit_4/junit-4.5.jar +libs.junit_4.javadoc=\ + ${base}/junit_4/junit-4.5-api.zip +libs.junit_4.src=\ + ${base}/junit_4/junit-4.5-src.jar diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_01/manifest.mf b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_01/manifest.mf new file mode 100644 index 0000000..328e8e5 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_01/manifest.mf @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +X-COMMENT: Main-Class will be added automatically by build + diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_01/nbproject/build-impl.xml b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_01/nbproject/build-impl.xml new file mode 100644 index 0000000..0a60dec --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_01/nbproject/build-impl.xml @@ -0,0 +1,1066 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set src.dir + Must set test.src.dir + Must set build.dir + Must set dist.dir + Must set build.classes.dir + Must set dist.javadoc.dir + Must set build.test.classes.dir + Must set build.test.results.dir + Must set build.classes.excludes + Must set dist.jar + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set JVM to use for profiling in profiler.info.jvm + Must set profiler agent JVM arguments in profiler.info.jvmargs.agent + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + + + + + + java -cp "${run.classpath.with.dist.jar}" ${main.class} + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + java -jar "${dist.jar.resolved}" + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set run.class + + + + Must select one file in the IDE or set run.class + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set debug.class + + + + + Must select one file in the IDE or set debug.class + + + + + Must set fix.includes + + + + + + + + + + + + + + + + + Must select one file in the IDE or set profile.class + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + Some tests failed; see details above. + + + + + + + + + Must select some files in the IDE or set test.includes + + + + Some tests failed; see details above. + + + + + Must select one file in the IDE or set test.class + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_01/nbproject/genfiles.properties b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_01/nbproject/genfiles.properties new file mode 100644 index 0000000..c5c7e3f --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_01/nbproject/genfiles.properties @@ -0,0 +1,8 @@ +build.xml.data.CRC32=0b411c32 +build.xml.script.CRC32=a86b5032 +build.xml.stylesheet.CRC32=28e38971@1.43.1.45 +# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. +# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. +nbproject/build-impl.xml.data.CRC32=0b411c32 +nbproject/build-impl.xml.script.CRC32=5f7c7205 +nbproject/build-impl.xml.stylesheet.CRC32=0c01fd8e@1.43.1.45 diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_01/nbproject/private/config.properties b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_01/nbproject/private/config.properties new file mode 100644 index 0000000..e69de29 diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_01/nbproject/private/private.properties b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_01/nbproject/private/private.properties new file mode 100644 index 0000000..a5ab360 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_01/nbproject/private/private.properties @@ -0,0 +1,6 @@ +compile.on.save=true +do.depend=false +do.jar=true +javac.debug=true +javadoc.preview=true +user.properties.file=C:\\Users\\Leo\\.netbeans\\7.0\\build.properties diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_01/nbproject/private/private.xml b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_01/nbproject/private/private.xml new file mode 100644 index 0000000..c1f155a --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_01/nbproject/private/private.xml @@ -0,0 +1,4 @@ + + + + diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_01/nbproject/project.properties b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_01/nbproject/project.properties new file mode 100644 index 0000000..e863d4c --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_01/nbproject/project.properties @@ -0,0 +1,74 @@ +annotation.processing.enabled=true +annotation.processing.enabled.in.editor=false +annotation.processing.run.all.processors=true +annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output +application.title=ff_01 +application.vendor=Leo +build.classes.dir=${build.dir}/classes +build.classes.excludes=**/*.java,**/*.form +# This directory is removed when the project is cleaned: +build.dir=build +build.generated.dir=${build.dir}/generated +build.generated.sources.dir=${build.dir}/generated-sources +# Only compile against the classpath explicitly listed here: +build.sysclasspath=ignore +build.test.classes.dir=${build.dir}/test/classes +build.test.results.dir=${build.dir}/test/results +# Uncomment to specify the preferred debugger connection transport: +#debug.transport=dt_socket +debug.classpath=\ + ${run.classpath} +debug.test.classpath=\ + ${run.test.classpath} +# This directory is removed when the project is cleaned: +dist.dir=dist +dist.jar=${dist.dir}/ff_01.jar +dist.javadoc.dir=${dist.dir}/javadoc +endorsed.classpath= +excludes= +includes=** +jar.compress=false +javac.classpath= +# Space-separated list of extra javac options +javac.compilerargs= +javac.deprecation=false +javac.processorpath=\ + ${javac.classpath} +javac.source=1.7 +javac.target=1.7 +javac.test.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir}:\ + ${libs.junit.classpath}:\ + ${libs.junit_4.classpath} +javac.test.processorpath=\ + ${javac.test.classpath} +javadoc.additionalparam= +javadoc.author=false +javadoc.encoding=${source.encoding} +javadoc.noindex=false +javadoc.nonavbar=false +javadoc.notree=false +javadoc.private=false +javadoc.splitindex=true +javadoc.use=true +javadoc.version=false +javadoc.windowtitle= +main.class=ff_01.Main +manifest.file=manifest.mf +meta.inf.dir=${src.dir}/META-INF +mkdist.disabled=false +platform.active=default_platform +run.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +# Space-separated list of JVM arguments used when running the project +# (you may also define separate properties like run-sys-prop.name=value instead of -Dname=value +# or test-sys-prop.name=value to set system properties for unit tests): +run.jvmargs= +run.test.classpath=\ + ${javac.test.classpath}:\ + ${build.test.classes.dir} +source.encoding=UTF-8 +src.dir=src +test.src.dir=test diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_01/nbproject/project.xml b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_01/nbproject/project.xml new file mode 100644 index 0000000..b78fa91 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_01/nbproject/project.xml @@ -0,0 +1,18 @@ + + + org.netbeans.modules.java.j2seproject + + + ff_01 + + + + + + + + + .\lib\nblibraries.properties + + + diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_01/src/ff_01/Main.java b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_01/src/ff_01/Main.java new file mode 100644 index 0000000..eb520fe --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_01/src/ff_01/Main.java @@ -0,0 +1,33 @@ +package ff_01; + +import java.io.IOException; +import java.nio.file.Path; +import java.nio.file.Files; +import java.nio.file.FileSystems; + +/** + * + * @author Apress + */ +public class Main { + + public static void main(String[] args) { + + Path path = FileSystems.getDefault().getPath("C:/rafaelnadal/photos", "rafa_1.jpg"); + + //delete the file + try { + Files.delete(path); + } catch (IOException | SecurityException e) { + System.err.println(e); + } + + //delete if exists + try { + boolean success = Files.deleteIfExists(path); + System.out.println("Delete status: " + success); + } catch (IOException | SecurityException e) { + System.err.println(e); + } + } +} diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_02/build.xml b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_02/build.xml new file mode 100644 index 0000000..5850c7c --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_02/build.xml @@ -0,0 +1,74 @@ + + + + + + + + + + + Builds, tests, and runs the project ff_02. + + + diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_02/build/built-jar.properties b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_02/build/built-jar.properties new file mode 100644 index 0000000..bc9e5c2 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_02/build/built-jar.properties @@ -0,0 +1,4 @@ +#Mon, 17 Oct 2011 06:28:02 +0200 + + +C\:\\NIO\\filesandfolders\\ff_02= diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_02/build/classes/ff_02/Main.class b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_02/build/classes/ff_02/Main.class new file mode 100644 index 0000000..0651603 Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_02/build/classes/ff_02/Main.class differ diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_02/dist/README.TXT b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_02/dist/README.TXT new file mode 100644 index 0000000..810a8d9 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_02/dist/README.TXT @@ -0,0 +1,33 @@ +======================== +BUILD OUTPUT DESCRIPTION +======================== + +When you build an Java application project that has a main class, the IDE +automatically copies all of the JAR +files on the projects classpath to your projects dist/lib folder. The IDE +also adds each of the JAR files to the Class-Path element in the application +JAR files manifest file (MANIFEST.MF). + +To run the project from the command line, go to the dist folder and +type the following: + +java -jar "ff_02.jar" + +To distribute this project, zip up the dist folder (including the lib folder) +and distribute the ZIP file. + +Notes: + +* If two JAR files on the project classpath have the same name, only the first +JAR file is copied to the lib folder. +* Only JAR files are copied to the lib folder. +If the classpath contains other types of files or folders, none of the +classpath elements are copied to the lib folder. In such a case, +you need to copy the classpath elements to the lib folder manually after the build. +* If a library on the projects classpath also has a Class-Path element +specified in the manifest,the content of the Class-Path element has to be on +the projects runtime path. +* To set a main class in a standard Java project, right-click the project node +in the Projects window and choose Properties. Then click Run and enter the +class name in the Main Class field. Alternatively, you can manually type the +class name in the manifest Main-Class element. diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_02/dist/ff_02.jar b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_02/dist/ff_02.jar new file mode 100644 index 0000000..332be5a Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_02/dist/ff_02.jar differ diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_02/lib/CopyLibs/org-netbeans-modules-java-j2seproject-copylibstask.jar b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_02/lib/CopyLibs/org-netbeans-modules-java-j2seproject-copylibstask.jar new file mode 100644 index 0000000..5ee71d2 Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_02/lib/CopyLibs/org-netbeans-modules-java-j2seproject-copylibstask.jar differ diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_02/lib/junit/junit-3.8.2-api.zip b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_02/lib/junit/junit-3.8.2-api.zip new file mode 100644 index 0000000..6d792fd Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_02/lib/junit/junit-3.8.2-api.zip differ diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_02/lib/junit/junit-3.8.2.jar b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_02/lib/junit/junit-3.8.2.jar new file mode 100644 index 0000000..d835872 Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_02/lib/junit/junit-3.8.2.jar differ diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_02/lib/junit_4/junit-4.5-api.zip b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_02/lib/junit_4/junit-4.5-api.zip new file mode 100644 index 0000000..5748c44 Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_02/lib/junit_4/junit-4.5-api.zip differ diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_02/lib/junit_4/junit-4.5-src.jar b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_02/lib/junit_4/junit-4.5-src.jar new file mode 100644 index 0000000..18774a5 Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_02/lib/junit_4/junit-4.5-src.jar differ diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_02/lib/junit_4/junit-4.5.jar b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_02/lib/junit_4/junit-4.5.jar new file mode 100644 index 0000000..83f8bc7 Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_02/lib/junit_4/junit-4.5.jar differ diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_02/lib/nblibraries.properties b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_02/lib/nblibraries.properties new file mode 100644 index 0000000..9137b06 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_02/lib/nblibraries.properties @@ -0,0 +1,12 @@ +libs.CopyLibs.classpath=\ + ${base}/CopyLibs/org-netbeans-modules-java-j2seproject-copylibstask.jar +libs.junit.classpath=\ + ${base}/junit/junit-3.8.2.jar +libs.junit.javadoc=\ + ${base}/junit/junit-3.8.2-api.zip +libs.junit_4.classpath=\ + ${base}/junit_4/junit-4.5.jar +libs.junit_4.javadoc=\ + ${base}/junit_4/junit-4.5-api.zip +libs.junit_4.src=\ + ${base}/junit_4/junit-4.5-src.jar diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_02/manifest.mf b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_02/manifest.mf new file mode 100644 index 0000000..328e8e5 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_02/manifest.mf @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +X-COMMENT: Main-Class will be added automatically by build + diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_02/nbproject/build-impl.xml b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_02/nbproject/build-impl.xml new file mode 100644 index 0000000..11ac689 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_02/nbproject/build-impl.xml @@ -0,0 +1,1066 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set src.dir + Must set test.src.dir + Must set build.dir + Must set dist.dir + Must set build.classes.dir + Must set dist.javadoc.dir + Must set build.test.classes.dir + Must set build.test.results.dir + Must set build.classes.excludes + Must set dist.jar + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set JVM to use for profiling in profiler.info.jvm + Must set profiler agent JVM arguments in profiler.info.jvmargs.agent + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + + + + + + java -cp "${run.classpath.with.dist.jar}" ${main.class} + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + java -jar "${dist.jar.resolved}" + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set run.class + + + + Must select one file in the IDE or set run.class + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set debug.class + + + + + Must select one file in the IDE or set debug.class + + + + + Must set fix.includes + + + + + + + + + + + + + + + + + Must select one file in the IDE or set profile.class + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + Some tests failed; see details above. + + + + + + + + + Must select some files in the IDE or set test.includes + + + + Some tests failed; see details above. + + + + + Must select one file in the IDE or set test.class + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_02/nbproject/genfiles.properties b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_02/nbproject/genfiles.properties new file mode 100644 index 0000000..8944636 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_02/nbproject/genfiles.properties @@ -0,0 +1,8 @@ +build.xml.data.CRC32=7b55b154 +build.xml.script.CRC32=762f47ff +build.xml.stylesheet.CRC32=28e38971@1.43.1.45 +# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. +# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. +nbproject/build-impl.xml.data.CRC32=7b55b154 +nbproject/build-impl.xml.script.CRC32=ea4a671f +nbproject/build-impl.xml.stylesheet.CRC32=0c01fd8e@1.43.1.45 diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_02/nbproject/private/config.properties b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_02/nbproject/private/config.properties new file mode 100644 index 0000000..e69de29 diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_02/nbproject/private/private.properties b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_02/nbproject/private/private.properties new file mode 100644 index 0000000..a5ab360 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_02/nbproject/private/private.properties @@ -0,0 +1,6 @@ +compile.on.save=true +do.depend=false +do.jar=true +javac.debug=true +javadoc.preview=true +user.properties.file=C:\\Users\\Leo\\.netbeans\\7.0\\build.properties diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_02/nbproject/private/private.xml b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_02/nbproject/private/private.xml new file mode 100644 index 0000000..c1f155a --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_02/nbproject/private/private.xml @@ -0,0 +1,4 @@ + + + + diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_02/nbproject/project.properties b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_02/nbproject/project.properties new file mode 100644 index 0000000..71dfef4 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_02/nbproject/project.properties @@ -0,0 +1,74 @@ +annotation.processing.enabled=true +annotation.processing.enabled.in.editor=false +annotation.processing.run.all.processors=true +annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output +application.title=ff_02 +application.vendor=Leo +build.classes.dir=${build.dir}/classes +build.classes.excludes=**/*.java,**/*.form +# This directory is removed when the project is cleaned: +build.dir=build +build.generated.dir=${build.dir}/generated +build.generated.sources.dir=${build.dir}/generated-sources +# Only compile against the classpath explicitly listed here: +build.sysclasspath=ignore +build.test.classes.dir=${build.dir}/test/classes +build.test.results.dir=${build.dir}/test/results +# Uncomment to specify the preferred debugger connection transport: +#debug.transport=dt_socket +debug.classpath=\ + ${run.classpath} +debug.test.classpath=\ + ${run.test.classpath} +# This directory is removed when the project is cleaned: +dist.dir=dist +dist.jar=${dist.dir}/ff_02.jar +dist.javadoc.dir=${dist.dir}/javadoc +endorsed.classpath= +excludes= +includes=** +jar.compress=false +javac.classpath= +# Space-separated list of extra javac options +javac.compilerargs= +javac.deprecation=false +javac.processorpath=\ + ${javac.classpath} +javac.source=1.7 +javac.target=1.7 +javac.test.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir}:\ + ${libs.junit.classpath}:\ + ${libs.junit_4.classpath} +javac.test.processorpath=\ + ${javac.test.classpath} +javadoc.additionalparam= +javadoc.author=false +javadoc.encoding=${source.encoding} +javadoc.noindex=false +javadoc.nonavbar=false +javadoc.notree=false +javadoc.private=false +javadoc.splitindex=true +javadoc.use=true +javadoc.version=false +javadoc.windowtitle= +main.class=ff_02.Main +manifest.file=manifest.mf +meta.inf.dir=${src.dir}/META-INF +mkdist.disabled=false +platform.active=default_platform +run.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +# Space-separated list of JVM arguments used when running the project +# (you may also define separate properties like run-sys-prop.name=value instead of -Dname=value +# or test-sys-prop.name=value to set system properties for unit tests): +run.jvmargs= +run.test.classpath=\ + ${javac.test.classpath}:\ + ${build.test.classes.dir} +source.encoding=UTF-8 +src.dir=src +test.src.dir=test diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_02/nbproject/project.xml b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_02/nbproject/project.xml new file mode 100644 index 0000000..c715d66 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_02/nbproject/project.xml @@ -0,0 +1,18 @@ + + + org.netbeans.modules.java.j2seproject + + + ff_02 + + + + + + + + + .\lib\nblibraries.properties + + + diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_02/src/ff_02/Main.java b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_02/src/ff_02/Main.java new file mode 100644 index 0000000..e07fe55 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_02/src/ff_02/Main.java @@ -0,0 +1,23 @@ +package ff_02; + +import java.nio.file.FileSystems; +import java.nio.file.Files; +import java.nio.file.LinkOption; +import java.nio.file.Path; + +/** + * + * @author Apress + */ +public class Main { + + public static void main(String[] args) { + + Path path = FileSystems.getDefault().getPath("C:/rafaelnadal/tournaments/2009", "AEGON.txt"); + + boolean path_exists = Files.exists(path, new LinkOption[]{LinkOption.NOFOLLOW_LINKS}); + boolean path_notexists = Files.notExists(path, new LinkOption[]{LinkOption.NOFOLLOW_LINKS}); + + System.out.println("Exists? " + path_exists + " Not exists? " + path_notexists); + } +} diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_03/build.xml b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_03/build.xml new file mode 100644 index 0000000..e12c8b9 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_03/build.xml @@ -0,0 +1,74 @@ + + + + + + + + + + + Builds, tests, and runs the project ff_03. + + + diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_03/build/built-jar.properties b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_03/build/built-jar.properties new file mode 100644 index 0000000..7316d75 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_03/build/built-jar.properties @@ -0,0 +1,4 @@ +#Mon, 17 Oct 2011 06:29:05 +0200 + + +C\:\\NIO\\filesandfolders\\ff_03= diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_03/build/classes/ff_03/Main.class b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_03/build/classes/ff_03/Main.class new file mode 100644 index 0000000..6209e3a Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_03/build/classes/ff_03/Main.class differ diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_03/dist/README.TXT b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_03/dist/README.TXT new file mode 100644 index 0000000..8d91e1f --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_03/dist/README.TXT @@ -0,0 +1,33 @@ +======================== +BUILD OUTPUT DESCRIPTION +======================== + +When you build an Java application project that has a main class, the IDE +automatically copies all of the JAR +files on the projects classpath to your projects dist/lib folder. The IDE +also adds each of the JAR files to the Class-Path element in the application +JAR files manifest file (MANIFEST.MF). + +To run the project from the command line, go to the dist folder and +type the following: + +java -jar "ff_03.jar" + +To distribute this project, zip up the dist folder (including the lib folder) +and distribute the ZIP file. + +Notes: + +* If two JAR files on the project classpath have the same name, only the first +JAR file is copied to the lib folder. +* Only JAR files are copied to the lib folder. +If the classpath contains other types of files or folders, none of the +classpath elements are copied to the lib folder. In such a case, +you need to copy the classpath elements to the lib folder manually after the build. +* If a library on the projects classpath also has a Class-Path element +specified in the manifest,the content of the Class-Path element has to be on +the projects runtime path. +* To set a main class in a standard Java project, right-click the project node +in the Projects window and choose Properties. Then click Run and enter the +class name in the Main Class field. Alternatively, you can manually type the +class name in the manifest Main-Class element. diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_03/dist/ff_03.jar b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_03/dist/ff_03.jar new file mode 100644 index 0000000..536f56a Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_03/dist/ff_03.jar differ diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_03/lib/CopyLibs/org-netbeans-modules-java-j2seproject-copylibstask.jar b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_03/lib/CopyLibs/org-netbeans-modules-java-j2seproject-copylibstask.jar new file mode 100644 index 0000000..5ee71d2 Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_03/lib/CopyLibs/org-netbeans-modules-java-j2seproject-copylibstask.jar differ diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_03/lib/junit/junit-3.8.2-api.zip b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_03/lib/junit/junit-3.8.2-api.zip new file mode 100644 index 0000000..6d792fd Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_03/lib/junit/junit-3.8.2-api.zip differ diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_03/lib/junit/junit-3.8.2.jar b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_03/lib/junit/junit-3.8.2.jar new file mode 100644 index 0000000..d835872 Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_03/lib/junit/junit-3.8.2.jar differ diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_03/lib/junit_4/junit-4.5-api.zip b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_03/lib/junit_4/junit-4.5-api.zip new file mode 100644 index 0000000..5748c44 Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_03/lib/junit_4/junit-4.5-api.zip differ diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_03/lib/junit_4/junit-4.5-src.jar b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_03/lib/junit_4/junit-4.5-src.jar new file mode 100644 index 0000000..18774a5 Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_03/lib/junit_4/junit-4.5-src.jar differ diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_03/lib/junit_4/junit-4.5.jar b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_03/lib/junit_4/junit-4.5.jar new file mode 100644 index 0000000..83f8bc7 Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_03/lib/junit_4/junit-4.5.jar differ diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_03/lib/nblibraries.properties b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_03/lib/nblibraries.properties new file mode 100644 index 0000000..9137b06 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_03/lib/nblibraries.properties @@ -0,0 +1,12 @@ +libs.CopyLibs.classpath=\ + ${base}/CopyLibs/org-netbeans-modules-java-j2seproject-copylibstask.jar +libs.junit.classpath=\ + ${base}/junit/junit-3.8.2.jar +libs.junit.javadoc=\ + ${base}/junit/junit-3.8.2-api.zip +libs.junit_4.classpath=\ + ${base}/junit_4/junit-4.5.jar +libs.junit_4.javadoc=\ + ${base}/junit_4/junit-4.5-api.zip +libs.junit_4.src=\ + ${base}/junit_4/junit-4.5-src.jar diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_03/manifest.mf b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_03/manifest.mf new file mode 100644 index 0000000..328e8e5 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_03/manifest.mf @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +X-COMMENT: Main-Class will be added automatically by build + diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_03/nbproject/build-impl.xml b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_03/nbproject/build-impl.xml new file mode 100644 index 0000000..394f27e --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_03/nbproject/build-impl.xml @@ -0,0 +1,1066 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set src.dir + Must set test.src.dir + Must set build.dir + Must set dist.dir + Must set build.classes.dir + Must set dist.javadoc.dir + Must set build.test.classes.dir + Must set build.test.results.dir + Must set build.classes.excludes + Must set dist.jar + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set JVM to use for profiling in profiler.info.jvm + Must set profiler agent JVM arguments in profiler.info.jvmargs.agent + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + + + + + + java -cp "${run.classpath.with.dist.jar}" ${main.class} + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + java -jar "${dist.jar.resolved}" + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set run.class + + + + Must select one file in the IDE or set run.class + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set debug.class + + + + + Must select one file in the IDE or set debug.class + + + + + Must set fix.includes + + + + + + + + + + + + + + + + + Must select one file in the IDE or set profile.class + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + Some tests failed; see details above. + + + + + + + + + Must select some files in the IDE or set test.includes + + + + Some tests failed; see details above. + + + + + Must select one file in the IDE or set test.class + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_03/nbproject/genfiles.properties b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_03/nbproject/genfiles.properties new file mode 100644 index 0000000..2a77e38 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_03/nbproject/genfiles.properties @@ -0,0 +1,8 @@ +build.xml.data.CRC32=54a62a76 +build.xml.script.CRC32=8ac3b77b +build.xml.stylesheet.CRC32=28e38971@1.43.1.45 +# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. +# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. +nbproject/build-impl.xml.data.CRC32=54a62a76 +nbproject/build-impl.xml.script.CRC32=307769d6 +nbproject/build-impl.xml.stylesheet.CRC32=0c01fd8e@1.43.1.45 diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_03/nbproject/private/config.properties b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_03/nbproject/private/config.properties new file mode 100644 index 0000000..e69de29 diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_03/nbproject/private/private.properties b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_03/nbproject/private/private.properties new file mode 100644 index 0000000..a5ab360 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_03/nbproject/private/private.properties @@ -0,0 +1,6 @@ +compile.on.save=true +do.depend=false +do.jar=true +javac.debug=true +javadoc.preview=true +user.properties.file=C:\\Users\\Leo\\.netbeans\\7.0\\build.properties diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_03/nbproject/private/private.xml b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_03/nbproject/private/private.xml new file mode 100644 index 0000000..c1f155a --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_03/nbproject/private/private.xml @@ -0,0 +1,4 @@ + + + + diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_03/nbproject/project.properties b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_03/nbproject/project.properties new file mode 100644 index 0000000..55aed38 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_03/nbproject/project.properties @@ -0,0 +1,74 @@ +annotation.processing.enabled=true +annotation.processing.enabled.in.editor=false +annotation.processing.run.all.processors=true +annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output +application.title=ff_03 +application.vendor=Leo +build.classes.dir=${build.dir}/classes +build.classes.excludes=**/*.java,**/*.form +# This directory is removed when the project is cleaned: +build.dir=build +build.generated.dir=${build.dir}/generated +build.generated.sources.dir=${build.dir}/generated-sources +# Only compile against the classpath explicitly listed here: +build.sysclasspath=ignore +build.test.classes.dir=${build.dir}/test/classes +build.test.results.dir=${build.dir}/test/results +# Uncomment to specify the preferred debugger connection transport: +#debug.transport=dt_socket +debug.classpath=\ + ${run.classpath} +debug.test.classpath=\ + ${run.test.classpath} +# This directory is removed when the project is cleaned: +dist.dir=dist +dist.jar=${dist.dir}/ff_03.jar +dist.javadoc.dir=${dist.dir}/javadoc +endorsed.classpath= +excludes= +includes=** +jar.compress=false +javac.classpath= +# Space-separated list of extra javac options +javac.compilerargs= +javac.deprecation=false +javac.processorpath=\ + ${javac.classpath} +javac.source=1.7 +javac.target=1.7 +javac.test.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir}:\ + ${libs.junit.classpath}:\ + ${libs.junit_4.classpath} +javac.test.processorpath=\ + ${javac.test.classpath} +javadoc.additionalparam= +javadoc.author=false +javadoc.encoding=${source.encoding} +javadoc.noindex=false +javadoc.nonavbar=false +javadoc.notree=false +javadoc.private=false +javadoc.splitindex=true +javadoc.use=true +javadoc.version=false +javadoc.windowtitle= +main.class=ff_03.Main +manifest.file=manifest.mf +meta.inf.dir=${src.dir}/META-INF +mkdist.disabled=false +platform.active=default_platform +run.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +# Space-separated list of JVM arguments used when running the project +# (you may also define separate properties like run-sys-prop.name=value instead of -Dname=value +# or test-sys-prop.name=value to set system properties for unit tests): +run.jvmargs= +run.test.classpath=\ + ${javac.test.classpath}:\ + ${build.test.classes.dir} +source.encoding=UTF-8 +src.dir=src +test.src.dir=test diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_03/nbproject/project.xml b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_03/nbproject/project.xml new file mode 100644 index 0000000..3ea542e --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_03/nbproject/project.xml @@ -0,0 +1,18 @@ + + + org.netbeans.modules.java.j2seproject + + + ff_03 + + + + + + + + + .\lib\nblibraries.properties + + + diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_03/src/ff_03/Main.java b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_03/src/ff_03/Main.java new file mode 100644 index 0000000..24a4f81 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_03/src/ff_03/Main.java @@ -0,0 +1,38 @@ +package ff_03; + +import java.nio.file.FileSystems; +import java.nio.file.Files; +import java.nio.file.LinkOption; +import java.nio.file.Path; + +/** + * + * @author Apress + */ +public class Main { + + public static void main(String[] args) { + + Path path = FileSystems.getDefault().getPath("C:/rafaelnadal/tournaments/2009", "AEGON.txt"); + + //method 1 + boolean is_readable = Files.isReadable(path); + boolean is_writable = Files.isWritable(path); + boolean is_executable = Files.isExecutable(path); + boolean is_regular = Files.isRegularFile(path, LinkOption.NOFOLLOW_LINKS); + + if ((is_readable) && (is_writable) && (is_executable) && (is_regular)) { + System.out.println("The checked file is accessible!"); + } else { + System.out.println("The checked file is not accessible!"); + } + + //method 2 + boolean is_accessible = Files.isRegularFile(path) & Files.isReadable(path) & Files.isExecutable(path) & Files.isWritable(path); + if (is_accessible) { + System.out.println("The checked file is accessible!"); + } else { + System.out.println("The checked file is not accessible!"); + } + } +} diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_04/build.xml b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_04/build.xml new file mode 100644 index 0000000..e0c4836 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_04/build.xml @@ -0,0 +1,74 @@ + + + + + + + + + + + Builds, tests, and runs the project ff_04. + + + diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_04/build/built-jar.properties b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_04/build/built-jar.properties new file mode 100644 index 0000000..a66b7c7 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_04/build/built-jar.properties @@ -0,0 +1,4 @@ +#Mon, 17 Oct 2011 06:30:08 +0200 + + +C\:\\NIO\\filesandfolders\\ff_04= diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_04/build/classes/ff_04/Main.class b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_04/build/classes/ff_04/Main.class new file mode 100644 index 0000000..737511e Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_04/build/classes/ff_04/Main.class differ diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_04/dist/README.TXT b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_04/dist/README.TXT new file mode 100644 index 0000000..59fd00d --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_04/dist/README.TXT @@ -0,0 +1,32 @@ +======================== +BUILD OUTPUT DESCRIPTION +======================== + +When you build an Java application project that has a main class, the IDE +automatically copies all of the JAR +files on the projects classpath to your projects dist/lib folder. The IDE +also adds each of the JAR files to the Class-Path element in the application +JAR files manifest file (MANIFEST.MF). + +To run the project from the command line, go to the dist folder and +type the following: + +java -jar "ff_04.jar" + +To distribute this project, zip up the dist folder (including the lib folder) +and distribute the ZIP file. + +Notes: + +* If two JAR files on the project classpath have the same name, only the first +JAR file is copied to the lib folder. +* Only JAR files are copied to the lib folder. +If the classpath contains other types of files or folders, these files (folders) +are not copied. +* If a library on the projects classpath also has a Class-Path element +specified in the manifest,the content of the Class-Path element has to be on +the projects runtime path. +* To set a main class in a standard Java project, right-click the project node +in the Projects window and choose Properties. Then click Run and enter the +class name in the Main Class field. Alternatively, you can manually type the +class name in the manifest Main-Class element. diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_04/dist/ff_04.jar b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_04/dist/ff_04.jar new file mode 100644 index 0000000..837b852 Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_04/dist/ff_04.jar differ diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_04/manifest.mf b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_04/manifest.mf new file mode 100644 index 0000000..328e8e5 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_04/manifest.mf @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +X-COMMENT: Main-Class will be added automatically by build + diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_04/nbproject/build-impl.xml b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_04/nbproject/build-impl.xml new file mode 100644 index 0000000..ba8c88c --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_04/nbproject/build-impl.xml @@ -0,0 +1,1041 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set src.dir + Must set test.src.dir + Must set build.dir + Must set dist.dir + Must set build.classes.dir + Must set dist.javadoc.dir + Must set build.test.classes.dir + Must set build.test.results.dir + Must set build.classes.excludes + Must set dist.jar + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set JVM to use for profiling in profiler.info.jvm + Must set profiler agent JVM arguments in profiler.info.jvmargs.agent + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + + + + + + java -cp "${run.classpath.with.dist.jar}" ${main.class} + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + java -jar "${dist.jar.resolved}" + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set run.class + + + + Must select one file in the IDE or set run.class + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set debug.class + + + + + Must select one file in the IDE or set debug.class + + + + + Must set fix.includes + + + + + + + + + + + + + + + + + Must select one file in the IDE or set profile.class + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + Some tests failed; see details above. + + + + + + + + + Must select some files in the IDE or set test.includes + + + + Some tests failed; see details above. + + + + + Must select one file in the IDE or set test.class + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_04/nbproject/genfiles.properties b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_04/nbproject/genfiles.properties new file mode 100644 index 0000000..be53953 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_04/nbproject/genfiles.properties @@ -0,0 +1,8 @@ +build.xml.data.CRC32=0199b6e7 +build.xml.script.CRC32=11d66e24 +build.xml.stylesheet.CRC32=28e38971@1.43.1.45 +# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. +# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. +nbproject/build-impl.xml.data.CRC32=0199b6e7 +nbproject/build-impl.xml.script.CRC32=748902f4 +nbproject/build-impl.xml.stylesheet.CRC32=0c01fd8e@1.43.1.45 diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_04/nbproject/private/config.properties b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_04/nbproject/private/config.properties new file mode 100644 index 0000000..e69de29 diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_04/nbproject/private/private.properties b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_04/nbproject/private/private.properties new file mode 100644 index 0000000..a5ab360 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_04/nbproject/private/private.properties @@ -0,0 +1,6 @@ +compile.on.save=true +do.depend=false +do.jar=true +javac.debug=true +javadoc.preview=true +user.properties.file=C:\\Users\\Leo\\.netbeans\\7.0\\build.properties diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_04/nbproject/private/private.xml b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_04/nbproject/private/private.xml new file mode 100644 index 0000000..c1f155a --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_04/nbproject/private/private.xml @@ -0,0 +1,4 @@ + + + + diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_04/nbproject/project.properties b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_04/nbproject/project.properties new file mode 100644 index 0000000..4255894 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_04/nbproject/project.properties @@ -0,0 +1,72 @@ +annotation.processing.enabled=true +annotation.processing.enabled.in.editor=false +annotation.processing.run.all.processors=true +annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output +application.title=ff_04 +application.vendor=Leo +build.classes.dir=${build.dir}/classes +build.classes.excludes=**/*.java,**/*.form +# This directory is removed when the project is cleaned: +build.dir=build +build.generated.dir=${build.dir}/generated +build.generated.sources.dir=${build.dir}/generated-sources +# Only compile against the classpath explicitly listed here: +build.sysclasspath=ignore +build.test.classes.dir=${build.dir}/test/classes +build.test.results.dir=${build.dir}/test/results +# Uncomment to specify the preferred debugger connection transport: +#debug.transport=dt_socket +debug.classpath=\ + ${run.classpath} +debug.test.classpath=\ + ${run.test.classpath} +# This directory is removed when the project is cleaned: +dist.dir=dist +dist.jar=${dist.dir}/ff_04.jar +dist.javadoc.dir=${dist.dir}/javadoc +endorsed.classpath= +excludes= +includes=** +jar.compress=false +javac.classpath= +# Space-separated list of extra javac options +javac.compilerargs= +javac.deprecation=false +javac.processorpath=\ + ${javac.classpath} +javac.source=1.7 +javac.target=1.7 +javac.test.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +javac.test.processorpath=\ + ${javac.test.classpath} +javadoc.additionalparam= +javadoc.author=false +javadoc.encoding=${source.encoding} +javadoc.noindex=false +javadoc.nonavbar=false +javadoc.notree=false +javadoc.private=false +javadoc.splitindex=true +javadoc.use=true +javadoc.version=false +javadoc.windowtitle= +main.class=ff_04.Main +manifest.file=manifest.mf +meta.inf.dir=${src.dir}/META-INF +mkdist.disabled=false +platform.active=default_platform +run.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +# Space-separated list of JVM arguments used when running the project +# (you may also define separate properties like run-sys-prop.name=value instead of -Dname=value +# or test-sys-prop.name=value to set system properties for unit tests): +run.jvmargs= +run.test.classpath=\ + ${javac.test.classpath}:\ + ${build.test.classes.dir} +source.encoding=UTF-8 +src.dir=src +test.src.dir=test diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_04/nbproject/project.xml b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_04/nbproject/project.xml new file mode 100644 index 0000000..9f8de95 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_04/nbproject/project.xml @@ -0,0 +1,15 @@ + + + org.netbeans.modules.java.j2seproject + + + ff_04 + + + + + + + + + diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_04/src/ff_04/Main.java b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_04/src/ff_04/Main.java new file mode 100644 index 0000000..ab57ad5 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_04/src/ff_04/Main.java @@ -0,0 +1,26 @@ +package ff_04; + +import java.io.IOException; +import java.nio.file.FileSystems; +import java.nio.file.Files; +import java.nio.file.Path; + +/** + * + * @author Apress + */ +public class Main { + + public static void main(String[] args) { + + Path path = FileSystems.getDefault().getPath("C:/rafaelnadal/tournaments/2009", "MutuaMadridOpen.txt"); + + //is hidden ? + try { + boolean is_hidden = Files.isHidden(path); + System.out.println("Is hidden ? " + is_hidden); + } catch (IOException e) { + System.err.println(e); + } + } +} diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_05/build.xml b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_05/build.xml new file mode 100644 index 0000000..13dbc80 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_05/build.xml @@ -0,0 +1,74 @@ + + + + + + + + + + + Builds, tests, and runs the project ff_05. + + + diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_05/build/built-jar.properties b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_05/build/built-jar.properties new file mode 100644 index 0000000..d10cc81 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_05/build/built-jar.properties @@ -0,0 +1,4 @@ +#Mon, 17 Oct 2011 06:36:51 +0200 + + +C\:\\NIO\\filesandfolders\\ff_05= diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_05/build/classes/ff_05/Main.class b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_05/build/classes/ff_05/Main.class new file mode 100644 index 0000000..f7c30ce Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_05/build/classes/ff_05/Main.class differ diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_05/dist/README.TXT b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_05/dist/README.TXT new file mode 100644 index 0000000..618547f --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_05/dist/README.TXT @@ -0,0 +1,33 @@ +======================== +BUILD OUTPUT DESCRIPTION +======================== + +When you build an Java application project that has a main class, the IDE +automatically copies all of the JAR +files on the projects classpath to your projects dist/lib folder. The IDE +also adds each of the JAR files to the Class-Path element in the application +JAR files manifest file (MANIFEST.MF). + +To run the project from the command line, go to the dist folder and +type the following: + +java -jar "ff_05.jar" + +To distribute this project, zip up the dist folder (including the lib folder) +and distribute the ZIP file. + +Notes: + +* If two JAR files on the project classpath have the same name, only the first +JAR file is copied to the lib folder. +* Only JAR files are copied to the lib folder. +If the classpath contains other types of files or folders, none of the +classpath elements are copied to the lib folder. In such a case, +you need to copy the classpath elements to the lib folder manually after the build. +* If a library on the projects classpath also has a Class-Path element +specified in the manifest,the content of the Class-Path element has to be on +the projects runtime path. +* To set a main class in a standard Java project, right-click the project node +in the Projects window and choose Properties. Then click Run and enter the +class name in the Main Class field. Alternatively, you can manually type the +class name in the manifest Main-Class element. diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_05/dist/ff_05.jar b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_05/dist/ff_05.jar new file mode 100644 index 0000000..365fda2 Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_05/dist/ff_05.jar differ diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_05/lib/CopyLibs/org-netbeans-modules-java-j2seproject-copylibstask.jar b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_05/lib/CopyLibs/org-netbeans-modules-java-j2seproject-copylibstask.jar new file mode 100644 index 0000000..5ee71d2 Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_05/lib/CopyLibs/org-netbeans-modules-java-j2seproject-copylibstask.jar differ diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_05/lib/junit/junit-3.8.2-api.zip b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_05/lib/junit/junit-3.8.2-api.zip new file mode 100644 index 0000000..6d792fd Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_05/lib/junit/junit-3.8.2-api.zip differ diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_05/lib/junit/junit-3.8.2.jar b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_05/lib/junit/junit-3.8.2.jar new file mode 100644 index 0000000..d835872 Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_05/lib/junit/junit-3.8.2.jar differ diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_05/lib/junit_4/junit-4.5-api.zip b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_05/lib/junit_4/junit-4.5-api.zip new file mode 100644 index 0000000..5748c44 Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_05/lib/junit_4/junit-4.5-api.zip differ diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_05/lib/junit_4/junit-4.5-src.jar b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_05/lib/junit_4/junit-4.5-src.jar new file mode 100644 index 0000000..18774a5 Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_05/lib/junit_4/junit-4.5-src.jar differ diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_05/lib/junit_4/junit-4.5.jar b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_05/lib/junit_4/junit-4.5.jar new file mode 100644 index 0000000..83f8bc7 Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_05/lib/junit_4/junit-4.5.jar differ diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_05/lib/nblibraries.properties b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_05/lib/nblibraries.properties new file mode 100644 index 0000000..9137b06 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_05/lib/nblibraries.properties @@ -0,0 +1,12 @@ +libs.CopyLibs.classpath=\ + ${base}/CopyLibs/org-netbeans-modules-java-j2seproject-copylibstask.jar +libs.junit.classpath=\ + ${base}/junit/junit-3.8.2.jar +libs.junit.javadoc=\ + ${base}/junit/junit-3.8.2-api.zip +libs.junit_4.classpath=\ + ${base}/junit_4/junit-4.5.jar +libs.junit_4.javadoc=\ + ${base}/junit_4/junit-4.5-api.zip +libs.junit_4.src=\ + ${base}/junit_4/junit-4.5-src.jar diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_05/manifest.mf b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_05/manifest.mf new file mode 100644 index 0000000..328e8e5 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_05/manifest.mf @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +X-COMMENT: Main-Class will be added automatically by build + diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_05/nbproject/build-impl.xml b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_05/nbproject/build-impl.xml new file mode 100644 index 0000000..63b4751 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_05/nbproject/build-impl.xml @@ -0,0 +1,1066 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set src.dir + Must set test.src.dir + Must set build.dir + Must set dist.dir + Must set build.classes.dir + Must set dist.javadoc.dir + Must set build.test.classes.dir + Must set build.test.results.dir + Must set build.classes.excludes + Must set dist.jar + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set JVM to use for profiling in profiler.info.jvm + Must set profiler agent JVM arguments in profiler.info.jvmargs.agent + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + + + + + + java -cp "${run.classpath.with.dist.jar}" ${main.class} + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + java -jar "${dist.jar.resolved}" + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set run.class + + + + Must select one file in the IDE or set run.class + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set debug.class + + + + + Must select one file in the IDE or set debug.class + + + + + Must set fix.includes + + + + + + + + + + + + + + + + + Must select one file in the IDE or set profile.class + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + Some tests failed; see details above. + + + + + + + + + Must select some files in the IDE or set test.includes + + + + Some tests failed; see details above. + + + + + Must select one file in the IDE or set test.class + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_05/nbproject/genfiles.properties b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_05/nbproject/genfiles.properties new file mode 100644 index 0000000..9ae59e5 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_05/nbproject/genfiles.properties @@ -0,0 +1,8 @@ +build.xml.data.CRC32=b48f70ba +build.xml.script.CRC32=ed3a9ea0 +build.xml.stylesheet.CRC32=28e38971@1.43.1.45 +# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. +# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. +nbproject/build-impl.xml.data.CRC32=b48f70ba +nbproject/build-impl.xml.script.CRC32=816a45a3 +nbproject/build-impl.xml.stylesheet.CRC32=0c01fd8e@1.43.1.45 diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_05/nbproject/private/config.properties b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_05/nbproject/private/config.properties new file mode 100644 index 0000000..e69de29 diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_05/nbproject/private/private.properties b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_05/nbproject/private/private.properties new file mode 100644 index 0000000..a5ab360 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_05/nbproject/private/private.properties @@ -0,0 +1,6 @@ +compile.on.save=true +do.depend=false +do.jar=true +javac.debug=true +javadoc.preview=true +user.properties.file=C:\\Users\\Leo\\.netbeans\\7.0\\build.properties diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_05/nbproject/private/private.xml b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_05/nbproject/private/private.xml new file mode 100644 index 0000000..c1f155a --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_05/nbproject/private/private.xml @@ -0,0 +1,4 @@ + + + + diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_05/nbproject/project.properties b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_05/nbproject/project.properties new file mode 100644 index 0000000..2c80840 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_05/nbproject/project.properties @@ -0,0 +1,70 @@ +annotation.processing.enabled=true +annotation.processing.enabled.in.editor=false +annotation.processing.run.all.processors=true +annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output +application.title=ff_05 +application.vendor=Leo +build.classes.dir=${build.dir}/classes +build.classes.excludes=**/*.java,**/*.form +# This directory is removed when the project is cleaned: +build.dir=build +build.generated.dir=${build.dir}/generated +build.generated.sources.dir=${build.dir}/generated-sources +# Only compile against the classpath explicitly listed here: +build.sysclasspath=ignore +build.test.classes.dir=${build.dir}/test/classes +build.test.results.dir=${build.dir}/test/results +# Uncomment to specify the preferred debugger connection transport: +#debug.transport=dt_socket +debug.classpath=\ + ${run.classpath} +debug.test.classpath=\ + ${run.test.classpath} +# This directory is removed when the project is cleaned: +dist.dir=dist +dist.jar=${dist.dir}/ff_05.jar +dist.javadoc.dir=${dist.dir}/javadoc +endorsed.classpath= +excludes= +includes=** +jar.compress=false +javac.classpath= +# Space-separated list of extra javac options +javac.compilerargs= +javac.deprecation=false +javac.processorpath=\ + ${javac.classpath} +javac.source=1.7 +javac.target=1.7 +javac.test.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir}:\ + ${libs.junit.classpath}:\ + ${libs.junit_4.classpath} +javac.test.processorpath=\ + ${javac.test.classpath} +javadoc.additionalparam= +javadoc.author=false +javadoc.encoding=${source.encoding} +javadoc.noindex=false +javadoc.nonavbar=false +javadoc.notree=false +javadoc.private=false +javadoc.splitindex=true +javadoc.use=true +javadoc.version=false +javadoc.windowtitle= +main.class=ff_05.Main +manifest.file=manifest.mf +meta.inf.dir=${src.dir}/META-INF +mkdist.disabled=false +platform.active=default_platform +run.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +run.test.classpath=\ + ${javac.test.classpath}:\ + ${build.test.classes.dir} +source.encoding=UTF-8 +src.dir=src +test.src.dir=test diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_05/nbproject/project.xml b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_05/nbproject/project.xml new file mode 100644 index 0000000..19da697 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_05/nbproject/project.xml @@ -0,0 +1,18 @@ + + + org.netbeans.modules.java.j2seproject + + + ff_05 + + + + + + + + + .\lib\nblibraries.properties + + + diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_05/src/ff_05/Main.java b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_05/src/ff_05/Main.java new file mode 100644 index 0000000..a1a19bf --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_05/src/ff_05/Main.java @@ -0,0 +1,67 @@ +package ff_05; + +import java.io.FileOutputStream; +import java.io.OutputStream; +import java.net.URI; +import java.io.FileInputStream; +import java.io.InputStream; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import static java.nio.file.StandardCopyOption.REPLACE_EXISTING; +import static java.nio.file.StandardCopyOption.COPY_ATTRIBUTES; +import static java.nio.file.LinkOption.NOFOLLOW_LINKS; + +/** + * + * @author Apress + */ +public class Main { + + public static void main(String[] args) { + + //Path to Path copy + //define the Path to copy from + Path copy_from_1 = Paths.get("C:/rafaelnadal/grandslam/AustralianOpen", "draw_template.txt"); + //define the Path to copy to + Path copy_to_1 = Paths.get("C:/rafaelnadal/grandslam/USOpen", copy_from_1.getFileName().toString()); + try { + Files.copy(copy_from_1, copy_to_1, REPLACE_EXISTING, COPY_ATTRIBUTES, NOFOLLOW_LINKS); + } catch (IOException e) { + System.err.println(e); + } + + //InputStream to Path copy + Path copy_from_2 = Paths.get("C:/rafaelnadal/grandslam/AustralianOpen", "draw_template.txt"); + Path copy_to_2 = Paths.get("C:/rafaelnadal/grandslam/Wimbledon", "draw_template.txt"); + + try (InputStream is = new FileInputStream(copy_from_2.toFile())) { + + Files.copy(is, copy_to_2, REPLACE_EXISTING); + + } catch (IOException e) { + System.err.println(e); + } + + Path copy_to_3 = Paths.get("C:/rafaelnadal/photos/rafa_winner_2.jpg"); + URI u = URI.create("https://lh6.googleusercontent.com/--udGIidomAM/Tl8KTbYd34I/AAAAAAAAAZw/j2nH24PaZyM/s800/rafa_winner.jpg"); + try (InputStream in = u.toURL().openStream()) { + Files.copy(in, copy_to_3); + } catch (IOException e) { + System.err.println(e); + } + + //Path to OutputStream copy + Path copy_from_4 = Paths.get("C:/rafaelnadal/grandslam/AustralianOpen", "draw_template.txt"); + Path copy_to_4 = Paths.get("C:/rafaelnadal/grandslam/RolandGarros", "draw_template.txt"); + try (OutputStream os = new FileOutputStream(copy_to_4.toFile())) { + + Files.copy(copy_from_4, os); + + } catch (IOException e) { + System.err.println(e); + } + + } +} diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_06/build.xml b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_06/build.xml new file mode 100644 index 0000000..ac24311 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_06/build.xml @@ -0,0 +1,74 @@ + + + + + + + + + + + Builds, tests, and runs the project ff_06. + + + diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_06/build/built-jar.properties b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_06/build/built-jar.properties new file mode 100644 index 0000000..da5b22d --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_06/build/built-jar.properties @@ -0,0 +1,4 @@ +#Mon, 17 Oct 2011 06:54:56 +0200 + + +C\:\\NIO\\filesandfolders\\ff_06= diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_06/build/classes/ff_06/Main.class b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_06/build/classes/ff_06/Main.class new file mode 100644 index 0000000..135f155 Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_06/build/classes/ff_06/Main.class differ diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_06/dist/README.TXT b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_06/dist/README.TXT new file mode 100644 index 0000000..b626f6f --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_06/dist/README.TXT @@ -0,0 +1,32 @@ +======================== +BUILD OUTPUT DESCRIPTION +======================== + +When you build an Java application project that has a main class, the IDE +automatically copies all of the JAR +files on the projects classpath to your projects dist/lib folder. The IDE +also adds each of the JAR files to the Class-Path element in the application +JAR files manifest file (MANIFEST.MF). + +To run the project from the command line, go to the dist folder and +type the following: + +java -jar "ff_06.jar" + +To distribute this project, zip up the dist folder (including the lib folder) +and distribute the ZIP file. + +Notes: + +* If two JAR files on the project classpath have the same name, only the first +JAR file is copied to the lib folder. +* Only JAR files are copied to the lib folder. +If the classpath contains other types of files or folders, these files (folders) +are not copied. +* If a library on the projects classpath also has a Class-Path element +specified in the manifest,the content of the Class-Path element has to be on +the projects runtime path. +* To set a main class in a standard Java project, right-click the project node +in the Projects window and choose Properties. Then click Run and enter the +class name in the Main Class field. Alternatively, you can manually type the +class name in the manifest Main-Class element. diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_06/dist/ff_06.jar b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_06/dist/ff_06.jar new file mode 100644 index 0000000..72216cb Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_06/dist/ff_06.jar differ diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_06/manifest.mf b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_06/manifest.mf new file mode 100644 index 0000000..328e8e5 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_06/manifest.mf @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +X-COMMENT: Main-Class will be added automatically by build + diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_06/nbproject/build-impl.xml b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_06/nbproject/build-impl.xml new file mode 100644 index 0000000..6f227ef --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_06/nbproject/build-impl.xml @@ -0,0 +1,1041 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set src.dir + Must set test.src.dir + Must set build.dir + Must set dist.dir + Must set build.classes.dir + Must set dist.javadoc.dir + Must set build.test.classes.dir + Must set build.test.results.dir + Must set build.classes.excludes + Must set dist.jar + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set JVM to use for profiling in profiler.info.jvm + Must set profiler agent JVM arguments in profiler.info.jvmargs.agent + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + + + + + + java -cp "${run.classpath.with.dist.jar}" ${main.class} + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + java -jar "${dist.jar.resolved}" + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set run.class + + + + Must select one file in the IDE or set run.class + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set debug.class + + + + + Must select one file in the IDE or set debug.class + + + + + Must set fix.includes + + + + + + + + + + + + + + + + + Must select one file in the IDE or set profile.class + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + Some tests failed; see details above. + + + + + + + + + Must select some files in the IDE or set test.includes + + + + Some tests failed; see details above. + + + + + Must select one file in the IDE or set test.class + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_06/nbproject/genfiles.properties b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_06/nbproject/genfiles.properties new file mode 100644 index 0000000..4af5144 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_06/nbproject/genfiles.properties @@ -0,0 +1,8 @@ +build.xml.data.CRC32=11beaeab +build.xml.script.CRC32=337e896d +build.xml.stylesheet.CRC32=28e38971@1.43.1.45 +# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. +# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. +nbproject/build-impl.xml.data.CRC32=11beaeab +nbproject/build-impl.xml.script.CRC32=c0ebec43 +nbproject/build-impl.xml.stylesheet.CRC32=0c01fd8e@1.43.1.45 diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_06/nbproject/private/config.properties b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_06/nbproject/private/config.properties new file mode 100644 index 0000000..e69de29 diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_06/nbproject/private/private.properties b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_06/nbproject/private/private.properties new file mode 100644 index 0000000..a5ab360 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_06/nbproject/private/private.properties @@ -0,0 +1,6 @@ +compile.on.save=true +do.depend=false +do.jar=true +javac.debug=true +javadoc.preview=true +user.properties.file=C:\\Users\\Leo\\.netbeans\\7.0\\build.properties diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_06/nbproject/private/private.xml b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_06/nbproject/private/private.xml new file mode 100644 index 0000000..c1f155a --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_06/nbproject/private/private.xml @@ -0,0 +1,4 @@ + + + + diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_06/nbproject/project.properties b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_06/nbproject/project.properties new file mode 100644 index 0000000..e857ca1 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_06/nbproject/project.properties @@ -0,0 +1,72 @@ +annotation.processing.enabled=true +annotation.processing.enabled.in.editor=false +annotation.processing.run.all.processors=true +annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output +application.title=ff_06 +application.vendor=Leo +build.classes.dir=${build.dir}/classes +build.classes.excludes=**/*.java,**/*.form +# This directory is removed when the project is cleaned: +build.dir=build +build.generated.dir=${build.dir}/generated +build.generated.sources.dir=${build.dir}/generated-sources +# Only compile against the classpath explicitly listed here: +build.sysclasspath=ignore +build.test.classes.dir=${build.dir}/test/classes +build.test.results.dir=${build.dir}/test/results +# Uncomment to specify the preferred debugger connection transport: +#debug.transport=dt_socket +debug.classpath=\ + ${run.classpath} +debug.test.classpath=\ + ${run.test.classpath} +# This directory is removed when the project is cleaned: +dist.dir=dist +dist.jar=${dist.dir}/ff_06.jar +dist.javadoc.dir=${dist.dir}/javadoc +endorsed.classpath= +excludes= +includes=** +jar.compress=false +javac.classpath= +# Space-separated list of extra javac options +javac.compilerargs= +javac.deprecation=false +javac.processorpath=\ + ${javac.classpath} +javac.source=1.7 +javac.target=1.7 +javac.test.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +javac.test.processorpath=\ + ${javac.test.classpath} +javadoc.additionalparam= +javadoc.author=false +javadoc.encoding=${source.encoding} +javadoc.noindex=false +javadoc.nonavbar=false +javadoc.notree=false +javadoc.private=false +javadoc.splitindex=true +javadoc.use=true +javadoc.version=false +javadoc.windowtitle= +main.class=ff_06.Main +manifest.file=manifest.mf +meta.inf.dir=${src.dir}/META-INF +mkdist.disabled=false +platform.active=default_platform +run.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +# Space-separated list of JVM arguments used when running the project +# (you may also define separate properties like run-sys-prop.name=value instead of -Dname=value +# or test-sys-prop.name=value to set system properties for unit tests): +run.jvmargs= +run.test.classpath=\ + ${javac.test.classpath}:\ + ${build.test.classes.dir} +source.encoding=UTF-8 +src.dir=src +test.src.dir=test diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_06/nbproject/project.xml b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_06/nbproject/project.xml new file mode 100644 index 0000000..39efd2b --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_06/nbproject/project.xml @@ -0,0 +1,15 @@ + + + org.netbeans.modules.java.j2seproject + + + ff_06 + + + + + + + + + diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_06/src/ff_06/Main.java b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_06/src/ff_06/Main.java new file mode 100644 index 0000000..9ef42f2 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_06/src/ff_06/Main.java @@ -0,0 +1,59 @@ +package ff_06; + +import java.awt.image.BufferedImage; +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.nio.charset.Charset; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.List; +import javax.imageio.ImageIO; + +/** + * + * @author Apress + */ +public class Main { + + public static void main(String[] args) { + + Path wiki_path = Paths.get("C:/rafaelnadal/wiki", "wiki.txt"); + Path ball_path = Paths.get("C:/rafaelnadal/photos", "ball.png"); + + //readAllBytes + try { + byte[] wikiArray = Files.readAllBytes(wiki_path); + //CHECK THE BYTE ARRAY CONTENT// + String wikiString = new String(wikiArray, "ISO-8859-1"); + System.out.println(wikiString); + //////////////////////////////// + } catch (IOException e) { + System.out.println(e); + } + + try { + byte[] ballArray = Files.readAllBytes(ball_path); + //CHECK THE BYTE ARRAY CONTENT// + Files.write(ball_path.resolveSibling("bytes_to_ball.png"), ballArray); + //BufferedImage bufferedImage = ImageIO.read(new ByteArrayInputStream(ballArray)); + //ImageIO.write(bufferedImage, "png", (ball_path.resolveSibling("bytes_to_ball.png")).toFile()); + //////////////////////////////// + } catch (IOException e) { + System.out.println(e); + } + + //readAllLines + Charset charset = Charset.forName("ISO-8859-1"); + try { + List lines = Files.readAllLines(wiki_path, charset); + //CHECK THE LIST CONTENT// + for (String line : lines) { + System.out.println(line); + } + ////////////////////////// + } catch (IOException e) { + System.out.println(e); + } + } +} diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_07/build.xml b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_07/build.xml new file mode 100644 index 0000000..d2f3c93 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_07/build.xml @@ -0,0 +1,74 @@ + + + + + + + + + + + Builds, tests, and runs the project ff_07. + + + diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_07/build/built-jar.properties b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_07/build/built-jar.properties new file mode 100644 index 0000000..71547ea --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_07/build/built-jar.properties @@ -0,0 +1,4 @@ +#Mon, 17 Oct 2011 06:39:45 +0200 + + +C\:\\NIO\\filesandfolders\\ff_07= diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_07/build/classes/ff_07/Main.class b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_07/build/classes/ff_07/Main.class new file mode 100644 index 0000000..9fad707 Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_07/build/classes/ff_07/Main.class differ diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_07/dist/README.TXT b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_07/dist/README.TXT new file mode 100644 index 0000000..42e7f44 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_07/dist/README.TXT @@ -0,0 +1,32 @@ +======================== +BUILD OUTPUT DESCRIPTION +======================== + +When you build an Java application project that has a main class, the IDE +automatically copies all of the JAR +files on the projects classpath to your projects dist/lib folder. The IDE +also adds each of the JAR files to the Class-Path element in the application +JAR files manifest file (MANIFEST.MF). + +To run the project from the command line, go to the dist folder and +type the following: + +java -jar "ff_07.jar" + +To distribute this project, zip up the dist folder (including the lib folder) +and distribute the ZIP file. + +Notes: + +* If two JAR files on the project classpath have the same name, only the first +JAR file is copied to the lib folder. +* Only JAR files are copied to the lib folder. +If the classpath contains other types of files or folders, these files (folders) +are not copied. +* If a library on the projects classpath also has a Class-Path element +specified in the manifest,the content of the Class-Path element has to be on +the projects runtime path. +* To set a main class in a standard Java project, right-click the project node +in the Projects window and choose Properties. Then click Run and enter the +class name in the Main Class field. Alternatively, you can manually type the +class name in the manifest Main-Class element. diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_07/dist/ff_07.jar b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_07/dist/ff_07.jar new file mode 100644 index 0000000..eeff6e4 Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_07/dist/ff_07.jar differ diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_07/manifest.mf b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_07/manifest.mf new file mode 100644 index 0000000..328e8e5 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_07/manifest.mf @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +X-COMMENT: Main-Class will be added automatically by build + diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_07/nbproject/build-impl.xml b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_07/nbproject/build-impl.xml new file mode 100644 index 0000000..3304480 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_07/nbproject/build-impl.xml @@ -0,0 +1,1041 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set src.dir + Must set test.src.dir + Must set build.dir + Must set dist.dir + Must set build.classes.dir + Must set dist.javadoc.dir + Must set build.test.classes.dir + Must set build.test.results.dir + Must set build.classes.excludes + Must set dist.jar + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set JVM to use for profiling in profiler.info.jvm + Must set profiler agent JVM arguments in profiler.info.jvmargs.agent + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + + + + + + java -cp "${run.classpath.with.dist.jar}" ${main.class} + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + java -jar "${dist.jar.resolved}" + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set run.class + + + + Must select one file in the IDE or set run.class + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set debug.class + + + + + Must select one file in the IDE or set debug.class + + + + + Must set fix.includes + + + + + + + + + + + + + + + + + Must select one file in the IDE or set profile.class + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + Some tests failed; see details above. + + + + + + + + + Must select some files in the IDE or set test.includes + + + + Some tests failed; see details above. + + + + + Must select one file in the IDE or set test.class + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_07/nbproject/genfiles.properties b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_07/nbproject/genfiles.properties new file mode 100644 index 0000000..88f8964 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_07/nbproject/genfiles.properties @@ -0,0 +1,8 @@ +build.xml.data.CRC32=19ad228d +build.xml.script.CRC32=cf9279e9 +build.xml.stylesheet.CRC32=28e38971@1.43.1.45 +# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. +# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. +nbproject/build-impl.xml.data.CRC32=19ad228d +nbproject/build-impl.xml.script.CRC32=77621838 +nbproject/build-impl.xml.stylesheet.CRC32=0c01fd8e@1.43.1.45 diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_07/nbproject/private/config.properties b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_07/nbproject/private/config.properties new file mode 100644 index 0000000..e69de29 diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_07/nbproject/private/private.properties b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_07/nbproject/private/private.properties new file mode 100644 index 0000000..a5ab360 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_07/nbproject/private/private.properties @@ -0,0 +1,6 @@ +compile.on.save=true +do.depend=false +do.jar=true +javac.debug=true +javadoc.preview=true +user.properties.file=C:\\Users\\Leo\\.netbeans\\7.0\\build.properties diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_07/nbproject/private/private.xml b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_07/nbproject/private/private.xml new file mode 100644 index 0000000..c1f155a --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_07/nbproject/private/private.xml @@ -0,0 +1,4 @@ + + + + diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_07/nbproject/project.properties b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_07/nbproject/project.properties new file mode 100644 index 0000000..009cb06 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_07/nbproject/project.properties @@ -0,0 +1,72 @@ +annotation.processing.enabled=true +annotation.processing.enabled.in.editor=false +annotation.processing.run.all.processors=true +annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output +application.title=ff_07 +application.vendor=Leo +build.classes.dir=${build.dir}/classes +build.classes.excludes=**/*.java,**/*.form +# This directory is removed when the project is cleaned: +build.dir=build +build.generated.dir=${build.dir}/generated +build.generated.sources.dir=${build.dir}/generated-sources +# Only compile against the classpath explicitly listed here: +build.sysclasspath=ignore +build.test.classes.dir=${build.dir}/test/classes +build.test.results.dir=${build.dir}/test/results +# Uncomment to specify the preferred debugger connection transport: +#debug.transport=dt_socket +debug.classpath=\ + ${run.classpath} +debug.test.classpath=\ + ${run.test.classpath} +# This directory is removed when the project is cleaned: +dist.dir=dist +dist.jar=${dist.dir}/ff_07.jar +dist.javadoc.dir=${dist.dir}/javadoc +endorsed.classpath= +excludes= +includes=** +jar.compress=false +javac.classpath= +# Space-separated list of extra javac options +javac.compilerargs= +javac.deprecation=false +javac.processorpath=\ + ${javac.classpath} +javac.source=1.7 +javac.target=1.7 +javac.test.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +javac.test.processorpath=\ + ${javac.test.classpath} +javadoc.additionalparam= +javadoc.author=false +javadoc.encoding=${source.encoding} +javadoc.noindex=false +javadoc.nonavbar=false +javadoc.notree=false +javadoc.private=false +javadoc.splitindex=true +javadoc.use=true +javadoc.version=false +javadoc.windowtitle= +main.class=ff_07.Main +manifest.file=manifest.mf +meta.inf.dir=${src.dir}/META-INF +mkdist.disabled=false +platform.active=default_platform +run.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +# Space-separated list of JVM arguments used when running the project +# (you may also define separate properties like run-sys-prop.name=value instead of -Dname=value +# or test-sys-prop.name=value to set system properties for unit tests): +run.jvmargs= +run.test.classpath=\ + ${javac.test.classpath}:\ + ${build.test.classes.dir} +source.encoding=UTF-8 +src.dir=src +test.src.dir=test diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_07/nbproject/project.xml b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_07/nbproject/project.xml new file mode 100644 index 0000000..6a07f36 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_07/nbproject/project.xml @@ -0,0 +1,15 @@ + + + org.netbeans.modules.java.j2seproject + + + ff_07 + + + + + + + + + diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_07/src/ff_07/Main.java b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_07/src/ff_07/Main.java new file mode 100644 index 0000000..fb62ac8 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_07/src/ff_07/Main.java @@ -0,0 +1,32 @@ +package ff_07; + +import java.io.IOException; +import java.nio.file.FileSystems; +import java.nio.file.Files; +import java.nio.file.Path; + +/** + * + * @author apress + */ +public class Main { + + public static void main(String[] args) { + + Path path_1 = FileSystems.getDefault().getPath("C:/rafaelnadal/tournaments/2009", "MutuaMadridOpen.txt"); + Path path_2 = FileSystems.getDefault().getPath("/rafaelnadal/tournaments/2009", "MutuaMadridOpen.txt"); + Path path_3 = FileSystems.getDefault().getPath("/rafaelnadal/tournaments/dummy/../2009", "MutuaMadridOpen.txt"); + + try { + boolean is_same_file_12 = Files.isSameFile(path_1, path_2); + boolean is_same_file_13 = Files.isSameFile(path_1, path_3); + boolean is_same_file_23 = Files.isSameFile(path_2, path_3); + System.out.println("is same file 1&2 ? " + is_same_file_12); + System.out.println("is same file 1&3 ? " + is_same_file_13); + System.out.println("is same file 2&3 ? " + is_same_file_23); + } catch (IOException e) { + System.err.println(e); + } + + } +} diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_08/build.xml b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_08/build.xml new file mode 100644 index 0000000..06f4814 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_08/build.xml @@ -0,0 +1,74 @@ + + + + + + + + + + + Builds, tests, and runs the project ff_08. + + + diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_08/build/built-jar.properties b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_08/build/built-jar.properties new file mode 100644 index 0000000..0bfebee --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_08/build/built-jar.properties @@ -0,0 +1,4 @@ +#Mon, 17 Oct 2011 06:40:29 +0200 + + +C\:\\NIO\\filesandfolders\\ff_08= diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_08/build/classes/ff_08/Main.class b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_08/build/classes/ff_08/Main.class new file mode 100644 index 0000000..0ae2459 Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_08/build/classes/ff_08/Main.class differ diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_08/dist/README.TXT b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_08/dist/README.TXT new file mode 100644 index 0000000..8932108 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_08/dist/README.TXT @@ -0,0 +1,32 @@ +======================== +BUILD OUTPUT DESCRIPTION +======================== + +When you build an Java application project that has a main class, the IDE +automatically copies all of the JAR +files on the projects classpath to your projects dist/lib folder. The IDE +also adds each of the JAR files to the Class-Path element in the application +JAR files manifest file (MANIFEST.MF). + +To run the project from the command line, go to the dist folder and +type the following: + +java -jar "ff_08.jar" + +To distribute this project, zip up the dist folder (including the lib folder) +and distribute the ZIP file. + +Notes: + +* If two JAR files on the project classpath have the same name, only the first +JAR file is copied to the lib folder. +* Only JAR files are copied to the lib folder. +If the classpath contains other types of files or folders, these files (folders) +are not copied. +* If a library on the projects classpath also has a Class-Path element +specified in the manifest,the content of the Class-Path element has to be on +the projects runtime path. +* To set a main class in a standard Java project, right-click the project node +in the Projects window and choose Properties. Then click Run and enter the +class name in the Main Class field. Alternatively, you can manually type the +class name in the manifest Main-Class element. diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_08/dist/ff_08.jar b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_08/dist/ff_08.jar new file mode 100644 index 0000000..1c4bc52 Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_08/dist/ff_08.jar differ diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_08/manifest.mf b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_08/manifest.mf new file mode 100644 index 0000000..328e8e5 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_08/manifest.mf @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +X-COMMENT: Main-Class will be added automatically by build + diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_08/nbproject/build-impl.xml b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_08/nbproject/build-impl.xml new file mode 100644 index 0000000..23af21b --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_08/nbproject/build-impl.xml @@ -0,0 +1,1041 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set src.dir + Must set test.src.dir + Must set build.dir + Must set dist.dir + Must set build.classes.dir + Must set dist.javadoc.dir + Must set build.test.classes.dir + Must set build.test.results.dir + Must set build.classes.excludes + Must set dist.jar + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set JVM to use for profiling in profiler.info.jvm + Must set profiler agent JVM arguments in profiler.info.jvmargs.agent + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + + + + + + java -cp "${run.classpath.with.dist.jar}" ${main.class} + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + java -jar "${dist.jar.resolved}" + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set run.class + + + + Must select one file in the IDE or set run.class + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set debug.class + + + + + Must select one file in the IDE or set debug.class + + + + + Must set fix.includes + + + + + + + + + + + + + + + + + Must select one file in the IDE or set profile.class + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + Some tests failed; see details above. + + + + + + + + + Must select some files in the IDE or set test.includes + + + + Some tests failed; see details above. + + + + + Must select one file in the IDE or set test.class + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_08/nbproject/genfiles.properties b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_08/nbproject/genfiles.properties new file mode 100644 index 0000000..07f61e3 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_08/nbproject/genfiles.properties @@ -0,0 +1,8 @@ +build.xml.data.CRC32=614be74f +build.xml.script.CRC32=de243d92 +build.xml.stylesheet.CRC32=28e38971@1.43.1.45 +# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. +# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. +nbproject/build-impl.xml.data.CRC32=614be74f +nbproject/build-impl.xml.script.CRC32=7b2569c4 +nbproject/build-impl.xml.stylesheet.CRC32=0c01fd8e@1.43.1.45 diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_08/nbproject/private/config.properties b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_08/nbproject/private/config.properties new file mode 100644 index 0000000..e69de29 diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_08/nbproject/private/private.properties b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_08/nbproject/private/private.properties new file mode 100644 index 0000000..a5ab360 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_08/nbproject/private/private.properties @@ -0,0 +1,6 @@ +compile.on.save=true +do.depend=false +do.jar=true +javac.debug=true +javadoc.preview=true +user.properties.file=C:\\Users\\Leo\\.netbeans\\7.0\\build.properties diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_08/nbproject/private/private.xml b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_08/nbproject/private/private.xml new file mode 100644 index 0000000..c1f155a --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_08/nbproject/private/private.xml @@ -0,0 +1,4 @@ + + + + diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_08/nbproject/project.properties b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_08/nbproject/project.properties new file mode 100644 index 0000000..89ee696 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_08/nbproject/project.properties @@ -0,0 +1,72 @@ +annotation.processing.enabled=true +annotation.processing.enabled.in.editor=false +annotation.processing.run.all.processors=true +annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output +application.title=ff_08 +application.vendor=Leo +build.classes.dir=${build.dir}/classes +build.classes.excludes=**/*.java,**/*.form +# This directory is removed when the project is cleaned: +build.dir=build +build.generated.dir=${build.dir}/generated +build.generated.sources.dir=${build.dir}/generated-sources +# Only compile against the classpath explicitly listed here: +build.sysclasspath=ignore +build.test.classes.dir=${build.dir}/test/classes +build.test.results.dir=${build.dir}/test/results +# Uncomment to specify the preferred debugger connection transport: +#debug.transport=dt_socket +debug.classpath=\ + ${run.classpath} +debug.test.classpath=\ + ${run.test.classpath} +# This directory is removed when the project is cleaned: +dist.dir=dist +dist.jar=${dist.dir}/ff_08.jar +dist.javadoc.dir=${dist.dir}/javadoc +endorsed.classpath= +excludes= +includes=** +jar.compress=false +javac.classpath= +# Space-separated list of extra javac options +javac.compilerargs= +javac.deprecation=false +javac.processorpath=\ + ${javac.classpath} +javac.source=1.7 +javac.target=1.7 +javac.test.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +javac.test.processorpath=\ + ${javac.test.classpath} +javadoc.additionalparam= +javadoc.author=false +javadoc.encoding=${source.encoding} +javadoc.noindex=false +javadoc.nonavbar=false +javadoc.notree=false +javadoc.private=false +javadoc.splitindex=true +javadoc.use=true +javadoc.version=false +javadoc.windowtitle= +main.class=ff_08.Main +manifest.file=manifest.mf +meta.inf.dir=${src.dir}/META-INF +mkdist.disabled=false +platform.active=default_platform +run.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +# Space-separated list of JVM arguments used when running the project +# (you may also define separate properties like run-sys-prop.name=value instead of -Dname=value +# or test-sys-prop.name=value to set system properties for unit tests): +run.jvmargs= +run.test.classpath=\ + ${javac.test.classpath}:\ + ${build.test.classes.dir} +source.encoding=UTF-8 +src.dir=src +test.src.dir=test diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_08/nbproject/project.xml b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_08/nbproject/project.xml new file mode 100644 index 0000000..cca790a --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_08/nbproject/project.xml @@ -0,0 +1,15 @@ + + + org.netbeans.modules.java.j2seproject + + + ff_08 + + + + + + + + + diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_08/src/ff_08/Main.java b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_08/src/ff_08/Main.java new file mode 100644 index 0000000..acf7f4d --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_08/src/ff_08/Main.java @@ -0,0 +1,27 @@ +package ff_08; + +import java.io.File; +import java.nio.file.FileSystems; +import java.nio.file.Path; + +/** + * + * @author Apress + */ +public class Main { + + public static void main(String[] args) { + + //Java 6 solution + File[] roots = File.listRoots(); + for (File root : roots) { + System.out.println(root); + } + + //Java 7 solution + Iterable dirs = FileSystems.getDefault().getRootDirectories(); + for (Path name : dirs) { + System.out.println(name); + } + } +} diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_09/build.xml b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_09/build.xml new file mode 100644 index 0000000..f91b1d0 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_09/build.xml @@ -0,0 +1,74 @@ + + + + + + + + + + + Builds, tests, and runs the project ff_09. + + + diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_09/build/built-jar.properties b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_09/build/built-jar.properties new file mode 100644 index 0000000..9731962 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_09/build/built-jar.properties @@ -0,0 +1,4 @@ +#Mon, 17 Oct 2011 06:42:17 +0200 + + +C\:\\NIO\\filesandfolders\\ff_09= diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_09/build/classes/ff_09/Main.class b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_09/build/classes/ff_09/Main.class new file mode 100644 index 0000000..3205237 Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_09/build/classes/ff_09/Main.class differ diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_09/dist/README.TXT b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_09/dist/README.TXT new file mode 100644 index 0000000..cf7b40c --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_09/dist/README.TXT @@ -0,0 +1,32 @@ +======================== +BUILD OUTPUT DESCRIPTION +======================== + +When you build an Java application project that has a main class, the IDE +automatically copies all of the JAR +files on the projects classpath to your projects dist/lib folder. The IDE +also adds each of the JAR files to the Class-Path element in the application +JAR files manifest file (MANIFEST.MF). + +To run the project from the command line, go to the dist folder and +type the following: + +java -jar "ff_09.jar" + +To distribute this project, zip up the dist folder (including the lib folder) +and distribute the ZIP file. + +Notes: + +* If two JAR files on the project classpath have the same name, only the first +JAR file is copied to the lib folder. +* Only JAR files are copied to the lib folder. +If the classpath contains other types of files or folders, these files (folders) +are not copied. +* If a library on the projects classpath also has a Class-Path element +specified in the manifest,the content of the Class-Path element has to be on +the projects runtime path. +* To set a main class in a standard Java project, right-click the project node +in the Projects window and choose Properties. Then click Run and enter the +class name in the Main Class field. Alternatively, you can manually type the +class name in the manifest Main-Class element. diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_09/dist/ff_09.jar b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_09/dist/ff_09.jar new file mode 100644 index 0000000..9b026b0 Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_09/dist/ff_09.jar differ diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_09/manifest.mf b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_09/manifest.mf new file mode 100644 index 0000000..328e8e5 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_09/manifest.mf @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +X-COMMENT: Main-Class will be added automatically by build + diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_09/nbproject/build-impl.xml b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_09/nbproject/build-impl.xml new file mode 100644 index 0000000..c8aea53 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_09/nbproject/build-impl.xml @@ -0,0 +1,1041 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set src.dir + Must set test.src.dir + Must set build.dir + Must set dist.dir + Must set build.classes.dir + Must set dist.javadoc.dir + Must set build.test.classes.dir + Must set build.test.results.dir + Must set build.classes.excludes + Must set dist.jar + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set JVM to use for profiling in profiler.info.jvm + Must set profiler agent JVM arguments in profiler.info.jvmargs.agent + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + + + + + + java -cp "${run.classpath.with.dist.jar}" ${main.class} + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + java -jar "${dist.jar.resolved}" + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set run.class + + + + Must select one file in the IDE or set run.class + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set debug.class + + + + + Must select one file in the IDE or set debug.class + + + + + Must set fix.includes + + + + + + + + + + + + + + + + + Must select one file in the IDE or set profile.class + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + Some tests failed; see details above. + + + + + + + + + Must select some files in the IDE or set test.includes + + + + Some tests failed; see details above. + + + + + Must select one file in the IDE or set test.class + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_09/nbproject/genfiles.properties b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_09/nbproject/genfiles.properties new file mode 100644 index 0000000..29bd799 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_09/nbproject/genfiles.properties @@ -0,0 +1,8 @@ +build.xml.data.CRC32=69586b69 +build.xml.script.CRC32=22c8cd16 +build.xml.stylesheet.CRC32=28e38971@1.43.1.45 +# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. +# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. +nbproject/build-impl.xml.data.CRC32=69586b69 +nbproject/build-impl.xml.script.CRC32=ccac9dbf +nbproject/build-impl.xml.stylesheet.CRC32=0c01fd8e@1.43.1.45 diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_09/nbproject/private/config.properties b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_09/nbproject/private/config.properties new file mode 100644 index 0000000..e69de29 diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_09/nbproject/private/private.properties b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_09/nbproject/private/private.properties new file mode 100644 index 0000000..a5ab360 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_09/nbproject/private/private.properties @@ -0,0 +1,6 @@ +compile.on.save=true +do.depend=false +do.jar=true +javac.debug=true +javadoc.preview=true +user.properties.file=C:\\Users\\Leo\\.netbeans\\7.0\\build.properties diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_09/nbproject/private/private.xml b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_09/nbproject/private/private.xml new file mode 100644 index 0000000..c1f155a --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_09/nbproject/private/private.xml @@ -0,0 +1,4 @@ + + + + diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_09/nbproject/project.properties b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_09/nbproject/project.properties new file mode 100644 index 0000000..ecf06fd --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_09/nbproject/project.properties @@ -0,0 +1,72 @@ +annotation.processing.enabled=true +annotation.processing.enabled.in.editor=false +annotation.processing.run.all.processors=true +annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output +application.title=ff_09 +application.vendor=Leo +build.classes.dir=${build.dir}/classes +build.classes.excludes=**/*.java,**/*.form +# This directory is removed when the project is cleaned: +build.dir=build +build.generated.dir=${build.dir}/generated +build.generated.sources.dir=${build.dir}/generated-sources +# Only compile against the classpath explicitly listed here: +build.sysclasspath=ignore +build.test.classes.dir=${build.dir}/test/classes +build.test.results.dir=${build.dir}/test/results +# Uncomment to specify the preferred debugger connection transport: +#debug.transport=dt_socket +debug.classpath=\ + ${run.classpath} +debug.test.classpath=\ + ${run.test.classpath} +# This directory is removed when the project is cleaned: +dist.dir=dist +dist.jar=${dist.dir}/ff_09.jar +dist.javadoc.dir=${dist.dir}/javadoc +endorsed.classpath= +excludes= +includes=** +jar.compress=false +javac.classpath= +# Space-separated list of extra javac options +javac.compilerargs= +javac.deprecation=false +javac.processorpath=\ + ${javac.classpath} +javac.source=1.7 +javac.target=1.7 +javac.test.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +javac.test.processorpath=\ + ${javac.test.classpath} +javadoc.additionalparam= +javadoc.author=false +javadoc.encoding=${source.encoding} +javadoc.noindex=false +javadoc.nonavbar=false +javadoc.notree=false +javadoc.private=false +javadoc.splitindex=true +javadoc.use=true +javadoc.version=false +javadoc.windowtitle= +main.class=ff_09.Main +manifest.file=manifest.mf +meta.inf.dir=${src.dir}/META-INF +mkdist.disabled=false +platform.active=default_platform +run.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +# Space-separated list of JVM arguments used when running the project +# (you may also define separate properties like run-sys-prop.name=value instead of -Dname=value +# or test-sys-prop.name=value to set system properties for unit tests): +run.jvmargs= +run.test.classpath=\ + ${javac.test.classpath}:\ + ${build.test.classes.dir} +source.encoding=UTF-8 +src.dir=src +test.src.dir=test diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_09/nbproject/project.xml b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_09/nbproject/project.xml new file mode 100644 index 0000000..bcc9555 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_09/nbproject/project.xml @@ -0,0 +1,15 @@ + + + org.netbeans.modules.java.j2seproject + + + ff_09 + + + + + + + + + diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_09/src/ff_09/Main.java b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_09/src/ff_09/Main.java new file mode 100644 index 0000000..4d3f071 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_09/src/ff_09/Main.java @@ -0,0 +1,48 @@ +package ff_09; + +import java.io.IOException; +import java.nio.file.FileSystems; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.attribute.FileAttribute; +import java.nio.file.attribute.PosixFilePermission; +import java.nio.file.attribute.PosixFilePermissions; +import java.util.Set; + +/** + * + * @author Apress + */ +public class Main { + + public static void main(String[] args) { + + Path newdir_1 = FileSystems.getDefault().getPath("C:/rafaelnadal/tournaments/2010/"); + Path newdir_posix = FileSystems.getDefault().getPath("/home/rafaelnadal/tournaments/2010/"); + Path newdir_2 = FileSystems.getDefault().getPath("/2010"); + Path newdir_3 = FileSystems.getDefault().getPath("2010"); + Path newdir_4 = FileSystems.getDefault().getPath("../2010"); + Path newdir_5 = FileSystems.getDefault().getPath("C:/rafaelnadal/", "statistics/win/prizes"); + + try { + Files.createDirectory(newdir_1); + } catch (IOException e) { + System.err.println(e); + } + + try { + Files.createDirectories(newdir_5); + } catch (IOException e) { + System.err.println(e); + } + + Set perms = PosixFilePermissions.fromString("rwxr-x---"); + FileAttribute> attr = PosixFilePermissions.asFileAttribute(perms); + try { + Files.createDirectory(newdir_posix, attr); + } catch (IOException e) { + System.err.println(e); + } + + } +} diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_10/build.xml b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_10/build.xml new file mode 100644 index 0000000..c0d473f --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_10/build.xml @@ -0,0 +1,74 @@ + + + + + + + + + + + Builds, tests, and runs the project ff_10. + + + diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_10/build/built-jar.properties b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_10/build/built-jar.properties new file mode 100644 index 0000000..65eacd5 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_10/build/built-jar.properties @@ -0,0 +1,4 @@ +#Mon, 17 Oct 2011 06:44:08 +0200 + + +C\:\\NIO\\filesandfolders\\ff_10= diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_10/build/classes/ff_10/Main$1.class b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_10/build/classes/ff_10/Main$1.class new file mode 100644 index 0000000..3834b46 Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_10/build/classes/ff_10/Main$1.class differ diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_10/build/classes/ff_10/Main.class b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_10/build/classes/ff_10/Main.class new file mode 100644 index 0000000..a318f80 Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_10/build/classes/ff_10/Main.class differ diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_10/dist/README.TXT b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_10/dist/README.TXT new file mode 100644 index 0000000..0379d55 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_10/dist/README.TXT @@ -0,0 +1,32 @@ +======================== +BUILD OUTPUT DESCRIPTION +======================== + +When you build an Java application project that has a main class, the IDE +automatically copies all of the JAR +files on the projects classpath to your projects dist/lib folder. The IDE +also adds each of the JAR files to the Class-Path element in the application +JAR files manifest file (MANIFEST.MF). + +To run the project from the command line, go to the dist folder and +type the following: + +java -jar "ff_10.jar" + +To distribute this project, zip up the dist folder (including the lib folder) +and distribute the ZIP file. + +Notes: + +* If two JAR files on the project classpath have the same name, only the first +JAR file is copied to the lib folder. +* Only JAR files are copied to the lib folder. +If the classpath contains other types of files or folders, these files (folders) +are not copied. +* If a library on the projects classpath also has a Class-Path element +specified in the manifest,the content of the Class-Path element has to be on +the projects runtime path. +* To set a main class in a standard Java project, right-click the project node +in the Projects window and choose Properties. Then click Run and enter the +class name in the Main Class field. Alternatively, you can manually type the +class name in the manifest Main-Class element. diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_10/dist/ff_10.jar b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_10/dist/ff_10.jar new file mode 100644 index 0000000..c086e01 Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_10/dist/ff_10.jar differ diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_10/manifest.mf b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_10/manifest.mf new file mode 100644 index 0000000..328e8e5 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_10/manifest.mf @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +X-COMMENT: Main-Class will be added automatically by build + diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_10/nbproject/build-impl.xml b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_10/nbproject/build-impl.xml new file mode 100644 index 0000000..1aaf4fa --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_10/nbproject/build-impl.xml @@ -0,0 +1,1041 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set src.dir + Must set test.src.dir + Must set build.dir + Must set dist.dir + Must set build.classes.dir + Must set dist.javadoc.dir + Must set build.test.classes.dir + Must set build.test.results.dir + Must set build.classes.excludes + Must set dist.jar + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set JVM to use for profiling in profiler.info.jvm + Must set profiler agent JVM arguments in profiler.info.jvmargs.agent + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + + + + + + java -cp "${run.classpath.with.dist.jar}" ${main.class} + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + java -jar "${dist.jar.resolved}" + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set run.class + + + + Must select one file in the IDE or set run.class + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set debug.class + + + + + Must select one file in the IDE or set debug.class + + + + + Must set fix.includes + + + + + + + + + + + + + + + + + Must select one file in the IDE or set profile.class + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + Some tests failed; see details above. + + + + + + + + + Must select some files in the IDE or set test.includes + + + + Some tests failed; see details above. + + + + + Must select one file in the IDE or set test.class + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_10/nbproject/genfiles.properties b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_10/nbproject/genfiles.properties new file mode 100644 index 0000000..d964149 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_10/nbproject/genfiles.properties @@ -0,0 +1,8 @@ +build.xml.data.CRC32=f3d2100e +build.xml.script.CRC32=beae0b7f +build.xml.stylesheet.CRC32=28e38971@1.43.1.45 +# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. +# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. +nbproject/build-impl.xml.data.CRC32=f3d2100e +nbproject/build-impl.xml.script.CRC32=005df89b +nbproject/build-impl.xml.stylesheet.CRC32=0c01fd8e@1.43.1.45 diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_10/nbproject/private/config.properties b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_10/nbproject/private/config.properties new file mode 100644 index 0000000..e69de29 diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_10/nbproject/private/private.properties b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_10/nbproject/private/private.properties new file mode 100644 index 0000000..a5ab360 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_10/nbproject/private/private.properties @@ -0,0 +1,6 @@ +compile.on.save=true +do.depend=false +do.jar=true +javac.debug=true +javadoc.preview=true +user.properties.file=C:\\Users\\Leo\\.netbeans\\7.0\\build.properties diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_10/nbproject/private/private.xml b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_10/nbproject/private/private.xml new file mode 100644 index 0000000..c1f155a --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_10/nbproject/private/private.xml @@ -0,0 +1,4 @@ + + + + diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_10/nbproject/project.properties b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_10/nbproject/project.properties new file mode 100644 index 0000000..d58b2e5 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_10/nbproject/project.properties @@ -0,0 +1,72 @@ +annotation.processing.enabled=true +annotation.processing.enabled.in.editor=false +annotation.processing.run.all.processors=true +annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output +application.title=ff_10 +application.vendor=Leo +build.classes.dir=${build.dir}/classes +build.classes.excludes=**/*.java,**/*.form +# This directory is removed when the project is cleaned: +build.dir=build +build.generated.dir=${build.dir}/generated +build.generated.sources.dir=${build.dir}/generated-sources +# Only compile against the classpath explicitly listed here: +build.sysclasspath=ignore +build.test.classes.dir=${build.dir}/test/classes +build.test.results.dir=${build.dir}/test/results +# Uncomment to specify the preferred debugger connection transport: +#debug.transport=dt_socket +debug.classpath=\ + ${run.classpath} +debug.test.classpath=\ + ${run.test.classpath} +# This directory is removed when the project is cleaned: +dist.dir=dist +dist.jar=${dist.dir}/ff_10.jar +dist.javadoc.dir=${dist.dir}/javadoc +endorsed.classpath= +excludes= +includes=** +jar.compress=false +javac.classpath= +# Space-separated list of extra javac options +javac.compilerargs= +javac.deprecation=false +javac.processorpath=\ + ${javac.classpath} +javac.source=1.7 +javac.target=1.7 +javac.test.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +javac.test.processorpath=\ + ${javac.test.classpath} +javadoc.additionalparam= +javadoc.author=false +javadoc.encoding=${source.encoding} +javadoc.noindex=false +javadoc.nonavbar=false +javadoc.notree=false +javadoc.private=false +javadoc.splitindex=true +javadoc.use=true +javadoc.version=false +javadoc.windowtitle= +main.class=ff_10.Main +manifest.file=manifest.mf +meta.inf.dir=${src.dir}/META-INF +mkdist.disabled=false +platform.active=default_platform +run.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +# Space-separated list of JVM arguments used when running the project +# (you may also define separate properties like run-sys-prop.name=value instead of -Dname=value +# or test-sys-prop.name=value to set system properties for unit tests): +run.jvmargs= +run.test.classpath=\ + ${javac.test.classpath}:\ + ${build.test.classes.dir} +source.encoding=UTF-8 +src.dir=src +test.src.dir=test diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_10/nbproject/project.xml b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_10/nbproject/project.xml new file mode 100644 index 0000000..ee7f256 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_10/nbproject/project.xml @@ -0,0 +1,15 @@ + + + org.netbeans.modules.java.j2seproject + + + ff_10 + + + + + + + + + diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_10/src/ff_10/Main.java b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_10/src/ff_10/Main.java new file mode 100644 index 0000000..bdcc3b8 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_10/src/ff_10/Main.java @@ -0,0 +1,52 @@ +package ff_10; + +import java.io.IOException; +import java.nio.file.DirectoryStream; +import java.nio.file.FileSystems; +import java.nio.file.Files; +import java.nio.file.Path; + +/** + * + * @author Apress + */ +public class Main { + + public static void main(String[] args) { + + final Path basedir = FileSystems.getDefault().getPath("C:/rafaelnadal/tmp/"); + final String tmp_dir_prefix = "rafa_"; + + try { + //create a tmp directory in a the base dir + final Path tmp_dir = Files.createTempDirectory(basedir, tmp_dir_prefix); + + Runtime.getRuntime().addShutdownHook(new Thread() { + + @Override + public void run() { + System.out.println("Deleting the temporary folder ..."); + try (DirectoryStream ds = Files.newDirectoryStream(tmp_dir)) { + for (Path file : ds) { + Files.delete(file); + } + + Files.delete(tmp_dir); + + } catch (IOException e) { + System.err.println(e); + } + System.out.println("Shutdown-hook completed..."); + } + }); + + //simulate some operations with temp file until delete it + Thread.sleep(10000); + //operations done + + } catch (IOException | InterruptedException e) { + System.err.println(e); + } + + } +} diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_11/build.xml b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_11/build.xml new file mode 100644 index 0000000..8c4d134 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_11/build.xml @@ -0,0 +1,74 @@ + + + + + + + + + + + Builds, tests, and runs the project ff_11. + + + diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_11/build/built-jar.properties b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_11/build/built-jar.properties new file mode 100644 index 0000000..1415ac6 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_11/build/built-jar.properties @@ -0,0 +1,4 @@ +#Mon, 17 Oct 2011 06:45:34 +0200 + + +C\:\\NIO\\filesandfolders\\ff_11= diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_11/build/classes/ff_11/Main.class b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_11/build/classes/ff_11/Main.class new file mode 100644 index 0000000..a125eb5 Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_11/build/classes/ff_11/Main.class differ diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_11/dist/README.TXT b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_11/dist/README.TXT new file mode 100644 index 0000000..8fa640a --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_11/dist/README.TXT @@ -0,0 +1,32 @@ +======================== +BUILD OUTPUT DESCRIPTION +======================== + +When you build an Java application project that has a main class, the IDE +automatically copies all of the JAR +files on the projects classpath to your projects dist/lib folder. The IDE +also adds each of the JAR files to the Class-Path element in the application +JAR files manifest file (MANIFEST.MF). + +To run the project from the command line, go to the dist folder and +type the following: + +java -jar "ff_11.jar" + +To distribute this project, zip up the dist folder (including the lib folder) +and distribute the ZIP file. + +Notes: + +* If two JAR files on the project classpath have the same name, only the first +JAR file is copied to the lib folder. +* Only JAR files are copied to the lib folder. +If the classpath contains other types of files or folders, these files (folders) +are not copied. +* If a library on the projects classpath also has a Class-Path element +specified in the manifest,the content of the Class-Path element has to be on +the projects runtime path. +* To set a main class in a standard Java project, right-click the project node +in the Projects window and choose Properties. Then click Run and enter the +class name in the Main Class field. Alternatively, you can manually type the +class name in the manifest Main-Class element. diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_11/dist/ff_11.jar b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_11/dist/ff_11.jar new file mode 100644 index 0000000..6fef989 Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_11/dist/ff_11.jar differ diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_11/manifest.mf b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_11/manifest.mf new file mode 100644 index 0000000..328e8e5 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_11/manifest.mf @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +X-COMMENT: Main-Class will be added automatically by build + diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_11/nbproject/build-impl.xml b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_11/nbproject/build-impl.xml new file mode 100644 index 0000000..8f6e858 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_11/nbproject/build-impl.xml @@ -0,0 +1,1041 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set src.dir + Must set test.src.dir + Must set build.dir + Must set dist.dir + Must set build.classes.dir + Must set dist.javadoc.dir + Must set build.test.classes.dir + Must set build.test.results.dir + Must set build.classes.excludes + Must set dist.jar + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set JVM to use for profiling in profiler.info.jvm + Must set profiler agent JVM arguments in profiler.info.jvmargs.agent + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + + + + + + java -cp "${run.classpath.with.dist.jar}" ${main.class} + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + java -jar "${dist.jar.resolved}" + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set run.class + + + + Must select one file in the IDE or set run.class + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set debug.class + + + + + Must select one file in the IDE or set debug.class + + + + + Must set fix.includes + + + + + + + + + + + + + + + + + Must select one file in the IDE or set profile.class + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + Some tests failed; see details above. + + + + + + + + + Must select some files in the IDE or set test.includes + + + + Some tests failed; see details above. + + + + + Must select one file in the IDE or set test.class + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_11/nbproject/genfiles.properties b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_11/nbproject/genfiles.properties new file mode 100644 index 0000000..7ba6a57 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_11/nbproject/genfiles.properties @@ -0,0 +1,8 @@ +build.xml.data.CRC32=fbc19c28 +build.xml.script.CRC32=4242fbfb +build.xml.stylesheet.CRC32=28e38971@1.43.1.45 +# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. +# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. +nbproject/build-impl.xml.data.CRC32=fbc19c28 +nbproject/build-impl.xml.script.CRC32=b7d40ce0 +nbproject/build-impl.xml.stylesheet.CRC32=0c01fd8e@1.43.1.45 diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_11/nbproject/private/config.properties b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_11/nbproject/private/config.properties new file mode 100644 index 0000000..e69de29 diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_11/nbproject/private/private.properties b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_11/nbproject/private/private.properties new file mode 100644 index 0000000..a5ab360 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_11/nbproject/private/private.properties @@ -0,0 +1,6 @@ +compile.on.save=true +do.depend=false +do.jar=true +javac.debug=true +javadoc.preview=true +user.properties.file=C:\\Users\\Leo\\.netbeans\\7.0\\build.properties diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_11/nbproject/private/private.xml b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_11/nbproject/private/private.xml new file mode 100644 index 0000000..c1f155a --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_11/nbproject/private/private.xml @@ -0,0 +1,4 @@ + + + + diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_11/nbproject/project.properties b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_11/nbproject/project.properties new file mode 100644 index 0000000..a5aeb55 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_11/nbproject/project.properties @@ -0,0 +1,72 @@ +annotation.processing.enabled=true +annotation.processing.enabled.in.editor=false +annotation.processing.run.all.processors=true +annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output +application.title=ff_11 +application.vendor=Leo +build.classes.dir=${build.dir}/classes +build.classes.excludes=**/*.java,**/*.form +# This directory is removed when the project is cleaned: +build.dir=build +build.generated.dir=${build.dir}/generated +build.generated.sources.dir=${build.dir}/generated-sources +# Only compile against the classpath explicitly listed here: +build.sysclasspath=ignore +build.test.classes.dir=${build.dir}/test/classes +build.test.results.dir=${build.dir}/test/results +# Uncomment to specify the preferred debugger connection transport: +#debug.transport=dt_socket +debug.classpath=\ + ${run.classpath} +debug.test.classpath=\ + ${run.test.classpath} +# This directory is removed when the project is cleaned: +dist.dir=dist +dist.jar=${dist.dir}/ff_11.jar +dist.javadoc.dir=${dist.dir}/javadoc +endorsed.classpath= +excludes= +includes=** +jar.compress=false +javac.classpath= +# Space-separated list of extra javac options +javac.compilerargs= +javac.deprecation=false +javac.processorpath=\ + ${javac.classpath} +javac.source=1.7 +javac.target=1.7 +javac.test.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +javac.test.processorpath=\ + ${javac.test.classpath} +javadoc.additionalparam= +javadoc.author=false +javadoc.encoding=${source.encoding} +javadoc.noindex=false +javadoc.nonavbar=false +javadoc.notree=false +javadoc.private=false +javadoc.splitindex=true +javadoc.use=true +javadoc.version=false +javadoc.windowtitle= +main.class=ff_11.Main +manifest.file=manifest.mf +meta.inf.dir=${src.dir}/META-INF +mkdist.disabled=false +platform.active=default_platform +run.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +# Space-separated list of JVM arguments used when running the project +# (you may also define separate properties like run-sys-prop.name=value instead of -Dname=value +# or test-sys-prop.name=value to set system properties for unit tests): +run.jvmargs= +run.test.classpath=\ + ${javac.test.classpath}:\ + ${build.test.classes.dir} +source.encoding=UTF-8 +src.dir=src +test.src.dir=test diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_11/nbproject/project.xml b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_11/nbproject/project.xml new file mode 100644 index 0000000..047da93 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_11/nbproject/project.xml @@ -0,0 +1,15 @@ + + + org.netbeans.modules.java.j2seproject + + + ff_11 + + + + + + + + + diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_11/src/ff_11/Main.java b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_11/src/ff_11/Main.java new file mode 100644 index 0000000..07c76d8 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_11/src/ff_11/Main.java @@ -0,0 +1,37 @@ +package ff_11; + +import java.io.IOException; +import java.nio.file.FileSystems; +import java.nio.file.Files; +import java.nio.file.Path; + +/** + * + * @author Apress + */ +public class Main { + + public static void main(String[] args) { + + Path basedir = FileSystems.getDefault().getPath("C:/rafaelnadal/tmp/"); + String tmp_dir_prefix = "rafa_"; + + //get the default temporary folders path + String default_tmp = System.getProperty("java.io.tmpdir"); + System.out.println(default_tmp); + + try { + //passing null prefix + Path tmp_1 = Files.createTempDirectory(null); + System.out.println("TMP: " + tmp_1.toString()); + //set a prefix + Path tmp_2 = Files.createTempDirectory(tmp_dir_prefix); + System.out.println("TMP: " + tmp_2.toString()); + //create a tmp directory in a the base dir + Path tmp_3 = Files.createTempDirectory(basedir, tmp_dir_prefix); + System.out.println("TMP: " + tmp_3.toString()); + } catch (IOException e) { + System.err.println(e); + } + } +} diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_12/build.xml b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_12/build.xml new file mode 100644 index 0000000..a9e7c03 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_12/build.xml @@ -0,0 +1,74 @@ + + + + + + + + + + + Builds, tests, and runs the project ff_12. + + + diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_12/build/built-jar.properties b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_12/build/built-jar.properties new file mode 100644 index 0000000..023bd7a --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_12/build/built-jar.properties @@ -0,0 +1,4 @@ +#Mon, 17 Oct 2011 06:46:43 +0200 + + +C\:\\NIO\\filesandfolders\\ff_12= diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_12/build/classes/ff_12/Main.class b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_12/build/classes/ff_12/Main.class new file mode 100644 index 0000000..f4cd8ad Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_12/build/classes/ff_12/Main.class differ diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_12/dist/README.TXT b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_12/dist/README.TXT new file mode 100644 index 0000000..31cd41b --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_12/dist/README.TXT @@ -0,0 +1,32 @@ +======================== +BUILD OUTPUT DESCRIPTION +======================== + +When you build an Java application project that has a main class, the IDE +automatically copies all of the JAR +files on the projects classpath to your projects dist/lib folder. The IDE +also adds each of the JAR files to the Class-Path element in the application +JAR files manifest file (MANIFEST.MF). + +To run the project from the command line, go to the dist folder and +type the following: + +java -jar "ff_12.jar" + +To distribute this project, zip up the dist folder (including the lib folder) +and distribute the ZIP file. + +Notes: + +* If two JAR files on the project classpath have the same name, only the first +JAR file is copied to the lib folder. +* Only JAR files are copied to the lib folder. +If the classpath contains other types of files or folders, these files (folders) +are not copied. +* If a library on the projects classpath also has a Class-Path element +specified in the manifest,the content of the Class-Path element has to be on +the projects runtime path. +* To set a main class in a standard Java project, right-click the project node +in the Projects window and choose Properties. Then click Run and enter the +class name in the Main Class field. Alternatively, you can manually type the +class name in the manifest Main-Class element. diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_12/dist/ff_12.jar b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_12/dist/ff_12.jar new file mode 100644 index 0000000..5e3241f Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_12/dist/ff_12.jar differ diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_12/manifest.mf b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_12/manifest.mf new file mode 100644 index 0000000..328e8e5 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_12/manifest.mf @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +X-COMMENT: Main-Class will be added automatically by build + diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_12/nbproject/build-impl.xml b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_12/nbproject/build-impl.xml new file mode 100644 index 0000000..d7e513c --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_12/nbproject/build-impl.xml @@ -0,0 +1,1041 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set src.dir + Must set test.src.dir + Must set build.dir + Must set dist.dir + Must set build.classes.dir + Must set dist.javadoc.dir + Must set build.test.classes.dir + Must set build.test.results.dir + Must set build.classes.excludes + Must set dist.jar + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set JVM to use for profiling in profiler.info.jvm + Must set profiler agent JVM arguments in profiler.info.jvmargs.agent + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + + + + + + java -cp "${run.classpath.with.dist.jar}" ${main.class} + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + java -jar "${dist.jar.resolved}" + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set run.class + + + + Must select one file in the IDE or set run.class + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set debug.class + + + + + Must select one file in the IDE or set debug.class + + + + + Must set fix.includes + + + + + + + + + + + + + + + + + Must select one file in the IDE or set profile.class + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + Some tests failed; see details above. + + + + + + + + + Must select some files in the IDE or set test.includes + + + + Some tests failed; see details above. + + + + + Must select one file in the IDE or set test.class + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_12/nbproject/genfiles.properties b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_12/nbproject/genfiles.properties new file mode 100644 index 0000000..c44438e --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_12/nbproject/genfiles.properties @@ -0,0 +1,8 @@ +build.xml.data.CRC32=e3f50842 +build.xml.script.CRC32=9c06ec36 +build.xml.stylesheet.CRC32=28e38971@1.43.1.45 +# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. +# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. +nbproject/build-impl.xml.data.CRC32=e3f50842 +nbproject/build-impl.xml.script.CRC32=b43f162c +nbproject/build-impl.xml.stylesheet.CRC32=0c01fd8e@1.43.1.45 diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_12/nbproject/private/config.properties b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_12/nbproject/private/config.properties new file mode 100644 index 0000000..e69de29 diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_12/nbproject/private/private.properties b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_12/nbproject/private/private.properties new file mode 100644 index 0000000..a5ab360 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_12/nbproject/private/private.properties @@ -0,0 +1,6 @@ +compile.on.save=true +do.depend=false +do.jar=true +javac.debug=true +javadoc.preview=true +user.properties.file=C:\\Users\\Leo\\.netbeans\\7.0\\build.properties diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_12/nbproject/private/private.xml b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_12/nbproject/private/private.xml new file mode 100644 index 0000000..c1f155a --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_12/nbproject/private/private.xml @@ -0,0 +1,4 @@ + + + + diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_12/nbproject/project.properties b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_12/nbproject/project.properties new file mode 100644 index 0000000..3e00689 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_12/nbproject/project.properties @@ -0,0 +1,72 @@ +annotation.processing.enabled=true +annotation.processing.enabled.in.editor=false +annotation.processing.run.all.processors=true +annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output +application.title=ff_12 +application.vendor=Leo +build.classes.dir=${build.dir}/classes +build.classes.excludes=**/*.java,**/*.form +# This directory is removed when the project is cleaned: +build.dir=build +build.generated.dir=${build.dir}/generated +build.generated.sources.dir=${build.dir}/generated-sources +# Only compile against the classpath explicitly listed here: +build.sysclasspath=ignore +build.test.classes.dir=${build.dir}/test/classes +build.test.results.dir=${build.dir}/test/results +# Uncomment to specify the preferred debugger connection transport: +#debug.transport=dt_socket +debug.classpath=\ + ${run.classpath} +debug.test.classpath=\ + ${run.test.classpath} +# This directory is removed when the project is cleaned: +dist.dir=dist +dist.jar=${dist.dir}/ff_12.jar +dist.javadoc.dir=${dist.dir}/javadoc +endorsed.classpath= +excludes= +includes=** +jar.compress=false +javac.classpath= +# Space-separated list of extra javac options +javac.compilerargs= +javac.deprecation=false +javac.processorpath=\ + ${javac.classpath} +javac.source=1.7 +javac.target=1.7 +javac.test.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +javac.test.processorpath=\ + ${javac.test.classpath} +javadoc.additionalparam= +javadoc.author=false +javadoc.encoding=${source.encoding} +javadoc.noindex=false +javadoc.nonavbar=false +javadoc.notree=false +javadoc.private=false +javadoc.splitindex=true +javadoc.use=true +javadoc.version=false +javadoc.windowtitle= +main.class=ff_12.Main +manifest.file=manifest.mf +meta.inf.dir=${src.dir}/META-INF +mkdist.disabled=false +platform.active=default_platform +run.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +# Space-separated list of JVM arguments used when running the project +# (you may also define separate properties like run-sys-prop.name=value instead of -Dname=value +# or test-sys-prop.name=value to set system properties for unit tests): +run.jvmargs= +run.test.classpath=\ + ${javac.test.classpath}:\ + ${build.test.classes.dir} +source.encoding=UTF-8 +src.dir=src +test.src.dir=test diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_12/nbproject/project.xml b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_12/nbproject/project.xml new file mode 100644 index 0000000..fc01e9f --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_12/nbproject/project.xml @@ -0,0 +1,15 @@ + + + org.netbeans.modules.java.j2seproject + + + ff_12 + + + + + + + + + diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_12/src/ff_12/Main.java b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_12/src/ff_12/Main.java new file mode 100644 index 0000000..bdc316f --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_12/src/ff_12/Main.java @@ -0,0 +1,37 @@ +package ff_12; + +import java.io.File; +import java.io.IOException; +import java.nio.file.FileSystems; +import java.nio.file.Files; +import java.nio.file.Path; + +/** + * + * @author Apress + */ +public class Main { + + public static void main(String[] args) { + + Path basedir = FileSystems.getDefault().getPath("C:/rafaelnadal/tmp/"); + String tmp_dir_prefix = "rafa_"; + + try { + //create a tmp directory in a the base dir + Path tmp_dir = Files.createTempDirectory(basedir, tmp_dir_prefix); + + File asFile = tmp_dir.toFile(); + asFile.deleteOnExit(); + + //simulate some operations with temp file until delete it + //EACH ENTRY SHOULD BE REGISTERED FOR DELETE ON EXIT + Thread.sleep(10000); + //operations done + + } catch (IOException | InterruptedException e) { + System.err.println(e); + } + + } +} diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_13/build.xml b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_13/build.xml new file mode 100644 index 0000000..1f2a3b0 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_13/build.xml @@ -0,0 +1,74 @@ + + + + + + + + + + + Builds, tests, and runs the project ff_13. + + + diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_13/build/built-jar.properties b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_13/build/built-jar.properties new file mode 100644 index 0000000..73571e4 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_13/build/built-jar.properties @@ -0,0 +1,4 @@ +#Mon, 17 Oct 2011 06:51:31 +0200 + + +C\:\\NIO\\filesandfolders\\ff_13= diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_13/build/classes/ff_13/Main$1.class b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_13/build/classes/ff_13/Main$1.class new file mode 100644 index 0000000..8464bbc Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_13/build/classes/ff_13/Main$1.class differ diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_13/build/classes/ff_13/Main$2.class b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_13/build/classes/ff_13/Main$2.class new file mode 100644 index 0000000..83c8c36 Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_13/build/classes/ff_13/Main$2.class differ diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_13/build/classes/ff_13/Main$3.class b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_13/build/classes/ff_13/Main$3.class new file mode 100644 index 0000000..004c61f Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_13/build/classes/ff_13/Main$3.class differ diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_13/build/classes/ff_13/Main$4.class b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_13/build/classes/ff_13/Main$4.class new file mode 100644 index 0000000..9adb29e Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_13/build/classes/ff_13/Main$4.class differ diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_13/build/classes/ff_13/Main.class b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_13/build/classes/ff_13/Main.class new file mode 100644 index 0000000..0e81b0c Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_13/build/classes/ff_13/Main.class differ diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_13/dist/README.TXT b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_13/dist/README.TXT new file mode 100644 index 0000000..5436c91 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_13/dist/README.TXT @@ -0,0 +1,32 @@ +======================== +BUILD OUTPUT DESCRIPTION +======================== + +When you build an Java application project that has a main class, the IDE +automatically copies all of the JAR +files on the projects classpath to your projects dist/lib folder. The IDE +also adds each of the JAR files to the Class-Path element in the application +JAR files manifest file (MANIFEST.MF). + +To run the project from the command line, go to the dist folder and +type the following: + +java -jar "ff_13.jar" + +To distribute this project, zip up the dist folder (including the lib folder) +and distribute the ZIP file. + +Notes: + +* If two JAR files on the project classpath have the same name, only the first +JAR file is copied to the lib folder. +* Only JAR files are copied to the lib folder. +If the classpath contains other types of files or folders, these files (folders) +are not copied. +* If a library on the projects classpath also has a Class-Path element +specified in the manifest,the content of the Class-Path element has to be on +the projects runtime path. +* To set a main class in a standard Java project, right-click the project node +in the Projects window and choose Properties. Then click Run and enter the +class name in the Main Class field. Alternatively, you can manually type the +class name in the manifest Main-Class element. diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_13/dist/ff_13.jar b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_13/dist/ff_13.jar new file mode 100644 index 0000000..0c7789f Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_13/dist/ff_13.jar differ diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_13/manifest.mf b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_13/manifest.mf new file mode 100644 index 0000000..328e8e5 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_13/manifest.mf @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +X-COMMENT: Main-Class will be added automatically by build + diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_13/nbproject/build-impl.xml b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_13/nbproject/build-impl.xml new file mode 100644 index 0000000..7f31a97 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_13/nbproject/build-impl.xml @@ -0,0 +1,1041 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set src.dir + Must set test.src.dir + Must set build.dir + Must set dist.dir + Must set build.classes.dir + Must set dist.javadoc.dir + Must set build.test.classes.dir + Must set build.test.results.dir + Must set build.classes.excludes + Must set dist.jar + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set JVM to use for profiling in profiler.info.jvm + Must set profiler agent JVM arguments in profiler.info.jvmargs.agent + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + + + + + + java -cp "${run.classpath.with.dist.jar}" ${main.class} + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + java -jar "${dist.jar.resolved}" + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set run.class + + + + Must select one file in the IDE or set run.class + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set debug.class + + + + + Must select one file in the IDE or set debug.class + + + + + Must set fix.includes + + + + + + + + + + + + + + + + + Must select one file in the IDE or set profile.class + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + Some tests failed; see details above. + + + + + + + + + Must select some files in the IDE or set test.includes + + + + Some tests failed; see details above. + + + + + Must select one file in the IDE or set test.class + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_13/nbproject/genfiles.properties b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_13/nbproject/genfiles.properties new file mode 100644 index 0000000..7165226 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_13/nbproject/genfiles.properties @@ -0,0 +1,8 @@ +build.xml.data.CRC32=ebe68464 +build.xml.script.CRC32=60ea1cb2 +build.xml.stylesheet.CRC32=28e38971@1.43.1.45 +# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. +# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. +nbproject/build-impl.xml.data.CRC32=ebe68464 +nbproject/build-impl.xml.script.CRC32=03b6e257 +nbproject/build-impl.xml.stylesheet.CRC32=0c01fd8e@1.43.1.45 diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_13/nbproject/private/config.properties b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_13/nbproject/private/config.properties new file mode 100644 index 0000000..e69de29 diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_13/nbproject/private/private.properties b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_13/nbproject/private/private.properties new file mode 100644 index 0000000..a5ab360 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_13/nbproject/private/private.properties @@ -0,0 +1,6 @@ +compile.on.save=true +do.depend=false +do.jar=true +javac.debug=true +javadoc.preview=true +user.properties.file=C:\\Users\\Leo\\.netbeans\\7.0\\build.properties diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_13/nbproject/private/private.xml b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_13/nbproject/private/private.xml new file mode 100644 index 0000000..c1f155a --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_13/nbproject/private/private.xml @@ -0,0 +1,4 @@ + + + + diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_13/nbproject/project.properties b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_13/nbproject/project.properties new file mode 100644 index 0000000..9a25bb4 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_13/nbproject/project.properties @@ -0,0 +1,72 @@ +annotation.processing.enabled=true +annotation.processing.enabled.in.editor=false +annotation.processing.run.all.processors=true +annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output +application.title=ff_13 +application.vendor=Leo +build.classes.dir=${build.dir}/classes +build.classes.excludes=**/*.java,**/*.form +# This directory is removed when the project is cleaned: +build.dir=build +build.generated.dir=${build.dir}/generated +build.generated.sources.dir=${build.dir}/generated-sources +# Only compile against the classpath explicitly listed here: +build.sysclasspath=ignore +build.test.classes.dir=${build.dir}/test/classes +build.test.results.dir=${build.dir}/test/results +# Uncomment to specify the preferred debugger connection transport: +#debug.transport=dt_socket +debug.classpath=\ + ${run.classpath} +debug.test.classpath=\ + ${run.test.classpath} +# This directory is removed when the project is cleaned: +dist.dir=dist +dist.jar=${dist.dir}/ff_13.jar +dist.javadoc.dir=${dist.dir}/javadoc +endorsed.classpath= +excludes= +includes=** +jar.compress=false +javac.classpath= +# Space-separated list of extra javac options +javac.compilerargs= +javac.deprecation=false +javac.processorpath=\ + ${javac.classpath} +javac.source=1.7 +javac.target=1.7 +javac.test.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +javac.test.processorpath=\ + ${javac.test.classpath} +javadoc.additionalparam= +javadoc.author=false +javadoc.encoding=${source.encoding} +javadoc.noindex=false +javadoc.nonavbar=false +javadoc.notree=false +javadoc.private=false +javadoc.splitindex=true +javadoc.use=true +javadoc.version=false +javadoc.windowtitle= +main.class=ff_13.Main +manifest.file=manifest.mf +meta.inf.dir=${src.dir}/META-INF +mkdist.disabled=false +platform.active=default_platform +run.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +# Space-separated list of JVM arguments used when running the project +# (you may also define separate properties like run-sys-prop.name=value instead of -Dname=value +# or test-sys-prop.name=value to set system properties for unit tests): +run.jvmargs= +run.test.classpath=\ + ${javac.test.classpath}:\ + ${build.test.classes.dir} +source.encoding=UTF-8 +src.dir=src +test.src.dir=test diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_13/nbproject/project.xml b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_13/nbproject/project.xml new file mode 100644 index 0000000..3fead26 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_13/nbproject/project.xml @@ -0,0 +1,15 @@ + + + org.netbeans.modules.java.j2seproject + + + ff_13 + + + + + + + + + diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_13/src/ff_13/Main.java b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_13/src/ff_13/Main.java new file mode 100644 index 0000000..7c90300 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_13/src/ff_13/Main.java @@ -0,0 +1,90 @@ +package ff_13; + +import java.io.IOException; +import java.nio.file.DirectoryStream; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.nio.file.attribute.FileTime; +import java.util.concurrent.TimeUnit; +import static java.nio.file.LinkOption.NOFOLLOW_LINKS; + +/** + * + * @author Apress + */ +public class Main { + + public static void main(String[] args) { + + Path path = Paths.get("C:/rafaelnadal/tournaments/2009"); + + //no filter applyied + System.out.println("\nNo filter applyied:"); + try (DirectoryStream ds = Files.newDirectoryStream(path)) { + for (Path file : ds) { + System.out.println(file.getFileName()); + } + } catch (IOException e) { + System.err.println(e); + } + + //glob pattern applyied + System.out.println("\nGlob pattern applyied:"); + try (DirectoryStream ds = Files.newDirectoryStream(path, "*.{png,jpg,bmp}")) { + for (Path file : ds) { + System.out.println(file.getFileName()); + } + } catch (IOException e) { + System.err.println(e); + } + + //user defined filter - only files/directories larger than 200 Kb + DirectoryStream.Filter size_filter = new DirectoryStream.Filter() { + + public boolean accept(Path path) throws IOException { + return (Files.size(path) > 8192L); + } + }; + + //user defined filter - only directories are accepted + DirectoryStream.Filter dir_filter = new DirectoryStream.Filter() { + + public boolean accept(Path path) throws IOException { + return (Files.isDirectory(path, NOFOLLOW_LINKS)); + } + }; + + //user defined filter - only files modified in the current day + DirectoryStream.Filter time_filter = new DirectoryStream.Filter() { + + public boolean accept(Path path) throws IOException { + long currentTime = FileTime.fromMillis(System.currentTimeMillis()).to(TimeUnit.DAYS); + long modifiedTime = ((FileTime) Files.getAttribute(path, "basic:lastModifiedTime", NOFOLLOW_LINKS)).to(TimeUnit.DAYS); + if (currentTime == modifiedTime) { + return true; + } + + return false; + } + }; + + //user defined filter - only hidden files/directories + DirectoryStream.Filter hidden_filter = new DirectoryStream.Filter() { + + public boolean accept(Path path) throws IOException { + return (Files.isHidden(path)); + } + }; + + //user defined filter applyied + System.out.println("\nUser defined filter applyied:"); + try (DirectoryStream ds = Files.newDirectoryStream(path, dir_filter)) { + for (Path file : ds) { + System.out.println(file.getFileName()); + } + } catch (IOException e) { + System.err.println(e); + } + } +} diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_14/build.xml b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_14/build.xml new file mode 100644 index 0000000..bac62df --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_14/build.xml @@ -0,0 +1,74 @@ + + + + + + + + + + + Builds, tests, and runs the project ff_14. + + + diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_14/build/built-jar.properties b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_14/build/built-jar.properties new file mode 100644 index 0000000..3be0a29 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_14/build/built-jar.properties @@ -0,0 +1,4 @@ +#Mon, 17 Oct 2011 06:53:16 +0200 + + +C\:\\NIO\\filesandfolders\\ff_14= diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_14/build/classes/ff_14/Main.class b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_14/build/classes/ff_14/Main.class new file mode 100644 index 0000000..eb32562 Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_14/build/classes/ff_14/Main.class differ diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_14/dist/README.TXT b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_14/dist/README.TXT new file mode 100644 index 0000000..5a48add --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_14/dist/README.TXT @@ -0,0 +1,32 @@ +======================== +BUILD OUTPUT DESCRIPTION +======================== + +When you build an Java application project that has a main class, the IDE +automatically copies all of the JAR +files on the projects classpath to your projects dist/lib folder. The IDE +also adds each of the JAR files to the Class-Path element in the application +JAR files manifest file (MANIFEST.MF). + +To run the project from the command line, go to the dist folder and +type the following: + +java -jar "ff_14.jar" + +To distribute this project, zip up the dist folder (including the lib folder) +and distribute the ZIP file. + +Notes: + +* If two JAR files on the project classpath have the same name, only the first +JAR file is copied to the lib folder. +* Only JAR files are copied to the lib folder. +If the classpath contains other types of files or folders, these files (folders) +are not copied. +* If a library on the projects classpath also has a Class-Path element +specified in the manifest,the content of the Class-Path element has to be on +the projects runtime path. +* To set a main class in a standard Java project, right-click the project node +in the Projects window and choose Properties. Then click Run and enter the +class name in the Main Class field. Alternatively, you can manually type the +class name in the manifest Main-Class element. diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_14/dist/ff_14.jar b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_14/dist/ff_14.jar new file mode 100644 index 0000000..895458f Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_14/dist/ff_14.jar differ diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_14/manifest.mf b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_14/manifest.mf new file mode 100644 index 0000000..328e8e5 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_14/manifest.mf @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +X-COMMENT: Main-Class will be added automatically by build + diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_14/nbproject/build-impl.xml b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_14/nbproject/build-impl.xml new file mode 100644 index 0000000..87e7415 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_14/nbproject/build-impl.xml @@ -0,0 +1,1041 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set src.dir + Must set test.src.dir + Must set build.dir + Must set dist.dir + Must set build.classes.dir + Must set dist.javadoc.dir + Must set build.test.classes.dir + Must set build.test.results.dir + Must set build.classes.excludes + Must set dist.jar + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set JVM to use for profiling in profiler.info.jvm + Must set profiler agent JVM arguments in profiler.info.jvmargs.agent + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + + + + + + java -cp "${run.classpath.with.dist.jar}" ${main.class} + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + java -jar "${dist.jar.resolved}" + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set run.class + + + + Must select one file in the IDE or set run.class + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set debug.class + + + + + Must select one file in the IDE or set debug.class + + + + + Must set fix.includes + + + + + + + + + + + + + + + + + Must select one file in the IDE or set profile.class + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + Some tests failed; see details above. + + + + + + + + + Must select some files in the IDE or set test.includes + + + + Some tests failed; see details above. + + + + + Must select one file in the IDE or set test.class + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_14/nbproject/genfiles.properties b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_14/nbproject/genfiles.properties new file mode 100644 index 0000000..58c228c --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_14/nbproject/genfiles.properties @@ -0,0 +1,8 @@ +build.xml.data.CRC32=d39c2096 +build.xml.script.CRC32=fbffc5ed +build.xml.stylesheet.CRC32=28e38971@1.43.1.45 +# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. +# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. +nbproject/build-impl.xml.data.CRC32=d39c2096 +nbproject/build-impl.xml.script.CRC32=b3e923b4 +nbproject/build-impl.xml.stylesheet.CRC32=0c01fd8e@1.43.1.45 diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_14/nbproject/private/config.properties b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_14/nbproject/private/config.properties new file mode 100644 index 0000000..e69de29 diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_14/nbproject/private/private.properties b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_14/nbproject/private/private.properties new file mode 100644 index 0000000..a5ab360 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_14/nbproject/private/private.properties @@ -0,0 +1,6 @@ +compile.on.save=true +do.depend=false +do.jar=true +javac.debug=true +javadoc.preview=true +user.properties.file=C:\\Users\\Leo\\.netbeans\\7.0\\build.properties diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_14/nbproject/private/private.xml b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_14/nbproject/private/private.xml new file mode 100644 index 0000000..c1f155a --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_14/nbproject/private/private.xml @@ -0,0 +1,4 @@ + + + + diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_14/nbproject/project.properties b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_14/nbproject/project.properties new file mode 100644 index 0000000..3c60bf4 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_14/nbproject/project.properties @@ -0,0 +1,72 @@ +annotation.processing.enabled=true +annotation.processing.enabled.in.editor=false +annotation.processing.run.all.processors=true +annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output +application.title=ff_14 +application.vendor=Leo +build.classes.dir=${build.dir}/classes +build.classes.excludes=**/*.java,**/*.form +# This directory is removed when the project is cleaned: +build.dir=build +build.generated.dir=${build.dir}/generated +build.generated.sources.dir=${build.dir}/generated-sources +# Only compile against the classpath explicitly listed here: +build.sysclasspath=ignore +build.test.classes.dir=${build.dir}/test/classes +build.test.results.dir=${build.dir}/test/results +# Uncomment to specify the preferred debugger connection transport: +#debug.transport=dt_socket +debug.classpath=\ + ${run.classpath} +debug.test.classpath=\ + ${run.test.classpath} +# This directory is removed when the project is cleaned: +dist.dir=dist +dist.jar=${dist.dir}/ff_14.jar +dist.javadoc.dir=${dist.dir}/javadoc +endorsed.classpath= +excludes= +includes=** +jar.compress=false +javac.classpath= +# Space-separated list of extra javac options +javac.compilerargs= +javac.deprecation=false +javac.processorpath=\ + ${javac.classpath} +javac.source=1.7 +javac.target=1.7 +javac.test.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +javac.test.processorpath=\ + ${javac.test.classpath} +javadoc.additionalparam= +javadoc.author=false +javadoc.encoding=${source.encoding} +javadoc.noindex=false +javadoc.nonavbar=false +javadoc.notree=false +javadoc.private=false +javadoc.splitindex=true +javadoc.use=true +javadoc.version=false +javadoc.windowtitle= +main.class=ff_14.Main +manifest.file=manifest.mf +meta.inf.dir=${src.dir}/META-INF +mkdist.disabled=false +platform.active=default_platform +run.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +# Space-separated list of JVM arguments used when running the project +# (you may also define separate properties like run-sys-prop.name=value instead of -Dname=value +# or test-sys-prop.name=value to set system properties for unit tests): +run.jvmargs= +run.test.classpath=\ + ${javac.test.classpath}:\ + ${build.test.classes.dir} +source.encoding=UTF-8 +src.dir=src +test.src.dir=test diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_14/nbproject/project.xml b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_14/nbproject/project.xml new file mode 100644 index 0000000..c91de1d --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_14/nbproject/project.xml @@ -0,0 +1,15 @@ + + + org.netbeans.modules.java.j2seproject + + + ff_14 + + + + + + + + + diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_14/src/ff_14/Main.java b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_14/src/ff_14/Main.java new file mode 100644 index 0000000..84bc05b --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_14/src/ff_14/Main.java @@ -0,0 +1,154 @@ +package ff_14; + +import java.io.IOException; +import java.nio.charset.Charset; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.nio.file.StandardOpenOption; +import java.util.ArrayList; + +/** + * + * @author Apress + */ +public class Main { + + public static void main(String[] args) { + + Path rf_wiki_path = Paths.get("C:/rafaelnadal/wiki", "wiki.txt"); + Path ball_path = Paths.get("C:/rafaelnadal/photos", "ball.png"); + + String rf_wiki = "Rafael \"Rafa\" Nadal Parera (born 3 June 1986) is a Spanish professional tennis " + + "player and a former World No. 1. As of 29 August 2011 (2011 -08-29)[update], he is ranked No. 2 " + + "by the Association of Tennis Professionals (ATP). He is widely regarded as one of the greatest players " + + "of all time; his success on clay has earned him the nickname \"The King of Clay\", and has prompted " + + "many experts to regard him as the greatest clay court player of all time. Some of his best wins are:"; + + byte[] ball_bytes = new byte[]{ + (byte) 0x89, (byte) 0x50, (byte) 0x4e, (byte) 0x47, (byte) 0x0d, (byte) 0x0a, (byte) 0x1a, (byte) 0x0a, (byte) 0x00, + (byte) 0x00, (byte) 0x00, (byte) 0x0d, (byte) 0x49, (byte) 0x48, (byte) 0x44, (byte) 0x52, (byte) 0x00, (byte) 0x00, + (byte) 0x00, (byte) 0x10, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x10, (byte) 0x08, (byte) 0x02, (byte) 0x00, + (byte) 0x00, (byte) 0x00, (byte) 0x90, (byte) 0x91, (byte) 0x68, (byte) 0x36, (byte) 0x00, (byte) 0x00, (byte) 0x00, + (byte) 0x01, (byte) 0x73, (byte) 0x52, (byte) 0x47, (byte) 0x42, (byte) 0x00, (byte) 0xae, (byte) 0xce, (byte) 0x1c, + (byte) 0xe9, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x04, (byte) 0x67, (byte) 0x41, (byte) 0x4d, (byte) 0x41, + (byte) 0x00, (byte) 0x00, (byte) 0xb1, (byte) 0x8f, (byte) 0x0b, (byte) 0xfc, (byte) 0x61, (byte) 0x05, (byte) 0x00, + (byte) 0x00, (byte) 0x00, (byte) 0x09, (byte) 0x70, (byte) 0x48, (byte) 0x59, (byte) 0x73, (byte) 0x00, (byte) 0x00, + (byte) 0x0e, (byte) 0xc3, (byte) 0x00, (byte) 0x00, (byte) 0x0e, (byte) 0xc3, (byte) 0x01, (byte) 0xc7, (byte) 0x6f, + (byte) 0xa8, (byte) 0x64, (byte) 0x00, (byte) 0x00, (byte) 0x02, (byte) 0xe2, (byte) 0x49, (byte) 0x44, (byte) 0x41, + (byte) 0x54, (byte) 0x38, (byte) 0x4f, (byte) 0x63, (byte) 0x60, (byte) 0x40, (byte) 0x02, (byte) 0xb2, (byte) 0xb2, + (byte) 0xc2, (byte) 0x61, (byte) 0xe1, (byte) 0x66, (byte) 0xdd, (byte) 0xbd, (byte) 0x81, (byte) 0xbb, (byte) 0xf6, + (byte) 0x86, (byte) 0x6e, (byte) 0xdf, (byte) 0x6b, (byte) 0xdf, (byte) 0xd4, (byte) 0xa1, (byte) 0x11, (byte) 0x10, + (byte) 0xa4, (byte) 0x2d, (byte) 0x2b, (byte) 0x27, (byte) 0x84, (byte) 0xac, (byte) 0x06, (byte) 0xc1, (byte) 0x4e, + (byte) 0x4e, (byte) 0xf1, (byte) 0x3c, (byte) 0x77, (byte) 0x61, (byte) 0xe5, (byte) 0xd7, (byte) 0xef, (byte) 0x97, + (byte) 0x7f, (byte) 0xfd, (byte) 0x3a, (byte) 0xf3, (byte) 0xe9, (byte) 0xd3, (byte) 0xe1, (byte) 0x77, (byte) 0xef, + (byte) 0xf6, (byte) 0x3f, (byte) 0x7d, (byte) 0xd1, (byte) 0x74, (byte) 0xf1, (byte) 0xba, (byte) 0xd9, (byte) 0xde, + (byte) 0xa3, (byte) 0x71, (byte) 0xa9, (byte) 0x99, (byte) 0x56, (byte) 0xcc, (byte) 0xcc, (byte) 0x8c, (byte) 0x08, + (byte) 0xa5, (byte) 0x8c, (byte) 0x8c, (byte) 0x8c, (byte) 0x65, (byte) 0xe5, (byte) 0xd1, (byte) 0x3f, (byte) 0x7f, + (byte) 0x3d, (byte) 0xfb, (byte) 0xf5, (byte) 0xeb, (byte) 0xf9, (byte) 0xcf, (byte) 0xef, (byte) 0x27, (byte) 0xbe, + (byte) 0x7e, (byte) 0x99, (byte) 0xfb, (byte) 0xe6, (byte) 0x4d, (byte) 0xfd, (byte) 0x83, (byte) 0xc7, (byte) 0xc5, + (byte) 0x4f, (byte) 0x9e, (byte) 0xad, (byte) 0x7f, (byte) 0xf8, (byte) 0x78, (byte) 0xe5, (byte) 0xbe, (byte) 0x13, + (byte) 0x66, (byte) 0x87, (byte) 0x2f, (byte) 0xc4, (byte) 0x64, (byte) 0x15, (byte) 0x9a, (byte) 0xb3, (byte) 0xb0, + (byte) 0x32, (byte) 0x41, (byte) 0xf5, (byte) 0x84, (byte) 0x44, (byte) 0x18, (byte) 0x7d, (byte) 0xfb, (byte) 0xf6, + (byte) 0xe4, (byte) 0xd3, (byte) 0xe7, (byte) 0x5d, (byte) 0x3f, (byte) 0x7f, (byte) 0x02, (byte) 0xd1, (byte) 0x86, + (byte) 0x6f, (byte) 0x5f, (byte) 0x27, (byte) 0xbf, (byte) 0x7d, (byte) 0x53, (byte) 0x7e, (byte) 0xef, (byte) 0x61, + (byte) 0xc8, (byte) 0xd1, (byte) 0xb3, (byte) 0x0a, (byte) 0xb7, (byte) 0xee, (byte) 0x4e, (byte) 0xba, (byte) 0x74, + (byte) 0x7d, (byte) 0xc2, (byte) 0xb2, (byte) 0x2d, (byte) 0x1a, (byte) 0x5b, (byte) 0x0e, (byte) 0xfb, (byte) 0x45, + (byte) 0xc4, (byte) 0xab, (byte) 0x30, (byte) 0x01, (byte) 0xed, (byte) 0x11, (byte) 0x11, (byte) 0x63, (byte) 0x3d, + (byte) 0x7b, (byte) 0x71, (byte) 0xe5, (byte) 0xeb, (byte) 0xb7, (byte) 0xcb, (byte) 0x5f, (byte) 0xbf, (byte) 0x99, + (byte) 0xfc, (byte) 0xe9, (byte) 0xf3, (byte) 0xa2, (byte) 0x2f, (byte) 0x9f, (byte) 0x67, (byte) 0x7d, (byte) 0xfc, + (byte) 0xd0, (byte) 0xf6, (byte) 0xe2, (byte) 0x65, (byte) 0xce, (byte) 0xcd, (byte) 0x7b, (byte) 0x01, (byte) 0x27, + (byte) 0xce, (byte) 0x1a, (byte) 0x6c, (byte) 0xdb, (byte) 0x2b, (byte) 0x7b, (byte) 0xef, (byte) 0xe1, (byte) 0xf6, + (byte) 0x15, (byte) 0x5b, (byte) 0x1d, (byte) 0xe7, (byte) 0xae, (byte) 0xd5, (byte) 0x9f, (byte) 0xb3, (byte) 0xd2, + (byte) 0x4c, (byte) 0x45, (byte) 0x83, (byte) 0x9b, (byte) 0xc1, (byte) 0x3f, (byte) 0x4c, (byte) 0xf9, (byte) 0xd9, + (byte) 0x8b, (byte) 0x4d, (byte) 0x37, (byte) 0xee, (byte) 0x64, (byte) 0x3d, (byte) 0x7e, (byte) 0xda, (byte) 0xf0, + (byte) 0xfc, (byte) 0x65, (byte) 0xe3, (byte) 0xab, (byte) 0x57, (byte) 0xd5, (byte) 0xcf, (byte) 0x9e, (byte) 0xe7, + (byte) 0xde, (byte) 0xbd, (byte) 0x1f, (byte) 0x71, (byte) 0xee, (byte) 0x8a, (byte) 0xcd, (byte) 0xfe, (byte) 0xe3, + (byte) 0xda, (byte) 0xab, (byte) 0xb7, (byte) 0x89, (byte) 0x9e, (byte) 0xbf, (byte) 0xda, (byte) 0xbf, (byte) 0xf3, + (byte) 0x50, (byte) 0xf1, (byte) 0xc4, (byte) 0xc5, (byte) 0xf2, (byte) 0x8b, (byte) 0x37, (byte) 0x1a, (byte) 0xe5, + (byte) 0x94, (byte) 0x28, (byte) 0x30, (byte) 0x4c, (byte) 0x9e, (byte) 0x15, (byte) 0x7e, (byte) 0xf1, (byte) 0x6a, + (byte) 0xed, (byte) 0xd1, (byte) 0xb3, (byte) 0xde, (byte) 0x57, (byte) 0x6f, (byte) 0x26, (byte) 0xdd, (byte) 0xb8, + (byte) 0x93, (byte) 0x74, (byte) 0xf3, (byte) 0x4e, (byte) 0xec, (byte) 0xd5, (byte) 0x9b, (byte) 0x01, (byte) 0x67, + (byte) 0x2e, (byte) 0xd9, (byte) 0x1c, (byte) 0x38, (byte) 0xa1, (byte) 0xb3, (byte) 0x6d, (byte) 0xbf, (byte) 0xf6, + (byte) 0x92, (byte) 0x0d, (byte) 0x52, (byte) 0x87, (byte) 0xcf, (byte) 0xd4, (byte) 0xed, (byte) 0x3e, (byte) 0x5c, + (byte) 0x37, (byte) 0x61, (byte) 0x91, (byte) 0xdc, (byte) 0xb2, (byte) 0xcd, (byte) 0x06, (byte) 0xb3, (byte) 0x97, + (byte) 0x6a, (byte) 0x32, (byte) 0xac, (byte) 0xdd, (byte) 0x5a, (byte) 0xb5, (byte) 0xfd, (byte) 0x40, (byte) 0xe0, + (byte) 0xf6, (byte) 0x83, (byte) 0x16, (byte) 0x07, (byte) 0x4f, (byte) 0xb9, (byte) 0x1c, (byte) 0x3d, (byte) 0xe3, + (byte) 0x7c, (byte) 0xf4, (byte) 0x8c, (byte) 0xdd, (byte) 0xc1, (byte) 0x93, (byte) 0xa6, (byte) 0x7b, (byte) 0x8e, + (byte) 0xe8, (byte) 0x6e, (byte) 0xdd, (byte) 0xa7, (byte) 0xb3, (byte) 0x76, (byte) 0xbb, (byte) 0xce, (byte) 0xac, + (byte) 0x95, (byte) 0x92, (byte) 0x87, (byte) 0xcf, (byte) 0x76, (byte) 0xef, (byte) 0x3c, (byte) 0x54, (byte) 0x31, + (byte) 0x65, (byte) 0x89, (byte) 0xfc, (byte) 0xea, (byte) 0xed, (byte) 0x46, (byte) 0x1b, (byte) 0x76, (byte) 0xa8, + (byte) 0x33, (byte) 0xac, (byte) 0xda, (byte) 0xd4, (byte) 0x34, (byte) 0x73, (byte) 0xa5, (byte) 0xde, (byte) 0x9a, + (byte) 0x1d, (byte) 0x56, (byte) 0x9b, (byte) 0xf7, (byte) 0x5a, (byte) 0x6e, (byte) 0xd9, (byte) 0x67, (byte) 0xb6, + (byte) 0x65, (byte) 0xaf, (byte) 0xf1, (byte) 0xe6, (byte) 0x3d, (byte) 0x86, (byte) 0x1b, (byte) 0x76, (byte) 0x19, + (byte) 0xac, (byte) 0xdc, (byte) 0xa2, (byte) 0xb7, (byte) 0x70, (byte) 0xa3, (byte) 0xde, (byte) 0xc4, (byte) 0xc5, + (byte) 0x32, (byte) 0xe7, (byte) 0xaf, (byte) 0xae, (byte) 0x58, (byte) 0xb9, (byte) 0x2d, (byte) 0x68, (byte) 0xfe, + (byte) 0x5a, (byte) 0xd5, (byte) 0x6d, (byte) 0xfb, (byte) 0x0d, (byte) 0x76, (byte) 0xee, (byte) 0x97, (byte) 0x67, + (byte) 0xa8, (byte) 0xa8, (byte) 0x8d, (byte) 0xea, (byte) 0x9a, (byte) 0xa3, (byte) 0x34, (byte) 0x67, (byte) 0x95, + (byte) 0xc1, (byte) 0xd2, (byte) 0x4d, (byte) 0xd6, (byte) 0x2b, (byte) 0x36, (byte) 0x5b, (byte) 0x2c, (byte) 0xdf, + (byte) 0x62, (byte) 0xba, (byte) 0x6c, (byte) 0x93, (byte) 0xd1, (byte) 0xc2, (byte) 0xf5, (byte) 0x06, (byte) 0x73, + (byte) 0xd7, (byte) 0x1a, (byte) 0x4e, (byte) 0x5a, (byte) 0x0c, (byte) 0x74, (byte) 0x46, (byte) 0xc0, (byte) 0xf5, + (byte) 0xdb, (byte) 0x9b, (byte) 0xe7, (byte) 0xac, (byte) 0x52, (byte) 0x5c, (byte) 0xbb, (byte) 0xc3, (byte) 0xf0, + (byte) 0xe8, (byte) 0x69, (byte) 0xd5, (byte) 0xf9, (byte) 0x4b, (byte) 0xa5, (byte) 0x18, (byte) 0x0c, (byte) 0x4c, + (byte) 0x84, (byte) 0xa6, (byte) 0x2e, (byte) 0xd5, (byte) 0x9c, (byte) 0xb6, (byte) 0x5c, (byte) 0x77, (byte) 0xfa, + (byte) 0x72, (byte) 0xfd, (byte) 0x99, (byte) 0x2b, (byte) 0x8d, (byte) 0x66, (byte) 0xae, (byte) 0x34, (byte) 0x9c, + (byte) 0xb9, (byte) 0xca, (byte) 0x70, (byte) 0xe6, (byte) 0x0a, (byte) 0xa3, (byte) 0x49, (byte) 0x4b, (byte) 0x94, + (byte) 0xa6, (byte) 0x2d, (byte) 0xd3, (byte) 0xba, (byte) 0x75, (byte) 0x77, (byte) 0xff, (byte) 0xfa, (byte) 0x5d, + (byte) 0xbe, (byte) 0x2b, (byte) 0xb7, (byte) 0xaa, (byte) 0xec, (byte) 0x3b, (byte) 0xae, (byte) 0x79, (byte) 0xed, + (byte) 0x96, (byte) 0x6c, (byte) 0x46, (byte) 0x9e, (byte) 0x38, (byte) 0x03, (byte) 0x27, (byte) 0x17, (byte) 0x73, + (byte) 0x4d, (byte) 0x9b, (byte) 0xf2, (byte) 0xe2, (byte) 0x8d, (byte) 0x06, (byte) 0xb3, (byte) 0x56, (byte) 0xea, + (byte) 0xcf, (byte) 0x5a, (byte) 0xa5, (byte) 0x0f, (byte) 0x22, (byte) 0x57, (byte) 0x1b, (byte) 0x4e, (byte) 0x5f, + (byte) 0xa1, (byte) 0x38, (byte) 0x77, (byte) 0x8d, (byte) 0xde, (byte) 0xed, (byte) 0xfb, (byte) 0x07, (byte) 0xf6, + (byte) 0x1e, (byte) 0xcf, (byte) 0x5c, (byte) 0xb3, (byte) 0x43, (byte) 0xf2, (byte) 0xf0, (byte) 0x29, (byte) 0xf5, + (byte) 0x6b, (byte) 0xb7, (byte) 0xe4, (byte) 0xb6, (byte) 0xee, (byte) 0x92, (byte) 0xe3, (byte) 0xe3, (byte) 0x67, + (byte) 0x06, (byte) 0xc5, (byte) 0x9d, (byte) 0x8a, (byte) 0x06, (byte) 0xd7, (byte) 0x86, (byte) 0x3d, (byte) 0xfa, + (byte) 0x5b, (byte) 0x0f, (byte) 0x1a, (byte) 0x03, (byte) 0x1d, (byte) 0xb3, (byte) 0x7c, (byte) 0xb3, (byte) 0xc9, + (byte) 0xd2, (byte) 0x8d, (byte) 0xea, (byte) 0x6b, (byte) 0x76, (byte) 0x58, (byte) 0xdf, (byte) 0x7b, (byte) 0x74, + (byte) 0xf0, (byte) 0xc4, (byte) 0xd9, (byte) 0xf4, (byte) 0xad, (byte) 0xfb, (byte) 0x84, (byte) 0x4f, (byte) 0x9c, + (byte) 0x53, (byte) 0xbc, (byte) 0x7c, (byte) 0x43, (byte) 0xfe, (byte) 0xee, (byte) 0x63, (byte) 0x15, (byte) 0x39, + (byte) 0x05, (byte) 0x36, (byte) 0x44, (byte) 0xea, (byte) 0x90, (byte) 0x94, (byte) 0x62, (byte) 0xdb, (byte) 0xb0, + (byte) 0x43, (byte) 0xe5, (byte) 0xc6, (byte) 0x7d, (byte) 0xdd, (byte) 0x23, (byte) 0x67, (byte) 0xd5, (byte) 0xf6, + (byte) 0x1c, (byte) 0x56, (byte) 0x79, (byte) 0xf8, (byte) 0x64, (byte) 0xdb, (byte) 0xf9, (byte) 0x4b, (byte) 0x81, + (byte) 0x07, (byte) 0x4f, (byte) 0x70, (byte) 0x5f, (byte) 0xbe, (byte) 0xa1, (byte) 0xf8, (byte) 0xf0, (byte) 0xa9, + (byte) 0xd2, (byte) 0xb9, (byte) 0xcb, (byte) 0xca, (byte) 0x1a, (byte) 0x5a, (byte) 0x1c, (byte) 0xe8, (byte) 0x49, + (byte) 0x90, (byte) 0x8d, (byte) 0x9d, (byte) 0x31, (byte) 0x3a, (byte) 0x8e, (byte) 0x6f, (byte) 0xe7, (byte) 0x01, + (byte) 0xee, (byte) 0x77, (byte) 0x1f, (byte) 0x32, (byte) 0x7e, (byte) 0xfe, (byte) 0x5a, (byte) 0x74, (byte) 0xf7, + (byte) 0x09, (byte) 0xef, (byte) 0xa3, (byte) 0x17, (byte) 0x6a, (byte) 0x97, (byte) 0x6f, (byte) 0x2a, (byte) 0x97, + (byte) 0x54, (byte) 0x88, (byte) 0x08, (byte) 0x8b, (byte) 0xb0, (byte) 0x60, (byte) 0x4f, (byte) 0xb0, (byte) 0x40, + (byte) 0x51, (byte) 0x31, (byte) 0x09, (byte) 0x66, (byte) 0x49, (byte) 0x29, (byte) 0x7e, (byte) 0x7d, (byte) 0x03, + (byte) 0x71, (byte) 0x03, (byte) 0x63, (byte) 0x36, (byte) 0x05, (byte) 0x25, (byte) 0x76, (byte) 0x6e, (byte) 0x1e, + (byte) 0x58, (byte) 0x82, (byte) 0x83, (byte) 0xe9, (byte) 0x00, (byte) 0x00, (byte) 0x4e, (byte) 0xe0, (byte) 0x60, + (byte) 0xcf, (byte) 0x75, (byte) 0xfc, (byte) 0x90, (byte) 0x67, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, + (byte) 0x49, (byte) 0x45, (byte) 0x4e, (byte) 0x44, (byte) 0xae, (byte) 0x42, (byte) 0x60, (byte) 0x82 + }; + + try { + Files.write(ball_path, ball_bytes); + } catch (IOException e) { + System.err.println(e); + } + + try { + byte[] rf_wiki_byte = rf_wiki.getBytes("UTF-8"); + Files.write(rf_wiki_path, rf_wiki_byte); + } catch (IOException e) { + System.err.println(e); + } + + Charset charset = Charset.forName("UTF-8"); + ArrayList lines = new ArrayList<>(); + lines.add("\n"); + lines.add("Rome Masters - 5 titles in 6 years"); + lines.add("Monte Carlo Masters - 7 consecutive titles (2005-2011)"); + lines.add("Australian Open - Winner 2009"); + lines.add("Roland Garros - Winnner 2005-2008, 2010, 2011"); + lines.add("Wimbledon - Winner 2008, 2010"); + lines.add("US Open - Winner 2010"); + + try { + Files.write(rf_wiki_path, lines, charset, StandardOpenOption.APPEND); + } catch (IOException e) { + System.err.println(e); + } + } +} diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_15/build.xml b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_15/build.xml new file mode 100644 index 0000000..9f1b405 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_15/build.xml @@ -0,0 +1,74 @@ + + + + + + + + + + + Builds, tests, and runs the project ff_15. + + + diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_15/build/built-jar.properties b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_15/build/built-jar.properties new file mode 100644 index 0000000..699062d --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_15/build/built-jar.properties @@ -0,0 +1,4 @@ +#Mon, 17 Oct 2011 06:55:38 +0200 + + +C\:\\NIO\\filesandfolders\\ff_15= diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_15/build/classes/.netbeans_automatic_build b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_15/build/classes/.netbeans_automatic_build new file mode 100644 index 0000000..e69de29 diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_15/build/classes/ff_15/Main.class b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_15/build/classes/ff_15/Main.class new file mode 100644 index 0000000..6153dc4 Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_15/build/classes/ff_15/Main.class differ diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_15/dist/README.TXT b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_15/dist/README.TXT new file mode 100644 index 0000000..9e9f678 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_15/dist/README.TXT @@ -0,0 +1,32 @@ +======================== +BUILD OUTPUT DESCRIPTION +======================== + +When you build an Java application project that has a main class, the IDE +automatically copies all of the JAR +files on the projects classpath to your projects dist/lib folder. The IDE +also adds each of the JAR files to the Class-Path element in the application +JAR files manifest file (MANIFEST.MF). + +To run the project from the command line, go to the dist folder and +type the following: + +java -jar "ff_15.jar" + +To distribute this project, zip up the dist folder (including the lib folder) +and distribute the ZIP file. + +Notes: + +* If two JAR files on the project classpath have the same name, only the first +JAR file is copied to the lib folder. +* Only JAR files are copied to the lib folder. +If the classpath contains other types of files or folders, these files (folders) +are not copied. +* If a library on the projects classpath also has a Class-Path element +specified in the manifest,the content of the Class-Path element has to be on +the projects runtime path. +* To set a main class in a standard Java project, right-click the project node +in the Projects window and choose Properties. Then click Run and enter the +class name in the Main Class field. Alternatively, you can manually type the +class name in the manifest Main-Class element. diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_15/dist/ff_15.jar b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_15/dist/ff_15.jar new file mode 100644 index 0000000..3b5a66a Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_15/dist/ff_15.jar differ diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_15/manifest.mf b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_15/manifest.mf new file mode 100644 index 0000000..328e8e5 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_15/manifest.mf @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +X-COMMENT: Main-Class will be added automatically by build + diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_15/nbproject/build-impl.xml b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_15/nbproject/build-impl.xml new file mode 100644 index 0000000..4308134 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_15/nbproject/build-impl.xml @@ -0,0 +1,1041 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set src.dir + Must set test.src.dir + Must set build.dir + Must set dist.dir + Must set build.classes.dir + Must set dist.javadoc.dir + Must set build.test.classes.dir + Must set build.test.results.dir + Must set build.classes.excludes + Must set dist.jar + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set JVM to use for profiling in profiler.info.jvm + Must set profiler agent JVM arguments in profiler.info.jvmargs.agent + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + + + + + + java -cp "${run.classpath.with.dist.jar}" ${main.class} + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + java -jar "${dist.jar.resolved}" + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set run.class + + + + Must select one file in the IDE or set run.class + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set debug.class + + + + + Must select one file in the IDE or set debug.class + + + + + Must set fix.includes + + + + + + + + + + + + + + + + + Must select one file in the IDE or set profile.class + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + Some tests failed; see details above. + + + + + + + + + Must select some files in the IDE or set test.includes + + + + Some tests failed; see details above. + + + + + Must select one file in the IDE or set test.class + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_15/nbproject/genfiles.properties b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_15/nbproject/genfiles.properties new file mode 100644 index 0000000..8a6da1e --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_15/nbproject/genfiles.properties @@ -0,0 +1,8 @@ +build.xml.data.CRC32=db8facb0 +build.xml.script.CRC32=07133569 +build.xml.stylesheet.CRC32=28e38971@1.43.1.45 +# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. +# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. +nbproject/build-impl.xml.data.CRC32=db8facb0 +nbproject/build-impl.xml.script.CRC32=0460d7cf +nbproject/build-impl.xml.stylesheet.CRC32=0c01fd8e@1.43.1.45 diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_15/nbproject/private/config.properties b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_15/nbproject/private/config.properties new file mode 100644 index 0000000..e69de29 diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_15/nbproject/private/private.properties b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_15/nbproject/private/private.properties new file mode 100644 index 0000000..a5ab360 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_15/nbproject/private/private.properties @@ -0,0 +1,6 @@ +compile.on.save=true +do.depend=false +do.jar=true +javac.debug=true +javadoc.preview=true +user.properties.file=C:\\Users\\Leo\\.netbeans\\7.0\\build.properties diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_15/nbproject/private/private.xml b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_15/nbproject/private/private.xml new file mode 100644 index 0000000..c1f155a --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_15/nbproject/private/private.xml @@ -0,0 +1,4 @@ + + + + diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_15/nbproject/project.properties b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_15/nbproject/project.properties new file mode 100644 index 0000000..58ef096 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_15/nbproject/project.properties @@ -0,0 +1,72 @@ +annotation.processing.enabled=true +annotation.processing.enabled.in.editor=false +annotation.processing.run.all.processors=true +annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output +application.title=ff_15 +application.vendor=Leo +build.classes.dir=${build.dir}/classes +build.classes.excludes=**/*.java,**/*.form +# This directory is removed when the project is cleaned: +build.dir=build +build.generated.dir=${build.dir}/generated +build.generated.sources.dir=${build.dir}/generated-sources +# Only compile against the classpath explicitly listed here: +build.sysclasspath=ignore +build.test.classes.dir=${build.dir}/test/classes +build.test.results.dir=${build.dir}/test/results +# Uncomment to specify the preferred debugger connection transport: +#debug.transport=dt_socket +debug.classpath=\ + ${run.classpath} +debug.test.classpath=\ + ${run.test.classpath} +# This directory is removed when the project is cleaned: +dist.dir=dist +dist.jar=${dist.dir}/ff_15.jar +dist.javadoc.dir=${dist.dir}/javadoc +endorsed.classpath= +excludes= +includes=** +jar.compress=false +javac.classpath= +# Space-separated list of extra javac options +javac.compilerargs= +javac.deprecation=false +javac.processorpath=\ + ${javac.classpath} +javac.source=1.7 +javac.target=1.7 +javac.test.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +javac.test.processorpath=\ + ${javac.test.classpath} +javadoc.additionalparam= +javadoc.author=false +javadoc.encoding=${source.encoding} +javadoc.noindex=false +javadoc.nonavbar=false +javadoc.notree=false +javadoc.private=false +javadoc.splitindex=true +javadoc.use=true +javadoc.version=false +javadoc.windowtitle= +main.class=ff_15.Main +manifest.file=manifest.mf +meta.inf.dir=${src.dir}/META-INF +mkdist.disabled=false +platform.active=default_platform +run.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +# Space-separated list of JVM arguments used when running the project +# (you may also define separate properties like run-sys-prop.name=value instead of -Dname=value +# or test-sys-prop.name=value to set system properties for unit tests): +run.jvmargs= +run.test.classpath=\ + ${javac.test.classpath}:\ + ${build.test.classes.dir} +source.encoding=UTF-8 +src.dir=src +test.src.dir=test diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_15/nbproject/project.xml b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_15/nbproject/project.xml new file mode 100644 index 0000000..dcfc9fe --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_15/nbproject/project.xml @@ -0,0 +1,15 @@ + + + org.netbeans.modules.java.j2seproject + + + ff_15 + + + + + + + + + diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_15/src/ff_15/Main.java b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_15/src/ff_15/Main.java new file mode 100644 index 0000000..4fd5a3a --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_15/src/ff_15/Main.java @@ -0,0 +1,30 @@ +package ff_15; + +import java.io.BufferedReader; +import java.io.IOException; +import java.nio.charset.Charset; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; + +/** + * + * @author Apress + */ +public class Main { + + public static void main(String[] args) { + + Path wiki_path = Paths.get("C:/rafaelnadal/wiki", "wiki.txt"); + + Charset charset = Charset.forName("UTF-8"); + try (BufferedReader reader = Files.newBufferedReader(wiki_path, charset)) { + String line = null; + while ((line = reader.readLine()) != null) { + System.out.println(line); + } + } catch (IOException e) { + System.err.println(e); + } + } +} diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_16/build.xml b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_16/build.xml new file mode 100644 index 0000000..a8508ce --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_16/build.xml @@ -0,0 +1,74 @@ + + + + + + + + + + + Builds, tests, and runs the project ff_16. + + + diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_16/build/built-jar.properties b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_16/build/built-jar.properties new file mode 100644 index 0000000..68879be --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_16/build/built-jar.properties @@ -0,0 +1,4 @@ +#Mon, 17 Oct 2011 06:56:28 +0200 + + +C\:\\NIO\\filesandfolders\\ff_16= diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_16/build/classes/ff_16/Main.class b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_16/build/classes/ff_16/Main.class new file mode 100644 index 0000000..f8fcac9 Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_16/build/classes/ff_16/Main.class differ diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_16/dist/README.TXT b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_16/dist/README.TXT new file mode 100644 index 0000000..23c95e0 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_16/dist/README.TXT @@ -0,0 +1,32 @@ +======================== +BUILD OUTPUT DESCRIPTION +======================== + +When you build an Java application project that has a main class, the IDE +automatically copies all of the JAR +files on the projects classpath to your projects dist/lib folder. The IDE +also adds each of the JAR files to the Class-Path element in the application +JAR files manifest file (MANIFEST.MF). + +To run the project from the command line, go to the dist folder and +type the following: + +java -jar "ff_16.jar" + +To distribute this project, zip up the dist folder (including the lib folder) +and distribute the ZIP file. + +Notes: + +* If two JAR files on the project classpath have the same name, only the first +JAR file is copied to the lib folder. +* Only JAR files are copied to the lib folder. +If the classpath contains other types of files or folders, these files (folders) +are not copied. +* If a library on the projects classpath also has a Class-Path element +specified in the manifest,the content of the Class-Path element has to be on +the projects runtime path. +* To set a main class in a standard Java project, right-click the project node +in the Projects window and choose Properties. Then click Run and enter the +class name in the Main Class field. Alternatively, you can manually type the +class name in the manifest Main-Class element. diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_16/dist/ff_16.jar b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_16/dist/ff_16.jar new file mode 100644 index 0000000..641b139 Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_16/dist/ff_16.jar differ diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_16/manifest.mf b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_16/manifest.mf new file mode 100644 index 0000000..328e8e5 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_16/manifest.mf @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +X-COMMENT: Main-Class will be added automatically by build + diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_16/nbproject/build-impl.xml b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_16/nbproject/build-impl.xml new file mode 100644 index 0000000..2bbc42c --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_16/nbproject/build-impl.xml @@ -0,0 +1,1041 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set src.dir + Must set test.src.dir + Must set build.dir + Must set dist.dir + Must set build.classes.dir + Must set dist.javadoc.dir + Must set build.test.classes.dir + Must set build.test.results.dir + Must set build.classes.excludes + Must set dist.jar + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set JVM to use for profiling in profiler.info.jvm + Must set profiler agent JVM arguments in profiler.info.jvmargs.agent + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + + + + + + java -cp "${run.classpath.with.dist.jar}" ${main.class} + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + java -jar "${dist.jar.resolved}" + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set run.class + + + + Must select one file in the IDE or set run.class + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set debug.class + + + + + Must select one file in the IDE or set debug.class + + + + + Must set fix.includes + + + + + + + + + + + + + + + + + Must select one file in the IDE or set profile.class + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + Some tests failed; see details above. + + + + + + + + + Must select some files in the IDE or set test.includes + + + + Some tests failed; see details above. + + + + + Must select one file in the IDE or set test.class + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_16/nbproject/genfiles.properties b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_16/nbproject/genfiles.properties new file mode 100644 index 0000000..60bb2b8 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_16/nbproject/genfiles.properties @@ -0,0 +1,8 @@ +build.xml.data.CRC32=c3bb38da +build.xml.script.CRC32=d95722a4 +build.xml.stylesheet.CRC32=28e38971@1.43.1.45 +# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. +# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. +nbproject/build-impl.xml.data.CRC32=c3bb38da +nbproject/build-impl.xml.script.CRC32=078bcd03 +nbproject/build-impl.xml.stylesheet.CRC32=0c01fd8e@1.43.1.45 diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_16/nbproject/private/config.properties b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_16/nbproject/private/config.properties new file mode 100644 index 0000000..e69de29 diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_16/nbproject/private/private.properties b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_16/nbproject/private/private.properties new file mode 100644 index 0000000..a5ab360 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_16/nbproject/private/private.properties @@ -0,0 +1,6 @@ +compile.on.save=true +do.depend=false +do.jar=true +javac.debug=true +javadoc.preview=true +user.properties.file=C:\\Users\\Leo\\.netbeans\\7.0\\build.properties diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_16/nbproject/private/private.xml b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_16/nbproject/private/private.xml new file mode 100644 index 0000000..c1f155a --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_16/nbproject/private/private.xml @@ -0,0 +1,4 @@ + + + + diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_16/nbproject/project.properties b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_16/nbproject/project.properties new file mode 100644 index 0000000..60bf39b --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_16/nbproject/project.properties @@ -0,0 +1,72 @@ +annotation.processing.enabled=true +annotation.processing.enabled.in.editor=false +annotation.processing.run.all.processors=true +annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output +application.title=ff_16 +application.vendor=Leo +build.classes.dir=${build.dir}/classes +build.classes.excludes=**/*.java,**/*.form +# This directory is removed when the project is cleaned: +build.dir=build +build.generated.dir=${build.dir}/generated +build.generated.sources.dir=${build.dir}/generated-sources +# Only compile against the classpath explicitly listed here: +build.sysclasspath=ignore +build.test.classes.dir=${build.dir}/test/classes +build.test.results.dir=${build.dir}/test/results +# Uncomment to specify the preferred debugger connection transport: +#debug.transport=dt_socket +debug.classpath=\ + ${run.classpath} +debug.test.classpath=\ + ${run.test.classpath} +# This directory is removed when the project is cleaned: +dist.dir=dist +dist.jar=${dist.dir}/ff_16.jar +dist.javadoc.dir=${dist.dir}/javadoc +endorsed.classpath= +excludes= +includes=** +jar.compress=false +javac.classpath= +# Space-separated list of extra javac options +javac.compilerargs= +javac.deprecation=false +javac.processorpath=\ + ${javac.classpath} +javac.source=1.7 +javac.target=1.7 +javac.test.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +javac.test.processorpath=\ + ${javac.test.classpath} +javadoc.additionalparam= +javadoc.author=false +javadoc.encoding=${source.encoding} +javadoc.noindex=false +javadoc.nonavbar=false +javadoc.notree=false +javadoc.private=false +javadoc.splitindex=true +javadoc.use=true +javadoc.version=false +javadoc.windowtitle= +main.class=ff_16.Main +manifest.file=manifest.mf +meta.inf.dir=${src.dir}/META-INF +mkdist.disabled=false +platform.active=default_platform +run.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +# Space-separated list of JVM arguments used when running the project +# (you may also define separate properties like run-sys-prop.name=value instead of -Dname=value +# or test-sys-prop.name=value to set system properties for unit tests): +run.jvmargs= +run.test.classpath=\ + ${javac.test.classpath}:\ + ${build.test.classes.dir} +source.encoding=UTF-8 +src.dir=src +test.src.dir=test diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_16/nbproject/project.xml b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_16/nbproject/project.xml new file mode 100644 index 0000000..836470d --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_16/nbproject/project.xml @@ -0,0 +1,15 @@ + + + org.netbeans.modules.java.j2seproject + + + ff_16 + + + + + + + + + diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_16/src/ff_16/Main.java b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_16/src/ff_16/Main.java new file mode 100644 index 0000000..b4e7f23 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_16/src/ff_16/Main.java @@ -0,0 +1,29 @@ +package ff_16; + +import java.io.BufferedWriter; +import java.io.IOException; +import java.nio.charset.Charset; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.nio.file.StandardOpenOption; + +/** + * + * @author Apress + */ +public class Main { + + public static void main(String[] args) { + + Path wiki_path = Paths.get("C:/rafaelnadal/wiki", "wiki.txt"); + + Charset charset = Charset.forName("UTF-8"); + String text = "\nVamos Rafa!"; + try (BufferedWriter writer = Files.newBufferedWriter(wiki_path, charset, StandardOpenOption.APPEND)) { + writer.write(text); + } catch (IOException e) { + System.err.println(e); + } + } +} diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_17/build.xml b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_17/build.xml new file mode 100644 index 0000000..7397c43 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_17/build.xml @@ -0,0 +1,74 @@ + + + + + + + + + + + Builds, tests, and runs the project ff_17. + + + diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_17/build/built-jar.properties b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_17/build/built-jar.properties new file mode 100644 index 0000000..2bc9b0d --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_17/build/built-jar.properties @@ -0,0 +1,4 @@ +#Mon, 17 Oct 2011 07:00:29 +0200 + + +C\:\\NIO\\filesandfolders\\ff_17= diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_17/build/classes/.netbeans_automatic_build b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_17/build/classes/.netbeans_automatic_build new file mode 100644 index 0000000..e69de29 diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_17/build/classes/ff_17/Main.class b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_17/build/classes/ff_17/Main.class new file mode 100644 index 0000000..6370829 Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_17/build/classes/ff_17/Main.class differ diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_17/dist/README.TXT b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_17/dist/README.TXT new file mode 100644 index 0000000..65bc828 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_17/dist/README.TXT @@ -0,0 +1,32 @@ +======================== +BUILD OUTPUT DESCRIPTION +======================== + +When you build an Java application project that has a main class, the IDE +automatically copies all of the JAR +files on the projects classpath to your projects dist/lib folder. The IDE +also adds each of the JAR files to the Class-Path element in the application +JAR files manifest file (MANIFEST.MF). + +To run the project from the command line, go to the dist folder and +type the following: + +java -jar "ff_17.jar" + +To distribute this project, zip up the dist folder (including the lib folder) +and distribute the ZIP file. + +Notes: + +* If two JAR files on the project classpath have the same name, only the first +JAR file is copied to the lib folder. +* Only JAR files are copied to the lib folder. +If the classpath contains other types of files or folders, these files (folders) +are not copied. +* If a library on the projects classpath also has a Class-Path element +specified in the manifest,the content of the Class-Path element has to be on +the projects runtime path. +* To set a main class in a standard Java project, right-click the project node +in the Projects window and choose Properties. Then click Run and enter the +class name in the Main Class field. Alternatively, you can manually type the +class name in the manifest Main-Class element. diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_17/dist/ff_17.jar b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_17/dist/ff_17.jar new file mode 100644 index 0000000..42a2cc4 Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_17/dist/ff_17.jar differ diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_17/manifest.mf b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_17/manifest.mf new file mode 100644 index 0000000..328e8e5 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_17/manifest.mf @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +X-COMMENT: Main-Class will be added automatically by build + diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_17/nbproject/build-impl.xml b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_17/nbproject/build-impl.xml new file mode 100644 index 0000000..f7dcb7a --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_17/nbproject/build-impl.xml @@ -0,0 +1,1041 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set src.dir + Must set test.src.dir + Must set build.dir + Must set dist.dir + Must set build.classes.dir + Must set dist.javadoc.dir + Must set build.test.classes.dir + Must set build.test.results.dir + Must set build.classes.excludes + Must set dist.jar + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set JVM to use for profiling in profiler.info.jvm + Must set profiler agent JVM arguments in profiler.info.jvmargs.agent + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + + + + + + java -cp "${run.classpath.with.dist.jar}" ${main.class} + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + java -jar "${dist.jar.resolved}" + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set run.class + + + + Must select one file in the IDE or set run.class + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set debug.class + + + + + Must select one file in the IDE or set debug.class + + + + + Must set fix.includes + + + + + + + + + + + + + + + + + Must select one file in the IDE or set profile.class + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + Some tests failed; see details above. + + + + + + + + + Must select some files in the IDE or set test.includes + + + + Some tests failed; see details above. + + + + + Must select one file in the IDE or set test.class + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_17/nbproject/genfiles.properties b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_17/nbproject/genfiles.properties new file mode 100644 index 0000000..333ac5d --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_17/nbproject/genfiles.properties @@ -0,0 +1,8 @@ +build.xml.data.CRC32=cba8b4fc +build.xml.script.CRC32=25bbd220 +build.xml.stylesheet.CRC32=28e38971@1.43.1.45 +# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. +# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. +nbproject/build-impl.xml.data.CRC32=cba8b4fc +nbproject/build-impl.xml.script.CRC32=b0023978 +nbproject/build-impl.xml.stylesheet.CRC32=0c01fd8e@1.43.1.45 diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_17/nbproject/private/config.properties b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_17/nbproject/private/config.properties new file mode 100644 index 0000000..e69de29 diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_17/nbproject/private/private.properties b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_17/nbproject/private/private.properties new file mode 100644 index 0000000..a5ab360 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_17/nbproject/private/private.properties @@ -0,0 +1,6 @@ +compile.on.save=true +do.depend=false +do.jar=true +javac.debug=true +javadoc.preview=true +user.properties.file=C:\\Users\\Leo\\.netbeans\\7.0\\build.properties diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_17/nbproject/private/private.xml b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_17/nbproject/private/private.xml new file mode 100644 index 0000000..c1f155a --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_17/nbproject/private/private.xml @@ -0,0 +1,4 @@ + + + + diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_17/nbproject/project.properties b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_17/nbproject/project.properties new file mode 100644 index 0000000..7dea623 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_17/nbproject/project.properties @@ -0,0 +1,72 @@ +annotation.processing.enabled=true +annotation.processing.enabled.in.editor=false +annotation.processing.run.all.processors=true +annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output +application.title=ff_17 +application.vendor=Leo +build.classes.dir=${build.dir}/classes +build.classes.excludes=**/*.java,**/*.form +# This directory is removed when the project is cleaned: +build.dir=build +build.generated.dir=${build.dir}/generated +build.generated.sources.dir=${build.dir}/generated-sources +# Only compile against the classpath explicitly listed here: +build.sysclasspath=ignore +build.test.classes.dir=${build.dir}/test/classes +build.test.results.dir=${build.dir}/test/results +# Uncomment to specify the preferred debugger connection transport: +#debug.transport=dt_socket +debug.classpath=\ + ${run.classpath} +debug.test.classpath=\ + ${run.test.classpath} +# This directory is removed when the project is cleaned: +dist.dir=dist +dist.jar=${dist.dir}/ff_17.jar +dist.javadoc.dir=${dist.dir}/javadoc +endorsed.classpath= +excludes= +includes=** +jar.compress=false +javac.classpath= +# Space-separated list of extra javac options +javac.compilerargs= +javac.deprecation=false +javac.processorpath=\ + ${javac.classpath} +javac.source=1.7 +javac.target=1.7 +javac.test.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +javac.test.processorpath=\ + ${javac.test.classpath} +javadoc.additionalparam= +javadoc.author=false +javadoc.encoding=${source.encoding} +javadoc.noindex=false +javadoc.nonavbar=false +javadoc.notree=false +javadoc.private=false +javadoc.splitindex=true +javadoc.use=true +javadoc.version=false +javadoc.windowtitle= +main.class=ff_17.Main +manifest.file=manifest.mf +meta.inf.dir=${src.dir}/META-INF +mkdist.disabled=false +platform.active=default_platform +run.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +# Space-separated list of JVM arguments used when running the project +# (you may also define separate properties like run-sys-prop.name=value instead of -Dname=value +# or test-sys-prop.name=value to set system properties for unit tests): +run.jvmargs= +run.test.classpath=\ + ${javac.test.classpath}:\ + ${build.test.classes.dir} +source.encoding=UTF-8 +src.dir=src +test.src.dir=test diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_17/nbproject/project.xml b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_17/nbproject/project.xml new file mode 100644 index 0000000..87eeab6 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_17/nbproject/project.xml @@ -0,0 +1,15 @@ + + + org.netbeans.modules.java.j2seproject + + + ff_17 + + + + + + + + + diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_17/src/ff_17/Main.java b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_17/src/ff_17/Main.java new file mode 100644 index 0000000..88edca8 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_17/src/ff_17/Main.java @@ -0,0 +1,51 @@ +package ff_17; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; + +/** + * + * @author Apress + */ +public class Main { + + public static void main(String[] args) { + + Path rn_racquet = Paths.get("C:/rafaelnadal/equipment", "racquet.txt"); + + //using NIO.2 unbuffered stream + int n; + try (InputStream in = Files.newInputStream(rn_racquet)) { + while ((n = in.read()) != -1) { + System.out.print((char) n); + } + } catch (IOException e) { + System.err.println(e); + } + + byte[] in_buffer = new byte[1024]; + try (InputStream in = Files.newInputStream(rn_racquet)) { + while ((n = in.read(in_buffer)) != -1) { + System.out.println(new String(in_buffer)); + } + } catch (IOException e) { + System.err.println(e); + } + + //convert unbuffered stream to buffered stream by using java.io API + try (InputStream in = Files.newInputStream(rn_racquet); + BufferedReader reader = new BufferedReader(new InputStreamReader(in))) { + String line = null; + while ((line = reader.readLine()) != null) { + System.out.println(line); + } + } catch (IOException e) { + System.err.println(e); + } + } +} diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_18/build.xml b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_18/build.xml new file mode 100644 index 0000000..88028da --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_18/build.xml @@ -0,0 +1,74 @@ + + + + + + + + + + + Builds, tests, and runs the project ff_18. + + + diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_18/build/built-jar.properties b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_18/build/built-jar.properties new file mode 100644 index 0000000..a1e02ef --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_18/build/built-jar.properties @@ -0,0 +1,4 @@ +#Mon, 17 Oct 2011 06:59:06 +0200 + + +C\:\\NIO\\filesandfolders\\ff_18= diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_18/build/classes/.netbeans_automatic_build b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_18/build/classes/.netbeans_automatic_build new file mode 100644 index 0000000..e69de29 diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_18/build/classes/ff_18/Main.class b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_18/build/classes/ff_18/Main.class new file mode 100644 index 0000000..8cce12c Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_18/build/classes/ff_18/Main.class differ diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_18/dist/README.TXT b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_18/dist/README.TXT new file mode 100644 index 0000000..eb8d7d8 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_18/dist/README.TXT @@ -0,0 +1,32 @@ +======================== +BUILD OUTPUT DESCRIPTION +======================== + +When you build an Java application project that has a main class, the IDE +automatically copies all of the JAR +files on the projects classpath to your projects dist/lib folder. The IDE +also adds each of the JAR files to the Class-Path element in the application +JAR files manifest file (MANIFEST.MF). + +To run the project from the command line, go to the dist folder and +type the following: + +java -jar "ff_18.jar" + +To distribute this project, zip up the dist folder (including the lib folder) +and distribute the ZIP file. + +Notes: + +* If two JAR files on the project classpath have the same name, only the first +JAR file is copied to the lib folder. +* Only JAR files are copied to the lib folder. +If the classpath contains other types of files or folders, these files (folders) +are not copied. +* If a library on the projects classpath also has a Class-Path element +specified in the manifest,the content of the Class-Path element has to be on +the projects runtime path. +* To set a main class in a standard Java project, right-click the project node +in the Projects window and choose Properties. Then click Run and enter the +class name in the Main Class field. Alternatively, you can manually type the +class name in the manifest Main-Class element. diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_18/dist/ff_18.jar b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_18/dist/ff_18.jar new file mode 100644 index 0000000..a8e8f97 Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_18/dist/ff_18.jar differ diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_18/manifest.mf b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_18/manifest.mf new file mode 100644 index 0000000..328e8e5 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_18/manifest.mf @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +X-COMMENT: Main-Class will be added automatically by build + diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_18/nbproject/build-impl.xml b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_18/nbproject/build-impl.xml new file mode 100644 index 0000000..ae57315 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_18/nbproject/build-impl.xml @@ -0,0 +1,1041 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set src.dir + Must set test.src.dir + Must set build.dir + Must set dist.dir + Must set build.classes.dir + Must set dist.javadoc.dir + Must set build.test.classes.dir + Must set build.test.results.dir + Must set build.classes.excludes + Must set dist.jar + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set JVM to use for profiling in profiler.info.jvm + Must set profiler agent JVM arguments in profiler.info.jvmargs.agent + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + + + + + + java -cp "${run.classpath.with.dist.jar}" ${main.class} + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + java -jar "${dist.jar.resolved}" + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set run.class + + + + Must select one file in the IDE or set run.class + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set debug.class + + + + + Must select one file in the IDE or set debug.class + + + + + Must set fix.includes + + + + + + + + + + + + + + + + + Must select one file in the IDE or set profile.class + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + Some tests failed; see details above. + + + + + + + + + Must select some files in the IDE or set test.includes + + + + Some tests failed; see details above. + + + + + Must select one file in the IDE or set test.class + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_18/nbproject/genfiles.properties b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_18/nbproject/genfiles.properties new file mode 100644 index 0000000..6410217 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_18/nbproject/genfiles.properties @@ -0,0 +1,8 @@ +build.xml.data.CRC32=b34e713e +build.xml.script.CRC32=340d965b +build.xml.stylesheet.CRC32=28e38971@1.43.1.45 +# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. +# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. +nbproject/build-impl.xml.data.CRC32=b34e713e +nbproject/build-impl.xml.script.CRC32=bc454884 +nbproject/build-impl.xml.stylesheet.CRC32=0c01fd8e@1.43.1.45 diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_18/nbproject/private/config.properties b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_18/nbproject/private/config.properties new file mode 100644 index 0000000..e69de29 diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_18/nbproject/private/private.properties b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_18/nbproject/private/private.properties new file mode 100644 index 0000000..a5ab360 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_18/nbproject/private/private.properties @@ -0,0 +1,6 @@ +compile.on.save=true +do.depend=false +do.jar=true +javac.debug=true +javadoc.preview=true +user.properties.file=C:\\Users\\Leo\\.netbeans\\7.0\\build.properties diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_18/nbproject/private/private.xml b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_18/nbproject/private/private.xml new file mode 100644 index 0000000..c1f155a --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_18/nbproject/private/private.xml @@ -0,0 +1,4 @@ + + + + diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_18/nbproject/project.properties b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_18/nbproject/project.properties new file mode 100644 index 0000000..b0bc3ab --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_18/nbproject/project.properties @@ -0,0 +1,72 @@ +annotation.processing.enabled=true +annotation.processing.enabled.in.editor=false +annotation.processing.run.all.processors=true +annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output +application.title=ff_18 +application.vendor=Leo +build.classes.dir=${build.dir}/classes +build.classes.excludes=**/*.java,**/*.form +# This directory is removed when the project is cleaned: +build.dir=build +build.generated.dir=${build.dir}/generated +build.generated.sources.dir=${build.dir}/generated-sources +# Only compile against the classpath explicitly listed here: +build.sysclasspath=ignore +build.test.classes.dir=${build.dir}/test/classes +build.test.results.dir=${build.dir}/test/results +# Uncomment to specify the preferred debugger connection transport: +#debug.transport=dt_socket +debug.classpath=\ + ${run.classpath} +debug.test.classpath=\ + ${run.test.classpath} +# This directory is removed when the project is cleaned: +dist.dir=dist +dist.jar=${dist.dir}/ff_18.jar +dist.javadoc.dir=${dist.dir}/javadoc +endorsed.classpath= +excludes= +includes=** +jar.compress=false +javac.classpath= +# Space-separated list of extra javac options +javac.compilerargs= +javac.deprecation=false +javac.processorpath=\ + ${javac.classpath} +javac.source=1.7 +javac.target=1.7 +javac.test.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +javac.test.processorpath=\ + ${javac.test.classpath} +javadoc.additionalparam= +javadoc.author=false +javadoc.encoding=${source.encoding} +javadoc.noindex=false +javadoc.nonavbar=false +javadoc.notree=false +javadoc.private=false +javadoc.splitindex=true +javadoc.use=true +javadoc.version=false +javadoc.windowtitle= +main.class=ff_18.Main +manifest.file=manifest.mf +meta.inf.dir=${src.dir}/META-INF +mkdist.disabled=false +platform.active=default_platform +run.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +# Space-separated list of JVM arguments used when running the project +# (you may also define separate properties like run-sys-prop.name=value instead of -Dname=value +# or test-sys-prop.name=value to set system properties for unit tests): +run.jvmargs= +run.test.classpath=\ + ${javac.test.classpath}:\ + ${build.test.classes.dir} +source.encoding=UTF-8 +src.dir=src +test.src.dir=test diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_18/nbproject/project.xml b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_18/nbproject/project.xml new file mode 100644 index 0000000..a526f5f --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_18/nbproject/project.xml @@ -0,0 +1,15 @@ + + + org.netbeans.modules.java.j2seproject + + + ff_18 + + + + + + + + + diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_18/src/ff_18/Main.java b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_18/src/ff_18/Main.java new file mode 100644 index 0000000..c65a930 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_18/src/ff_18/Main.java @@ -0,0 +1,40 @@ +package ff_18; + +import java.io.BufferedWriter; +import java.io.IOException; +import java.io.OutputStream; +import java.io.OutputStreamWriter; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.nio.file.StandardOpenOption; + +/** + * + * @author Apress + */ +public class Main { + + public static void main(String[] args) { + + Path rn_racquet = Paths.get("C:/rafaelnadal/equipment", "racquet.txt"); + String racquet = "Racquet: Babolat AeroPro Drive GT"; + String string = "\nString: Babolat RPM Blast 16"; + + //using NIO.2 unbuffered stream + byte data[] = racquet.getBytes(); + try (OutputStream outputStream = Files.newOutputStream(rn_racquet)) { + outputStream.write(data); + } catch (IOException e) { + System.err.println(e); + } + + //convert unbuffered stream to buffered stream by using java.io API + try (OutputStream outputStream = Files.newOutputStream(rn_racquet, StandardOpenOption.APPEND); + BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(outputStream))) { + writer.write(string); + } catch (IOException e) { + System.err.println(e); + } + } +} diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_19/build.xml b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_19/build.xml new file mode 100644 index 0000000..22d5afe --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_19/build.xml @@ -0,0 +1,74 @@ + + + + + + + + + + + Builds, tests, and runs the project ff_19. + + + diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_19/build/built-jar.properties b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_19/build/built-jar.properties new file mode 100644 index 0000000..f25124b --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_19/build/built-jar.properties @@ -0,0 +1,4 @@ +#Mon, 17 Oct 2011 07:03:54 +0200 + + +C\:\\NIO\\filesandfolders\\ff_19= diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_19/build/classes/ff_19/Main.class b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_19/build/classes/ff_19/Main.class new file mode 100644 index 0000000..569b9e8 Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_19/build/classes/ff_19/Main.class differ diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_19/dist/README.TXT b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_19/dist/README.TXT new file mode 100644 index 0000000..5fea58a --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_19/dist/README.TXT @@ -0,0 +1,32 @@ +======================== +BUILD OUTPUT DESCRIPTION +======================== + +When you build an Java application project that has a main class, the IDE +automatically copies all of the JAR +files on the projects classpath to your projects dist/lib folder. The IDE +also adds each of the JAR files to the Class-Path element in the application +JAR files manifest file (MANIFEST.MF). + +To run the project from the command line, go to the dist folder and +type the following: + +java -jar "ff_19.jar" + +To distribute this project, zip up the dist folder (including the lib folder) +and distribute the ZIP file. + +Notes: + +* If two JAR files on the project classpath have the same name, only the first +JAR file is copied to the lib folder. +* Only JAR files are copied to the lib folder. +If the classpath contains other types of files or folders, these files (folders) +are not copied. +* If a library on the projects classpath also has a Class-Path element +specified in the manifest,the content of the Class-Path element has to be on +the projects runtime path. +* To set a main class in a standard Java project, right-click the project node +in the Projects window and choose Properties. Then click Run and enter the +class name in the Main Class field. Alternatively, you can manually type the +class name in the manifest Main-Class element. diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_19/dist/ff_19.jar b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_19/dist/ff_19.jar new file mode 100644 index 0000000..2020738 Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_19/dist/ff_19.jar differ diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_19/manifest.mf b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_19/manifest.mf new file mode 100644 index 0000000..328e8e5 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_19/manifest.mf @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +X-COMMENT: Main-Class will be added automatically by build + diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_19/nbproject/build-impl.xml b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_19/nbproject/build-impl.xml new file mode 100644 index 0000000..287cba4 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_19/nbproject/build-impl.xml @@ -0,0 +1,1074 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set platform.home + Must set platform.bootcp + Must set platform.java + Must set platform.javac + + The J2SE Platform is not correctly set up. + Your active platform is: ${platform.active}, but the corresponding property "platforms.${platform.active}.home" is not found in the project's properties files. + Either open the project in the IDE and setup the Platform with the same name or add it manually. + For example like this: + ant -Duser.properties.file=<path_to_property_file> jar (where you put the property "platforms.${platform.active}.home" in a .properties file) + or ant -Dplatforms.${platform.active}.home=<path_to_JDK_home> jar (where no properties file is used) + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set src.dir + Must set test.src.dir + Must set build.dir + Must set dist.dir + Must set build.classes.dir + Must set dist.javadoc.dir + Must set build.test.classes.dir + Must set build.test.results.dir + Must set build.classes.excludes + Must set dist.jar + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set JVM to use for profiling in profiler.info.jvm + Must set profiler agent JVM arguments in profiler.info.jvmargs.agent + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + + + + + + ${platform.java} -cp "${run.classpath.with.dist.jar}" ${main.class} + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + ${platform.java} -jar "${dist.jar.resolved}" + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set run.class + + + + Must select one file in the IDE or set run.class + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set debug.class + + + + + Must select one file in the IDE or set debug.class + + + + + Must set fix.includes + + + + + + + + + + + + + + + + + Must select one file in the IDE or set profile.class + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + Some tests failed; see details above. + + + + + + + + + Must select some files in the IDE or set test.includes + + + + Some tests failed; see details above. + + + + + Must select one file in the IDE or set test.class + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_19/nbproject/genfiles.properties b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_19/nbproject/genfiles.properties new file mode 100644 index 0000000..5d8e97c --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_19/nbproject/genfiles.properties @@ -0,0 +1,8 @@ +build.xml.data.CRC32=01f033f0 +build.xml.script.CRC32=c8e166df +build.xml.stylesheet.CRC32=28e38971@1.43.1.45 +# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. +# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. +nbproject/build-impl.xml.data.CRC32=01f033f0 +nbproject/build-impl.xml.script.CRC32=04713bfa +nbproject/build-impl.xml.stylesheet.CRC32=0c01fd8e@1.43.1.45 diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_19/nbproject/private/config.properties b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_19/nbproject/private/config.properties new file mode 100644 index 0000000..e69de29 diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_19/nbproject/private/private.properties b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_19/nbproject/private/private.properties new file mode 100644 index 0000000..a5ab360 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_19/nbproject/private/private.properties @@ -0,0 +1,6 @@ +compile.on.save=true +do.depend=false +do.jar=true +javac.debug=true +javadoc.preview=true +user.properties.file=C:\\Users\\Leo\\.netbeans\\7.0\\build.properties diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_19/nbproject/private/private.xml b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_19/nbproject/private/private.xml new file mode 100644 index 0000000..c1f155a --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_19/nbproject/private/private.xml @@ -0,0 +1,4 @@ + + + + diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_19/nbproject/project.properties b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_19/nbproject/project.properties new file mode 100644 index 0000000..fcf86c6 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_19/nbproject/project.properties @@ -0,0 +1,72 @@ +annotation.processing.enabled=true +annotation.processing.enabled.in.editor=false +annotation.processing.run.all.processors=true +annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output +application.title=ff_19 +application.vendor=Leo +build.classes.dir=${build.dir}/classes +build.classes.excludes=**/*.java,**/*.form +# This directory is removed when the project is cleaned: +build.dir=build +build.generated.dir=${build.dir}/generated +build.generated.sources.dir=${build.dir}/generated-sources +# Only compile against the classpath explicitly listed here: +build.sysclasspath=ignore +build.test.classes.dir=${build.dir}/test/classes +build.test.results.dir=${build.dir}/test/results +# Uncomment to specify the preferred debugger connection transport: +#debug.transport=dt_socket +debug.classpath=\ + ${run.classpath} +debug.test.classpath=\ + ${run.test.classpath} +# This directory is removed when the project is cleaned: +dist.dir=dist +dist.jar=${dist.dir}/ff_19.jar +dist.javadoc.dir=${dist.dir}/javadoc +endorsed.classpath= +excludes= +includes=** +jar.compress=false +javac.classpath= +# Space-separated list of extra javac options +javac.compilerargs= +javac.deprecation=false +javac.processorpath=\ + ${javac.classpath} +javac.source=1.7 +javac.target=1.7 +javac.test.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +javac.test.processorpath=\ + ${javac.test.classpath} +javadoc.additionalparam= +javadoc.author=false +javadoc.encoding=${source.encoding} +javadoc.noindex=false +javadoc.nonavbar=false +javadoc.notree=false +javadoc.private=false +javadoc.splitindex=true +javadoc.use=true +javadoc.version=false +javadoc.windowtitle= +main.class=ff_19.Main +manifest.file=manifest.mf +meta.inf.dir=${src.dir}/META-INF +mkdist.disabled=false +platform.active=JDK_1.7 +run.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +# Space-separated list of JVM arguments used when running the project +# (you may also define separate properties like run-sys-prop.name=value instead of -Dname=value +# or test-sys-prop.name=value to set system properties for unit tests): +run.jvmargs= +run.test.classpath=\ + ${javac.test.classpath}:\ + ${build.test.classes.dir} +source.encoding=UTF-8 +src.dir=src +test.src.dir=test diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_19/nbproject/project.xml b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_19/nbproject/project.xml new file mode 100644 index 0000000..3ce513d --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_19/nbproject/project.xml @@ -0,0 +1,16 @@ + + + org.netbeans.modules.java.j2seproject + + + ff_19 + + + + + + + + + + diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_19/src/ff_19/Main.java b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_19/src/ff_19/Main.java new file mode 100644 index 0000000..fa5fd09 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_19/src/ff_19/Main.java @@ -0,0 +1,42 @@ +package ff_19; + +import java.io.IOException; +import java.nio.file.FileAlreadyExistsException; +import java.nio.file.FileSystems; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.attribute.FileAttribute; +import java.nio.file.attribute.PosixFilePermission; +import java.nio.file.attribute.PosixFilePermissions; +import java.util.Set; + +/** + * + * @author Apress + */ +public class Main { + + public static void main(String[] args) { + + Path newfile_1 = FileSystems.getDefault().getPath("C:/rafaelnadal/tournaments/2010/SonyEricssonOpen.txt"); + Path newfile_2 = FileSystems.getDefault().getPath("/home/rafaelnadal/tournaments/2010/SonyEricssonOpen.txt"); + Path newfile_3 = FileSystems.getDefault().getPath("2010/SonyEricssonOpen.txt"); + Path newfile_4 = FileSystems.getDefault().getPath("../2010/SonyEricssonOpen.txt"); + + //create a file with default attributes + try { + Files.createFile(newfile_1); + } catch (IOException e) { + System.err.println(e); + } + + //create a file with a set of specified attributes + Set perms = PosixFilePermissions.fromString("rw-------"); + FileAttribute> attr = PosixFilePermissions.asFileAttribute(perms); + try { + Files.createFile(newfile_2, attr); + } catch (IOException e) { + System.err.println(e); + } + } +} diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_20/build.xml b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_20/build.xml new file mode 100644 index 0000000..e1b6310 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_20/build.xml @@ -0,0 +1,74 @@ + + + + + + + + + + + Builds, tests, and runs the project ff_20. + + + diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_20/build/built-jar.properties b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_20/build/built-jar.properties new file mode 100644 index 0000000..c9519d7 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_20/build/built-jar.properties @@ -0,0 +1,4 @@ +#Mon, 17 Oct 2011 07:05:54 +0200 + + +C\:\\NIO\\filesandfolders\\ff_20= diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_20/build/classes/ff_20/Main.class b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_20/build/classes/ff_20/Main.class new file mode 100644 index 0000000..5796559 Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_20/build/classes/ff_20/Main.class differ diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_20/dist/README.TXT b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_20/dist/README.TXT new file mode 100644 index 0000000..3996160 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_20/dist/README.TXT @@ -0,0 +1,32 @@ +======================== +BUILD OUTPUT DESCRIPTION +======================== + +When you build an Java application project that has a main class, the IDE +automatically copies all of the JAR +files on the projects classpath to your projects dist/lib folder. The IDE +also adds each of the JAR files to the Class-Path element in the application +JAR files manifest file (MANIFEST.MF). + +To run the project from the command line, go to the dist folder and +type the following: + +java -jar "ff_20.jar" + +To distribute this project, zip up the dist folder (including the lib folder) +and distribute the ZIP file. + +Notes: + +* If two JAR files on the project classpath have the same name, only the first +JAR file is copied to the lib folder. +* Only JAR files are copied to the lib folder. +If the classpath contains other types of files or folders, these files (folders) +are not copied. +* If a library on the projects classpath also has a Class-Path element +specified in the manifest,the content of the Class-Path element has to be on +the projects runtime path. +* To set a main class in a standard Java project, right-click the project node +in the Projects window and choose Properties. Then click Run and enter the +class name in the Main Class field. Alternatively, you can manually type the +class name in the manifest Main-Class element. diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_20/dist/ff_20.jar b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_20/dist/ff_20.jar new file mode 100644 index 0000000..5415b03 Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_20/dist/ff_20.jar differ diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_20/manifest.mf b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_20/manifest.mf new file mode 100644 index 0000000..328e8e5 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_20/manifest.mf @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +X-COMMENT: Main-Class will be added automatically by build + diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_20/nbproject/build-impl.xml b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_20/nbproject/build-impl.xml new file mode 100644 index 0000000..71e1bd7 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_20/nbproject/build-impl.xml @@ -0,0 +1,1041 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set src.dir + Must set test.src.dir + Must set build.dir + Must set dist.dir + Must set build.classes.dir + Must set dist.javadoc.dir + Must set build.test.classes.dir + Must set build.test.results.dir + Must set build.classes.excludes + Must set dist.jar + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set JVM to use for profiling in profiler.info.jvm + Must set profiler agent JVM arguments in profiler.info.jvmargs.agent + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + + + + + + java -cp "${run.classpath.with.dist.jar}" ${main.class} + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + java -jar "${dist.jar.resolved}" + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set run.class + + + + Must select one file in the IDE or set run.class + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set debug.class + + + + + Must select one file in the IDE or set debug.class + + + + + Must set fix.includes + + + + + + + + + + + + + + + + + Must select one file in the IDE or set profile.class + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + Some tests failed; see details above. + + + + + + + + + Must select some files in the IDE or set test.includes + + + + Some tests failed; see details above. + + + + + Must select one file in the IDE or set test.class + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_20/nbproject/genfiles.properties b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_20/nbproject/genfiles.properties new file mode 100644 index 0000000..7e3b4be --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_20/nbproject/genfiles.properties @@ -0,0 +1,8 @@ +build.xml.data.CRC32=5eadacdc +build.xml.script.CRC32=5ba5f165 +build.xml.stylesheet.CRC32=28e38971@1.43.1.45 +# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. +# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. +nbproject/build-impl.xml.data.CRC32=5eadacdc +nbproject/build-impl.xml.script.CRC32=928c9d1a +nbproject/build-impl.xml.stylesheet.CRC32=0c01fd8e@1.43.1.45 diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_20/nbproject/private/config.properties b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_20/nbproject/private/config.properties new file mode 100644 index 0000000..e69de29 diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_20/nbproject/private/private.properties b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_20/nbproject/private/private.properties new file mode 100644 index 0000000..a5ab360 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_20/nbproject/private/private.properties @@ -0,0 +1,6 @@ +compile.on.save=true +do.depend=false +do.jar=true +javac.debug=true +javadoc.preview=true +user.properties.file=C:\\Users\\Leo\\.netbeans\\7.0\\build.properties diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_20/nbproject/private/private.xml b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_20/nbproject/private/private.xml new file mode 100644 index 0000000..c1f155a --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_20/nbproject/private/private.xml @@ -0,0 +1,4 @@ + + + + diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_20/nbproject/project.properties b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_20/nbproject/project.properties new file mode 100644 index 0000000..1179aa4 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_20/nbproject/project.properties @@ -0,0 +1,72 @@ +annotation.processing.enabled=true +annotation.processing.enabled.in.editor=false +annotation.processing.run.all.processors=true +annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output +application.title=ff_20 +application.vendor=Leo +build.classes.dir=${build.dir}/classes +build.classes.excludes=**/*.java,**/*.form +# This directory is removed when the project is cleaned: +build.dir=build +build.generated.dir=${build.dir}/generated +build.generated.sources.dir=${build.dir}/generated-sources +# Only compile against the classpath explicitly listed here: +build.sysclasspath=ignore +build.test.classes.dir=${build.dir}/test/classes +build.test.results.dir=${build.dir}/test/results +# Uncomment to specify the preferred debugger connection transport: +#debug.transport=dt_socket +debug.classpath=\ + ${run.classpath} +debug.test.classpath=\ + ${run.test.classpath} +# This directory is removed when the project is cleaned: +dist.dir=dist +dist.jar=${dist.dir}/ff_20.jar +dist.javadoc.dir=${dist.dir}/javadoc +endorsed.classpath= +excludes= +includes=** +jar.compress=false +javac.classpath= +# Space-separated list of extra javac options +javac.compilerargs= +javac.deprecation=false +javac.processorpath=\ + ${javac.classpath} +javac.source=1.7 +javac.target=1.7 +javac.test.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +javac.test.processorpath=\ + ${javac.test.classpath} +javadoc.additionalparam= +javadoc.author=false +javadoc.encoding=${source.encoding} +javadoc.noindex=false +javadoc.nonavbar=false +javadoc.notree=false +javadoc.private=false +javadoc.splitindex=true +javadoc.use=true +javadoc.version=false +javadoc.windowtitle= +main.class=ff_20.Main +manifest.file=manifest.mf +meta.inf.dir=${src.dir}/META-INF +mkdist.disabled=false +platform.active=default_platform +run.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +# Space-separated list of JVM arguments used when running the project +# (you may also define separate properties like run-sys-prop.name=value instead of -Dname=value +# or test-sys-prop.name=value to set system properties for unit tests): +run.jvmargs= +run.test.classpath=\ + ${javac.test.classpath}:\ + ${build.test.classes.dir} +source.encoding=UTF-8 +src.dir=src +test.src.dir=test diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_20/nbproject/project.xml b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_20/nbproject/project.xml new file mode 100644 index 0000000..0a786b6 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_20/nbproject/project.xml @@ -0,0 +1,15 @@ + + + org.netbeans.modules.java.j2seproject + + + ff_20 + + + + + + + + + diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_20/src/ff_20/Main.java b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_20/src/ff_20/Main.java new file mode 100644 index 0000000..0d1e267 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_20/src/ff_20/Main.java @@ -0,0 +1,39 @@ +package ff_20; + +import java.io.IOException; +import java.nio.file.FileSystems; +import java.nio.file.Files; +import java.nio.file.Path; + +/** + * + * @author Apress + */ +public class Main { + + public static void main(String[] args) { + + Path basedir = FileSystems.getDefault().getPath("C:/rafaelnadal/tmp"); + String tmp_file_prefix = "rafa_"; + String tmp_file_sufix=".txt"; + + //get the default temporary folders path + String default_tmp = System.getProperty("java.io.tmpdir"); + System.out.println(default_tmp); + + try { + //passing null prefix/sufix + Path tmp_1 = Files.createTempFile(null,null); + System.out.println("TMP: " + tmp_1.toString()); + //set a prefix and a sufix + Path tmp_2 = Files.createTempFile(tmp_file_prefix, tmp_file_sufix); + System.out.println("TMP: " + tmp_2.toString()); + //create a tmp file in a the base dir + Path tmp_3 = Files.createTempFile(basedir, tmp_file_prefix, tmp_file_sufix); + System.out.println("TMP: " + tmp_3.toString()); + } catch (IOException e) { + System.err.println(e); + } + + } +} diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_21/build.xml b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_21/build.xml new file mode 100644 index 0000000..28fe50a --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_21/build.xml @@ -0,0 +1,74 @@ + + + + + + + + + + + Builds, tests, and runs the project ff_21. + + + diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_21/build/built-jar.properties b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_21/build/built-jar.properties new file mode 100644 index 0000000..f3bd853 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_21/build/built-jar.properties @@ -0,0 +1,4 @@ +#Mon, 17 Oct 2011 07:07:06 +0200 + + +C\:\\NIO\\filesandfolders\\ff_21= diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_21/build/classes/ff_21/Main$1.class b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_21/build/classes/ff_21/Main$1.class new file mode 100644 index 0000000..fa91895 Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_21/build/classes/ff_21/Main$1.class differ diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_21/build/classes/ff_21/Main.class b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_21/build/classes/ff_21/Main.class new file mode 100644 index 0000000..eac8db5 Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_21/build/classes/ff_21/Main.class differ diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_21/dist/README.TXT b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_21/dist/README.TXT new file mode 100644 index 0000000..bf0c76d --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_21/dist/README.TXT @@ -0,0 +1,32 @@ +======================== +BUILD OUTPUT DESCRIPTION +======================== + +When you build an Java application project that has a main class, the IDE +automatically copies all of the JAR +files on the projects classpath to your projects dist/lib folder. The IDE +also adds each of the JAR files to the Class-Path element in the application +JAR files manifest file (MANIFEST.MF). + +To run the project from the command line, go to the dist folder and +type the following: + +java -jar "ff_21.jar" + +To distribute this project, zip up the dist folder (including the lib folder) +and distribute the ZIP file. + +Notes: + +* If two JAR files on the project classpath have the same name, only the first +JAR file is copied to the lib folder. +* Only JAR files are copied to the lib folder. +If the classpath contains other types of files or folders, these files (folders) +are not copied. +* If a library on the projects classpath also has a Class-Path element +specified in the manifest,the content of the Class-Path element has to be on +the projects runtime path. +* To set a main class in a standard Java project, right-click the project node +in the Projects window and choose Properties. Then click Run and enter the +class name in the Main Class field. Alternatively, you can manually type the +class name in the manifest Main-Class element. diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_21/dist/ff_21.jar b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_21/dist/ff_21.jar new file mode 100644 index 0000000..4e6b223 Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_21/dist/ff_21.jar differ diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_21/manifest.mf b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_21/manifest.mf new file mode 100644 index 0000000..328e8e5 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_21/manifest.mf @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +X-COMMENT: Main-Class will be added automatically by build + diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_21/nbproject/build-impl.xml b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_21/nbproject/build-impl.xml new file mode 100644 index 0000000..c7070a8 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_21/nbproject/build-impl.xml @@ -0,0 +1,1041 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set src.dir + Must set test.src.dir + Must set build.dir + Must set dist.dir + Must set build.classes.dir + Must set dist.javadoc.dir + Must set build.test.classes.dir + Must set build.test.results.dir + Must set build.classes.excludes + Must set dist.jar + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set JVM to use for profiling in profiler.info.jvm + Must set profiler agent JVM arguments in profiler.info.jvmargs.agent + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + + + + + + java -cp "${run.classpath.with.dist.jar}" ${main.class} + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + java -jar "${dist.jar.resolved}" + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set run.class + + + + Must select one file in the IDE or set run.class + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set debug.class + + + + + Must select one file in the IDE or set debug.class + + + + + Must set fix.includes + + + + + + + + + + + + + + + + + Must select one file in the IDE or set profile.class + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + Some tests failed; see details above. + + + + + + + + + Must select some files in the IDE or set test.includes + + + + Some tests failed; see details above. + + + + + Must select one file in the IDE or set test.class + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_21/nbproject/genfiles.properties b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_21/nbproject/genfiles.properties new file mode 100644 index 0000000..313ed21 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_21/nbproject/genfiles.properties @@ -0,0 +1,8 @@ +build.xml.data.CRC32=56be20fa +build.xml.script.CRC32=a74901e1 +build.xml.stylesheet.CRC32=28e38971@1.43.1.45 +# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. +# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. +nbproject/build-impl.xml.data.CRC32=56be20fa +nbproject/build-impl.xml.script.CRC32=25056961 +nbproject/build-impl.xml.stylesheet.CRC32=0c01fd8e@1.43.1.45 diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_21/nbproject/private/config.properties b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_21/nbproject/private/config.properties new file mode 100644 index 0000000..e69de29 diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_21/nbproject/private/private.properties b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_21/nbproject/private/private.properties new file mode 100644 index 0000000..a5ab360 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_21/nbproject/private/private.properties @@ -0,0 +1,6 @@ +compile.on.save=true +do.depend=false +do.jar=true +javac.debug=true +javadoc.preview=true +user.properties.file=C:\\Users\\Leo\\.netbeans\\7.0\\build.properties diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_21/nbproject/private/private.xml b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_21/nbproject/private/private.xml new file mode 100644 index 0000000..c1f155a --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_21/nbproject/private/private.xml @@ -0,0 +1,4 @@ + + + + diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_21/nbproject/project.properties b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_21/nbproject/project.properties new file mode 100644 index 0000000..f6c8a3a --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_21/nbproject/project.properties @@ -0,0 +1,72 @@ +annotation.processing.enabled=true +annotation.processing.enabled.in.editor=false +annotation.processing.run.all.processors=true +annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output +application.title=ff_21 +application.vendor=Leo +build.classes.dir=${build.dir}/classes +build.classes.excludes=**/*.java,**/*.form +# This directory is removed when the project is cleaned: +build.dir=build +build.generated.dir=${build.dir}/generated +build.generated.sources.dir=${build.dir}/generated-sources +# Only compile against the classpath explicitly listed here: +build.sysclasspath=ignore +build.test.classes.dir=${build.dir}/test/classes +build.test.results.dir=${build.dir}/test/results +# Uncomment to specify the preferred debugger connection transport: +#debug.transport=dt_socket +debug.classpath=\ + ${run.classpath} +debug.test.classpath=\ + ${run.test.classpath} +# This directory is removed when the project is cleaned: +dist.dir=dist +dist.jar=${dist.dir}/ff_21.jar +dist.javadoc.dir=${dist.dir}/javadoc +endorsed.classpath= +excludes= +includes=** +jar.compress=false +javac.classpath= +# Space-separated list of extra javac options +javac.compilerargs= +javac.deprecation=false +javac.processorpath=\ + ${javac.classpath} +javac.source=1.7 +javac.target=1.7 +javac.test.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +javac.test.processorpath=\ + ${javac.test.classpath} +javadoc.additionalparam= +javadoc.author=false +javadoc.encoding=${source.encoding} +javadoc.noindex=false +javadoc.nonavbar=false +javadoc.notree=false +javadoc.private=false +javadoc.splitindex=true +javadoc.use=true +javadoc.version=false +javadoc.windowtitle= +main.class=ff_21.Main +manifest.file=manifest.mf +meta.inf.dir=${src.dir}/META-INF +mkdist.disabled=false +platform.active=default_platform +run.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +# Space-separated list of JVM arguments used when running the project +# (you may also define separate properties like run-sys-prop.name=value instead of -Dname=value +# or test-sys-prop.name=value to set system properties for unit tests): +run.jvmargs= +run.test.classpath=\ + ${javac.test.classpath}:\ + ${build.test.classes.dir} +source.encoding=UTF-8 +src.dir=src +test.src.dir=test diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_21/nbproject/project.xml b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_21/nbproject/project.xml new file mode 100644 index 0000000..34de1b6 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_21/nbproject/project.xml @@ -0,0 +1,15 @@ + + + org.netbeans.modules.java.j2seproject + + + ff_21 + + + + + + + + + diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_21/src/ff_21/Main.java b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_21/src/ff_21/Main.java new file mode 100644 index 0000000..579af96 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_21/src/ff_21/Main.java @@ -0,0 +1,46 @@ +package ff_21; + +import java.io.IOException; +import java.nio.file.FileSystems; +import java.nio.file.Files; +import java.nio.file.Path; + +/** + * + * @author Apress + */ +public class Main { + + public static void main(String[] args) { + + Path basedir = FileSystems.getDefault().getPath("C:/rafaelnadal/tmp"); + String tmp_file_prefix = "rafa_"; + String tmp_file_sufix = ".txt"; + + try { + final Path tmp_file = Files.createTempFile(basedir, tmp_file_prefix, tmp_file_sufix); + + Runtime.getRuntime().addShutdownHook(new Thread() { + + @Override + public void run() { + System.out.println("Deleting the temporary file ..."); + try { + Files.delete(tmp_file); + } catch (IOException e) { + System.err.println(e); + } + System.out.println("Shutdown hook completed..."); + } + }); + + //simulate some operations with temp file until delete it + Thread.sleep(10000); + //operations done + + } catch (IOException | InterruptedException e) { + System.err.println(e); + } + + } +} diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_22/build.xml b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_22/build.xml new file mode 100644 index 0000000..812f364 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_22/build.xml @@ -0,0 +1,74 @@ + + + + + + + + + + + Builds, tests, and runs the project ff_22. + + + diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_22/build/built-jar.properties b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_22/build/built-jar.properties new file mode 100644 index 0000000..f46e993 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_22/build/built-jar.properties @@ -0,0 +1,4 @@ +#Mon, 17 Oct 2011 07:07:55 +0200 + + +C\:\\NIO\\filesandfolders\\ff_22= diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_22/build/classes/ff_22/Main.class b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_22/build/classes/ff_22/Main.class new file mode 100644 index 0000000..28018f4 Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_22/build/classes/ff_22/Main.class differ diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_22/dist/README.TXT b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_22/dist/README.TXT new file mode 100644 index 0000000..70ad704 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_22/dist/README.TXT @@ -0,0 +1,32 @@ +======================== +BUILD OUTPUT DESCRIPTION +======================== + +When you build an Java application project that has a main class, the IDE +automatically copies all of the JAR +files on the projects classpath to your projects dist/lib folder. The IDE +also adds each of the JAR files to the Class-Path element in the application +JAR files manifest file (MANIFEST.MF). + +To run the project from the command line, go to the dist folder and +type the following: + +java -jar "ff_22.jar" + +To distribute this project, zip up the dist folder (including the lib folder) +and distribute the ZIP file. + +Notes: + +* If two JAR files on the project classpath have the same name, only the first +JAR file is copied to the lib folder. +* Only JAR files are copied to the lib folder. +If the classpath contains other types of files or folders, these files (folders) +are not copied. +* If a library on the projects classpath also has a Class-Path element +specified in the manifest,the content of the Class-Path element has to be on +the projects runtime path. +* To set a main class in a standard Java project, right-click the project node +in the Projects window and choose Properties. Then click Run and enter the +class name in the Main Class field. Alternatively, you can manually type the +class name in the manifest Main-Class element. diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_22/dist/ff_22.jar b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_22/dist/ff_22.jar new file mode 100644 index 0000000..26b626e Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_22/dist/ff_22.jar differ diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_22/manifest.mf b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_22/manifest.mf new file mode 100644 index 0000000..328e8e5 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_22/manifest.mf @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +X-COMMENT: Main-Class will be added automatically by build + diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_22/nbproject/build-impl.xml b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_22/nbproject/build-impl.xml new file mode 100644 index 0000000..d7b2f69 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_22/nbproject/build-impl.xml @@ -0,0 +1,1041 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set src.dir + Must set test.src.dir + Must set build.dir + Must set dist.dir + Must set build.classes.dir + Must set dist.javadoc.dir + Must set build.test.classes.dir + Must set build.test.results.dir + Must set build.classes.excludes + Must set dist.jar + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set JVM to use for profiling in profiler.info.jvm + Must set profiler agent JVM arguments in profiler.info.jvmargs.agent + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + + + + + + java -cp "${run.classpath.with.dist.jar}" ${main.class} + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + java -jar "${dist.jar.resolved}" + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set run.class + + + + Must select one file in the IDE or set run.class + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set debug.class + + + + + Must select one file in the IDE or set debug.class + + + + + Must set fix.includes + + + + + + + + + + + + + + + + + Must select one file in the IDE or set profile.class + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + Some tests failed; see details above. + + + + + + + + + Must select some files in the IDE or set test.includes + + + + Some tests failed; see details above. + + + + + Must select one file in the IDE or set test.class + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_22/nbproject/genfiles.properties b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_22/nbproject/genfiles.properties new file mode 100644 index 0000000..ada796b --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_22/nbproject/genfiles.properties @@ -0,0 +1,8 @@ +build.xml.data.CRC32=4e8ab490 +build.xml.script.CRC32=790d162c +build.xml.stylesheet.CRC32=28e38971@1.43.1.45 +# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. +# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. +nbproject/build-impl.xml.data.CRC32=4e8ab490 +nbproject/build-impl.xml.script.CRC32=26ee73ad +nbproject/build-impl.xml.stylesheet.CRC32=0c01fd8e@1.43.1.45 diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_22/nbproject/private/config.properties b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_22/nbproject/private/config.properties new file mode 100644 index 0000000..e69de29 diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_22/nbproject/private/private.properties b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_22/nbproject/private/private.properties new file mode 100644 index 0000000..a5ab360 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_22/nbproject/private/private.properties @@ -0,0 +1,6 @@ +compile.on.save=true +do.depend=false +do.jar=true +javac.debug=true +javadoc.preview=true +user.properties.file=C:\\Users\\Leo\\.netbeans\\7.0\\build.properties diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_22/nbproject/private/private.xml b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_22/nbproject/private/private.xml new file mode 100644 index 0000000..c1f155a --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_22/nbproject/private/private.xml @@ -0,0 +1,4 @@ + + + + diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_22/nbproject/project.properties b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_22/nbproject/project.properties new file mode 100644 index 0000000..40d0201 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_22/nbproject/project.properties @@ -0,0 +1,72 @@ +annotation.processing.enabled=true +annotation.processing.enabled.in.editor=false +annotation.processing.run.all.processors=true +annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output +application.title=ff_22 +application.vendor=Leo +build.classes.dir=${build.dir}/classes +build.classes.excludes=**/*.java,**/*.form +# This directory is removed when the project is cleaned: +build.dir=build +build.generated.dir=${build.dir}/generated +build.generated.sources.dir=${build.dir}/generated-sources +# Only compile against the classpath explicitly listed here: +build.sysclasspath=ignore +build.test.classes.dir=${build.dir}/test/classes +build.test.results.dir=${build.dir}/test/results +# Uncomment to specify the preferred debugger connection transport: +#debug.transport=dt_socket +debug.classpath=\ + ${run.classpath} +debug.test.classpath=\ + ${run.test.classpath} +# This directory is removed when the project is cleaned: +dist.dir=dist +dist.jar=${dist.dir}/ff_22.jar +dist.javadoc.dir=${dist.dir}/javadoc +endorsed.classpath= +excludes= +includes=** +jar.compress=false +javac.classpath= +# Space-separated list of extra javac options +javac.compilerargs= +javac.deprecation=false +javac.processorpath=\ + ${javac.classpath} +javac.source=1.7 +javac.target=1.7 +javac.test.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +javac.test.processorpath=\ + ${javac.test.classpath} +javadoc.additionalparam= +javadoc.author=false +javadoc.encoding=${source.encoding} +javadoc.noindex=false +javadoc.nonavbar=false +javadoc.notree=false +javadoc.private=false +javadoc.splitindex=true +javadoc.use=true +javadoc.version=false +javadoc.windowtitle= +main.class=ff_22.Main +manifest.file=manifest.mf +meta.inf.dir=${src.dir}/META-INF +mkdist.disabled=false +platform.active=default_platform +run.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +# Space-separated list of JVM arguments used when running the project +# (you may also define separate properties like run-sys-prop.name=value instead of -Dname=value +# or test-sys-prop.name=value to set system properties for unit tests): +run.jvmargs= +run.test.classpath=\ + ${javac.test.classpath}:\ + ${build.test.classes.dir} +source.encoding=UTF-8 +src.dir=src +test.src.dir=test diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_22/nbproject/project.xml b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_22/nbproject/project.xml new file mode 100644 index 0000000..11ecabc --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_22/nbproject/project.xml @@ -0,0 +1,15 @@ + + + org.netbeans.modules.java.j2seproject + + + ff_22 + + + + + + + + + diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_22/src/ff_22/Main.java b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_22/src/ff_22/Main.java new file mode 100644 index 0000000..bb58127 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_22/src/ff_22/Main.java @@ -0,0 +1,35 @@ +package ff_22; + +import java.io.File; +import java.io.IOException; +import java.nio.file.FileSystems; +import java.nio.file.Files; +import java.nio.file.Path; + +/** + * + * @author Apress + */ +public class Main { + + public static void main(String[] args) { + + Path basedir = FileSystems.getDefault().getPath("C:/rafaelnadal/tmp"); + String tmp_file_prefix = "rafa_"; + String tmp_file_sufix = ".txt"; + + try { + final Path tmp_file = Files.createTempFile(basedir, tmp_file_prefix, tmp_file_sufix); + + File asFile = tmp_file.toFile(); + asFile.deleteOnExit(); + + //simulate some operations with temp file until delete it + Thread.sleep(10000); + //operations done + + } catch (IOException | InterruptedException e) { + System.err.println(e); + } + } +} diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_23/build.xml b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_23/build.xml new file mode 100644 index 0000000..1e1b54b --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_23/build.xml @@ -0,0 +1,74 @@ + + + + + + + + + + + Builds, tests, and runs the project ff_23. + + + diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_23/build/built-jar.properties b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_23/build/built-jar.properties new file mode 100644 index 0000000..4fd7540 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_23/build/built-jar.properties @@ -0,0 +1,4 @@ +#Mon, 17 Oct 2011 07:10:13 +0200 + + +C\:\\NIO\\filesandfolders\\ff_23= diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_23/build/classes/ff_23/Main.class b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_23/build/classes/ff_23/Main.class new file mode 100644 index 0000000..8f55f6b Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_23/build/classes/ff_23/Main.class differ diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_23/dist/README.TXT b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_23/dist/README.TXT new file mode 100644 index 0000000..89ceccc --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_23/dist/README.TXT @@ -0,0 +1,32 @@ +======================== +BUILD OUTPUT DESCRIPTION +======================== + +When you build an Java application project that has a main class, the IDE +automatically copies all of the JAR +files on the projects classpath to your projects dist/lib folder. The IDE +also adds each of the JAR files to the Class-Path element in the application +JAR files manifest file (MANIFEST.MF). + +To run the project from the command line, go to the dist folder and +type the following: + +java -jar "ff_23.jar" + +To distribute this project, zip up the dist folder (including the lib folder) +and distribute the ZIP file. + +Notes: + +* If two JAR files on the project classpath have the same name, only the first +JAR file is copied to the lib folder. +* Only JAR files are copied to the lib folder. +If the classpath contains other types of files or folders, these files (folders) +are not copied. +* If a library on the projects classpath also has a Class-Path element +specified in the manifest,the content of the Class-Path element has to be on +the projects runtime path. +* To set a main class in a standard Java project, right-click the project node +in the Projects window and choose Properties. Then click Run and enter the +class name in the Main Class field. Alternatively, you can manually type the +class name in the manifest Main-Class element. diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_23/dist/ff_23.jar b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_23/dist/ff_23.jar new file mode 100644 index 0000000..da465d2 Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_23/dist/ff_23.jar differ diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_23/manifest.mf b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_23/manifest.mf new file mode 100644 index 0000000..328e8e5 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_23/manifest.mf @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +X-COMMENT: Main-Class will be added automatically by build + diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_23/nbproject/build-impl.xml b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_23/nbproject/build-impl.xml new file mode 100644 index 0000000..379bf22 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_23/nbproject/build-impl.xml @@ -0,0 +1,1041 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set src.dir + Must set test.src.dir + Must set build.dir + Must set dist.dir + Must set build.classes.dir + Must set dist.javadoc.dir + Must set build.test.classes.dir + Must set build.test.results.dir + Must set build.classes.excludes + Must set dist.jar + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set JVM to use for profiling in profiler.info.jvm + Must set profiler agent JVM arguments in profiler.info.jvmargs.agent + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + + + + + + java -cp "${run.classpath.with.dist.jar}" ${main.class} + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + java -jar "${dist.jar.resolved}" + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set run.class + + + + Must select one file in the IDE or set run.class + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set debug.class + + + + + Must select one file in the IDE or set debug.class + + + + + Must set fix.includes + + + + + + + + + + + + + + + + + Must select one file in the IDE or set profile.class + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + Some tests failed; see details above. + + + + + + + + + Must select some files in the IDE or set test.includes + + + + Some tests failed; see details above. + + + + + Must select one file in the IDE or set test.class + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_23/nbproject/genfiles.properties b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_23/nbproject/genfiles.properties new file mode 100644 index 0000000..d30817f --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_23/nbproject/genfiles.properties @@ -0,0 +1,8 @@ +build.xml.data.CRC32=469938b6 +build.xml.script.CRC32=85e1e6a8 +build.xml.stylesheet.CRC32=28e38971@1.43.1.45 +# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. +# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. +nbproject/build-impl.xml.data.CRC32=469938b6 +nbproject/build-impl.xml.script.CRC32=916787d6 +nbproject/build-impl.xml.stylesheet.CRC32=0c01fd8e@1.43.1.45 diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_23/nbproject/private/config.properties b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_23/nbproject/private/config.properties new file mode 100644 index 0000000..e69de29 diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_23/nbproject/private/private.properties b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_23/nbproject/private/private.properties new file mode 100644 index 0000000..a5ab360 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_23/nbproject/private/private.properties @@ -0,0 +1,6 @@ +compile.on.save=true +do.depend=false +do.jar=true +javac.debug=true +javadoc.preview=true +user.properties.file=C:\\Users\\Leo\\.netbeans\\7.0\\build.properties diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_23/nbproject/private/private.xml b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_23/nbproject/private/private.xml new file mode 100644 index 0000000..c1f155a --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_23/nbproject/private/private.xml @@ -0,0 +1,4 @@ + + + + diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_23/nbproject/project.properties b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_23/nbproject/project.properties new file mode 100644 index 0000000..7e9ad33 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_23/nbproject/project.properties @@ -0,0 +1,72 @@ +annotation.processing.enabled=true +annotation.processing.enabled.in.editor=false +annotation.processing.run.all.processors=true +annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output +application.title=ff_23 +application.vendor=Leo +build.classes.dir=${build.dir}/classes +build.classes.excludes=**/*.java,**/*.form +# This directory is removed when the project is cleaned: +build.dir=build +build.generated.dir=${build.dir}/generated +build.generated.sources.dir=${build.dir}/generated-sources +# Only compile against the classpath explicitly listed here: +build.sysclasspath=ignore +build.test.classes.dir=${build.dir}/test/classes +build.test.results.dir=${build.dir}/test/results +# Uncomment to specify the preferred debugger connection transport: +#debug.transport=dt_socket +debug.classpath=\ + ${run.classpath} +debug.test.classpath=\ + ${run.test.classpath} +# This directory is removed when the project is cleaned: +dist.dir=dist +dist.jar=${dist.dir}/ff_23.jar +dist.javadoc.dir=${dist.dir}/javadoc +endorsed.classpath= +excludes= +includes=** +jar.compress=false +javac.classpath= +# Space-separated list of extra javac options +javac.compilerargs= +javac.deprecation=false +javac.processorpath=\ + ${javac.classpath} +javac.source=1.7 +javac.target=1.7 +javac.test.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +javac.test.processorpath=\ + ${javac.test.classpath} +javadoc.additionalparam= +javadoc.author=false +javadoc.encoding=${source.encoding} +javadoc.noindex=false +javadoc.nonavbar=false +javadoc.notree=false +javadoc.private=false +javadoc.splitindex=true +javadoc.use=true +javadoc.version=false +javadoc.windowtitle= +main.class=ff_23.Main +manifest.file=manifest.mf +meta.inf.dir=${src.dir}/META-INF +mkdist.disabled=false +platform.active=default_platform +run.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +# Space-separated list of JVM arguments used when running the project +# (you may also define separate properties like run-sys-prop.name=value instead of -Dname=value +# or test-sys-prop.name=value to set system properties for unit tests): +run.jvmargs= +run.test.classpath=\ + ${javac.test.classpath}:\ + ${build.test.classes.dir} +source.encoding=UTF-8 +src.dir=src +test.src.dir=test diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_23/nbproject/project.xml b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_23/nbproject/project.xml new file mode 100644 index 0000000..6382730 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_23/nbproject/project.xml @@ -0,0 +1,15 @@ + + + org.netbeans.modules.java.j2seproject + + + ff_23 + + + + + + + + + diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_23/src/ff_23/Main.java b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_23/src/ff_23/Main.java new file mode 100644 index 0000000..59e3635 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_23/src/ff_23/Main.java @@ -0,0 +1,42 @@ +package ff_23; + +import java.io.IOException; +import java.nio.file.FileSystems; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.StandardCopyOption; + +/** + * + * @author Apress + */ +public class Main { + + public static void main(String[] args) { + + Path movefrom = FileSystems.getDefault().getPath("C:/rafaelnadal/rafa_2.jpg"); + Path target = FileSystems.getDefault().getPath("C:/rafaelnadal/photos/rafa_2.jpg"); + Path target_dir = FileSystems.getDefault().getPath("C:/rafaelnadal/photos"); + + //method 1 + try { + Files.move(movefrom, target, StandardCopyOption.REPLACE_EXISTING); + } catch (IOException e) { + System.err.println(e); + } + + //method 2 - using resolve + try { + Files.move(movefrom, target_dir.resolve(movefrom.getFileName()), StandardCopyOption.REPLACE_EXISTING); + } catch (IOException e) { + System.err.println(e); + } + + //method 3 - using resolve to move and rename + try { + Files.move(target, target.resolveSibling("rafa_renamed_2.jpg"), StandardCopyOption.REPLACE_EXISTING); + } catch (IOException e) { + System.err.println(e); + } + } +} diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_24/build.xml b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_24/build.xml new file mode 100644 index 0000000..f5fee6a --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_24/build.xml @@ -0,0 +1,74 @@ + + + + + + + + + + + Builds, tests, and runs the project ff_24. + + + diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_24/build/built-jar.properties b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_24/build/built-jar.properties new file mode 100644 index 0000000..116716f --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_24/build/built-jar.properties @@ -0,0 +1,4 @@ +#Mon, 17 Oct 2011 07:11:49 +0200 + + +C\:\\NIO\\filesandfolders\\ff_24= diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_24/build/classes/ff_24/Main.class b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_24/build/classes/ff_24/Main.class new file mode 100644 index 0000000..e7ed438 Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_24/build/classes/ff_24/Main.class differ diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_24/dist/README.TXT b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_24/dist/README.TXT new file mode 100644 index 0000000..db9e620 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_24/dist/README.TXT @@ -0,0 +1,32 @@ +======================== +BUILD OUTPUT DESCRIPTION +======================== + +When you build an Java application project that has a main class, the IDE +automatically copies all of the JAR +files on the projects classpath to your projects dist/lib folder. The IDE +also adds each of the JAR files to the Class-Path element in the application +JAR files manifest file (MANIFEST.MF). + +To run the project from the command line, go to the dist folder and +type the following: + +java -jar "ff_24.jar" + +To distribute this project, zip up the dist folder (including the lib folder) +and distribute the ZIP file. + +Notes: + +* If two JAR files on the project classpath have the same name, only the first +JAR file is copied to the lib folder. +* Only JAR files are copied to the lib folder. +If the classpath contains other types of files or folders, these files (folders) +are not copied. +* If a library on the projects classpath also has a Class-Path element +specified in the manifest,the content of the Class-Path element has to be on +the projects runtime path. +* To set a main class in a standard Java project, right-click the project node +in the Projects window and choose Properties. Then click Run and enter the +class name in the Main Class field. Alternatively, you can manually type the +class name in the manifest Main-Class element. diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_24/dist/ff_24.jar b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_24/dist/ff_24.jar new file mode 100644 index 0000000..204d9ed Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_24/dist/ff_24.jar differ diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_24/manifest.mf b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_24/manifest.mf new file mode 100644 index 0000000..328e8e5 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_24/manifest.mf @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +X-COMMENT: Main-Class will be added automatically by build + diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_24/nbproject/build-impl.xml b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_24/nbproject/build-impl.xml new file mode 100644 index 0000000..b08d307 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_24/nbproject/build-impl.xml @@ -0,0 +1,1041 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set src.dir + Must set test.src.dir + Must set build.dir + Must set dist.dir + Must set build.classes.dir + Must set dist.javadoc.dir + Must set build.test.classes.dir + Must set build.test.results.dir + Must set build.classes.excludes + Must set dist.jar + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set JVM to use for profiling in profiler.info.jvm + Must set profiler agent JVM arguments in profiler.info.jvmargs.agent + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + + + + + + java -cp "${run.classpath.with.dist.jar}" ${main.class} + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + java -jar "${dist.jar.resolved}" + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set run.class + + + + Must select one file in the IDE or set run.class + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set debug.class + + + + + Must select one file in the IDE or set debug.class + + + + + Must set fix.includes + + + + + + + + + + + + + + + + + Must select one file in the IDE or set profile.class + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + Some tests failed; see details above. + + + + + + + + + Must select some files in the IDE or set test.includes + + + + Some tests failed; see details above. + + + + + Must select one file in the IDE or set test.class + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_24/nbproject/genfiles.properties b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_24/nbproject/genfiles.properties new file mode 100644 index 0000000..c552c21 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_24/nbproject/genfiles.properties @@ -0,0 +1,8 @@ +build.xml.data.CRC32=7ee39c44 +build.xml.script.CRC32=1ef43ff7 +build.xml.stylesheet.CRC32=28e38971@1.43.1.45 +# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. +# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. +nbproject/build-impl.xml.data.CRC32=7ee39c44 +nbproject/build-impl.xml.script.CRC32=21384635 +nbproject/build-impl.xml.stylesheet.CRC32=0c01fd8e@1.43.1.45 diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_24/nbproject/private/config.properties b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_24/nbproject/private/config.properties new file mode 100644 index 0000000..e69de29 diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_24/nbproject/private/private.properties b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_24/nbproject/private/private.properties new file mode 100644 index 0000000..a5ab360 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_24/nbproject/private/private.properties @@ -0,0 +1,6 @@ +compile.on.save=true +do.depend=false +do.jar=true +javac.debug=true +javadoc.preview=true +user.properties.file=C:\\Users\\Leo\\.netbeans\\7.0\\build.properties diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_24/nbproject/private/private.xml b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_24/nbproject/private/private.xml new file mode 100644 index 0000000..c1f155a --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_24/nbproject/private/private.xml @@ -0,0 +1,4 @@ + + + + diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_24/nbproject/project.properties b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_24/nbproject/project.properties new file mode 100644 index 0000000..0183164 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_24/nbproject/project.properties @@ -0,0 +1,72 @@ +annotation.processing.enabled=true +annotation.processing.enabled.in.editor=false +annotation.processing.run.all.processors=true +annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output +application.title=ff_24 +application.vendor=Leo +build.classes.dir=${build.dir}/classes +build.classes.excludes=**/*.java,**/*.form +# This directory is removed when the project is cleaned: +build.dir=build +build.generated.dir=${build.dir}/generated +build.generated.sources.dir=${build.dir}/generated-sources +# Only compile against the classpath explicitly listed here: +build.sysclasspath=ignore +build.test.classes.dir=${build.dir}/test/classes +build.test.results.dir=${build.dir}/test/results +# Uncomment to specify the preferred debugger connection transport: +#debug.transport=dt_socket +debug.classpath=\ + ${run.classpath} +debug.test.classpath=\ + ${run.test.classpath} +# This directory is removed when the project is cleaned: +dist.dir=dist +dist.jar=${dist.dir}/ff_24.jar +dist.javadoc.dir=${dist.dir}/javadoc +endorsed.classpath= +excludes= +includes=** +jar.compress=false +javac.classpath= +# Space-separated list of extra javac options +javac.compilerargs= +javac.deprecation=false +javac.processorpath=\ + ${javac.classpath} +javac.source=1.7 +javac.target=1.7 +javac.test.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +javac.test.processorpath=\ + ${javac.test.classpath} +javadoc.additionalparam= +javadoc.author=false +javadoc.encoding=${source.encoding} +javadoc.noindex=false +javadoc.nonavbar=false +javadoc.notree=false +javadoc.private=false +javadoc.splitindex=true +javadoc.use=true +javadoc.version=false +javadoc.windowtitle= +main.class=ff_24.Main +manifest.file=manifest.mf +meta.inf.dir=${src.dir}/META-INF +mkdist.disabled=false +platform.active=default_platform +run.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +# Space-separated list of JVM arguments used when running the project +# (you may also define separate properties like run-sys-prop.name=value instead of -Dname=value +# or test-sys-prop.name=value to set system properties for unit tests): +run.jvmargs= +run.test.classpath=\ + ${javac.test.classpath}:\ + ${build.test.classes.dir} +source.encoding=UTF-8 +src.dir=src +test.src.dir=test diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_24/nbproject/project.xml b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_24/nbproject/project.xml new file mode 100644 index 0000000..f7b2b4c --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_24/nbproject/project.xml @@ -0,0 +1,15 @@ + + + org.netbeans.modules.java.j2seproject + + + ff_24 + + + + + + + + + diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_24/src/ff_24/Main.java b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_24/src/ff_24/Main.java new file mode 100644 index 0000000..d90751d --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_24/src/ff_24/Main.java @@ -0,0 +1,54 @@ +package ff_24; + +import java.io.BufferedWriter; +import java.io.IOException; +import java.io.OutputStream; +import java.io.OutputStreamWriter; +import java.nio.file.FileSystems; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.StandardOpenOption; + +/** + * + * @author apress + */ +public class Main { + + public static void main(String[] args) { + + Path basedir = FileSystems.getDefault().getPath("C:/rafaelnadal/tmp"); + String tmp_file_prefix = "rafa_"; + String tmp_file_sufix = ".txt"; + Path tmp_file = null; + + //solution 1 + try { + tmp_file = Files.createTempFile(basedir, tmp_file_prefix, tmp_file_sufix); + } catch (IOException e) { + System.err.println(e); + } + + try (OutputStream outputStream = Files.newOutputStream(tmp_file, StandardOpenOption.DELETE_ON_CLOSE); + BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(outputStream))) { + //simulate some operations with temp file until delete it + Thread.sleep(10000); + //operations done + } catch (IOException | InterruptedException e) { + System.err.println(e); + } + + //solution 2 + tmp_file = FileSystems.getDefault().getPath("C:/rafaelnadal/tmp", tmp_file_prefix + "temporary" + tmp_file_sufix); + + try (OutputStream outputStream = Files.newOutputStream(tmp_file, StandardOpenOption.CREATE, StandardOpenOption.DELETE_ON_CLOSE); + BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(outputStream))) { + //simulate some operations with temp file until delete it + Thread.sleep(10000); + //operations done + } catch (IOException | InterruptedException e) { + System.err.println(e); + } + + } +} diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_25/build.xml b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_25/build.xml new file mode 100644 index 0000000..9dc2e56 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_25/build.xml @@ -0,0 +1,74 @@ + + + + + + + + + + + Builds, tests, and runs the project ff_25. + + + diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_25/build/built-jar.properties b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_25/build/built-jar.properties new file mode 100644 index 0000000..c46e472 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_25/build/built-jar.properties @@ -0,0 +1,4 @@ +#Mon, 17 Oct 2011 07:12:40 +0200 + + +C\:\\NIO\\filesandfolders\\ff_25= diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_25/build/classes/.netbeans_automatic_build b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_25/build/classes/.netbeans_automatic_build new file mode 100644 index 0000000..e69de29 diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_25/build/classes/ff_25/Main.class b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_25/build/classes/ff_25/Main.class new file mode 100644 index 0000000..3c72806 Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_25/build/classes/ff_25/Main.class differ diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_25/dist/README.TXT b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_25/dist/README.TXT new file mode 100644 index 0000000..0289a5a --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_25/dist/README.TXT @@ -0,0 +1,32 @@ +======================== +BUILD OUTPUT DESCRIPTION +======================== + +When you build an Java application project that has a main class, the IDE +automatically copies all of the JAR +files on the projects classpath to your projects dist/lib folder. The IDE +also adds each of the JAR files to the Class-Path element in the application +JAR files manifest file (MANIFEST.MF). + +To run the project from the command line, go to the dist folder and +type the following: + +java -jar "ff_25.jar" + +To distribute this project, zip up the dist folder (including the lib folder) +and distribute the ZIP file. + +Notes: + +* If two JAR files on the project classpath have the same name, only the first +JAR file is copied to the lib folder. +* Only JAR files are copied to the lib folder. +If the classpath contains other types of files or folders, these files (folders) +are not copied. +* If a library on the projects classpath also has a Class-Path element +specified in the manifest,the content of the Class-Path element has to be on +the projects runtime path. +* To set a main class in a standard Java project, right-click the project node +in the Projects window and choose Properties. Then click Run and enter the +class name in the Main Class field. Alternatively, you can manually type the +class name in the manifest Main-Class element. diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_25/dist/ff_25.jar b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_25/dist/ff_25.jar new file mode 100644 index 0000000..486015f Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_25/dist/ff_25.jar differ diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_25/manifest.mf b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_25/manifest.mf new file mode 100644 index 0000000..328e8e5 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_25/manifest.mf @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +X-COMMENT: Main-Class will be added automatically by build + diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_25/nbproject/build-impl.xml b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_25/nbproject/build-impl.xml new file mode 100644 index 0000000..28ab223 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_25/nbproject/build-impl.xml @@ -0,0 +1,1041 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set src.dir + Must set test.src.dir + Must set build.dir + Must set dist.dir + Must set build.classes.dir + Must set dist.javadoc.dir + Must set build.test.classes.dir + Must set build.test.results.dir + Must set build.classes.excludes + Must set dist.jar + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set JVM to use for profiling in profiler.info.jvm + Must set profiler agent JVM arguments in profiler.info.jvmargs.agent + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + + + + + + java -cp "${run.classpath.with.dist.jar}" ${main.class} + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + java -jar "${dist.jar.resolved}" + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set run.class + + + + Must select one file in the IDE or set run.class + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set debug.class + + + + + Must select one file in the IDE or set debug.class + + + + + Must set fix.includes + + + + + + + + + + + + + + + + + Must select one file in the IDE or set profile.class + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + Some tests failed; see details above. + + + + + + + + + Must select some files in the IDE or set test.includes + + + + Some tests failed; see details above. + + + + + Must select one file in the IDE or set test.class + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_25/nbproject/genfiles.properties b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_25/nbproject/genfiles.properties new file mode 100644 index 0000000..2da0a19 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_25/nbproject/genfiles.properties @@ -0,0 +1,8 @@ +build.xml.data.CRC32=76f01062 +build.xml.script.CRC32=e218cf73 +build.xml.stylesheet.CRC32=28e38971@1.43.1.45 +# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. +# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. +nbproject/build-impl.xml.data.CRC32=76f01062 +nbproject/build-impl.xml.script.CRC32=96b1b24e +nbproject/build-impl.xml.stylesheet.CRC32=0c01fd8e@1.43.1.45 diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_25/nbproject/private/config.properties b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_25/nbproject/private/config.properties new file mode 100644 index 0000000..e69de29 diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_25/nbproject/private/private.properties b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_25/nbproject/private/private.properties new file mode 100644 index 0000000..a5ab360 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_25/nbproject/private/private.properties @@ -0,0 +1,6 @@ +compile.on.save=true +do.depend=false +do.jar=true +javac.debug=true +javadoc.preview=true +user.properties.file=C:\\Users\\Leo\\.netbeans\\7.0\\build.properties diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_25/nbproject/private/private.xml b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_25/nbproject/private/private.xml new file mode 100644 index 0000000..c1f155a --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_25/nbproject/private/private.xml @@ -0,0 +1,4 @@ + + + + diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_25/nbproject/project.properties b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_25/nbproject/project.properties new file mode 100644 index 0000000..d4448b3 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_25/nbproject/project.properties @@ -0,0 +1,72 @@ +annotation.processing.enabled=true +annotation.processing.enabled.in.editor=false +annotation.processing.run.all.processors=true +annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output +application.title=ff_25 +application.vendor=Leo +build.classes.dir=${build.dir}/classes +build.classes.excludes=**/*.java,**/*.form +# This directory is removed when the project is cleaned: +build.dir=build +build.generated.dir=${build.dir}/generated +build.generated.sources.dir=${build.dir}/generated-sources +# Only compile against the classpath explicitly listed here: +build.sysclasspath=ignore +build.test.classes.dir=${build.dir}/test/classes +build.test.results.dir=${build.dir}/test/results +# Uncomment to specify the preferred debugger connection transport: +#debug.transport=dt_socket +debug.classpath=\ + ${run.classpath} +debug.test.classpath=\ + ${run.test.classpath} +# This directory is removed when the project is cleaned: +dist.dir=dist +dist.jar=${dist.dir}/ff_25.jar +dist.javadoc.dir=${dist.dir}/javadoc +endorsed.classpath= +excludes= +includes=** +jar.compress=false +javac.classpath= +# Space-separated list of extra javac options +javac.compilerargs= +javac.deprecation=false +javac.processorpath=\ + ${javac.classpath} +javac.source=1.7 +javac.target=1.7 +javac.test.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +javac.test.processorpath=\ + ${javac.test.classpath} +javadoc.additionalparam= +javadoc.author=false +javadoc.encoding=${source.encoding} +javadoc.noindex=false +javadoc.nonavbar=false +javadoc.notree=false +javadoc.private=false +javadoc.splitindex=true +javadoc.use=true +javadoc.version=false +javadoc.windowtitle= +main.class=ff_25.Main +manifest.file=manifest.mf +meta.inf.dir=${src.dir}/META-INF +mkdist.disabled=false +platform.active=default_platform +run.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +# Space-separated list of JVM arguments used when running the project +# (you may also define separate properties like run-sys-prop.name=value instead of -Dname=value +# or test-sys-prop.name=value to set system properties for unit tests): +run.jvmargs= +run.test.classpath=\ + ${javac.test.classpath}:\ + ${build.test.classes.dir} +source.encoding=UTF-8 +src.dir=src +test.src.dir=test diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_25/nbproject/project.xml b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_25/nbproject/project.xml new file mode 100644 index 0000000..8d06e27 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_25/nbproject/project.xml @@ -0,0 +1,15 @@ + + + org.netbeans.modules.java.j2seproject + + + ff_25 + + + + + + + + + diff --git a/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_25/src/ff_25/Main.java b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_25/src/ff_25/Main.java new file mode 100644 index 0000000..f25d7a7 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter04/filesandfolders/ff_25/src/ff_25/Main.java @@ -0,0 +1,28 @@ +package ff_25; + +import java.nio.file.FileSystems; +import java.nio.file.Path; +import java.util.ArrayList; + +/** + * + * @author Apress + */ +public class Main { + + public static void main(String[] args) { + + Iterable dirs = FileSystems.getDefault().getRootDirectories(); + ArrayList list = new ArrayList(); + for (Path name : dirs) { + //System.out.println(name); + list.add(name); + } + Path[] arr = new Path[list.size()]; + list.toArray(arr); + + for (Path path : arr) { + System.out.println(path); + } + } +} diff --git a/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_01/build.xml b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_01/build.xml new file mode 100644 index 0000000..bcd52c0 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_01/build.xml @@ -0,0 +1,74 @@ + + + + + + + + + + + Builds, tests, and runs the project fv_01. + + + diff --git a/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_01/build/built-jar.properties b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_01/build/built-jar.properties new file mode 100644 index 0000000..93bacdd --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_01/build/built-jar.properties @@ -0,0 +1,4 @@ +#Mon, 17 Oct 2011 08:54:28 +0200 + + +C\:\\NIO\\filevisitor\\fv_01= diff --git a/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_01/build/classes/fv_01/Main.class b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_01/build/classes/fv_01/Main.class new file mode 100644 index 0000000..67e9830 Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_01/build/classes/fv_01/Main.class differ diff --git a/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_01/build/classes/fv_01/Search.class b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_01/build/classes/fv_01/Search.class new file mode 100644 index 0000000..152b021 Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_01/build/classes/fv_01/Search.class differ diff --git a/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_01/dist/README.TXT b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_01/dist/README.TXT new file mode 100644 index 0000000..aff7cba --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_01/dist/README.TXT @@ -0,0 +1,32 @@ +======================== +BUILD OUTPUT DESCRIPTION +======================== + +When you build an Java application project that has a main class, the IDE +automatically copies all of the JAR +files on the projects classpath to your projects dist/lib folder. The IDE +also adds each of the JAR files to the Class-Path element in the application +JAR files manifest file (MANIFEST.MF). + +To run the project from the command line, go to the dist folder and +type the following: + +java -jar "fv_01.jar" + +To distribute this project, zip up the dist folder (including the lib folder) +and distribute the ZIP file. + +Notes: + +* If two JAR files on the project classpath have the same name, only the first +JAR file is copied to the lib folder. +* Only JAR files are copied to the lib folder. +If the classpath contains other types of files or folders, these files (folders) +are not copied. +* If a library on the projects classpath also has a Class-Path element +specified in the manifest,the content of the Class-Path element has to be on +the projects runtime path. +* To set a main class in a standard Java project, right-click the project node +in the Projects window and choose Properties. Then click Run and enter the +class name in the Main Class field. Alternatively, you can manually type the +class name in the manifest Main-Class element. diff --git a/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_01/dist/fv_01.jar b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_01/dist/fv_01.jar new file mode 100644 index 0000000..4fb52d9 Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_01/dist/fv_01.jar differ diff --git a/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_01/manifest.mf b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_01/manifest.mf new file mode 100644 index 0000000..328e8e5 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_01/manifest.mf @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +X-COMMENT: Main-Class will be added automatically by build + diff --git a/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_01/nbproject/build-impl.xml b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_01/nbproject/build-impl.xml new file mode 100644 index 0000000..f456f57 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_01/nbproject/build-impl.xml @@ -0,0 +1,1041 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set src.dir + Must set test.src.dir + Must set build.dir + Must set dist.dir + Must set build.classes.dir + Must set dist.javadoc.dir + Must set build.test.classes.dir + Must set build.test.results.dir + Must set build.classes.excludes + Must set dist.jar + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set JVM to use for profiling in profiler.info.jvm + Must set profiler agent JVM arguments in profiler.info.jvmargs.agent + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + + + + + + java -cp "${run.classpath.with.dist.jar}" ${main.class} + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + java -jar "${dist.jar.resolved}" + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set run.class + + + + Must select one file in the IDE or set run.class + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set debug.class + + + + + Must select one file in the IDE or set debug.class + + + + + Must set fix.includes + + + + + + + + + + + + + + + + + Must select one file in the IDE or set profile.class + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + Some tests failed; see details above. + + + + + + + + + Must select some files in the IDE or set test.includes + + + + Some tests failed; see details above. + + + + + Must select one file in the IDE or set test.class + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_01/nbproject/genfiles.properties b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_01/nbproject/genfiles.properties new file mode 100644 index 0000000..315e15c --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_01/nbproject/genfiles.properties @@ -0,0 +1,8 @@ +build.xml.data.CRC32=b0ddccaa +build.xml.script.CRC32=1bf38715 +build.xml.stylesheet.CRC32=28e38971@1.43.1.45 +# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. +# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. +nbproject/build-impl.xml.data.CRC32=b0ddccaa +nbproject/build-impl.xml.script.CRC32=6a628fdf +nbproject/build-impl.xml.stylesheet.CRC32=0c01fd8e@1.43.1.45 diff --git a/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_01/nbproject/private/config.properties b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_01/nbproject/private/config.properties new file mode 100644 index 0000000..e69de29 diff --git a/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_01/nbproject/private/private.properties b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_01/nbproject/private/private.properties new file mode 100644 index 0000000..a5ab360 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_01/nbproject/private/private.properties @@ -0,0 +1,6 @@ +compile.on.save=true +do.depend=false +do.jar=true +javac.debug=true +javadoc.preview=true +user.properties.file=C:\\Users\\Leo\\.netbeans\\7.0\\build.properties diff --git a/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_01/nbproject/private/private.xml b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_01/nbproject/private/private.xml new file mode 100644 index 0000000..c1f155a --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_01/nbproject/private/private.xml @@ -0,0 +1,4 @@ + + + + diff --git a/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_01/nbproject/project.properties b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_01/nbproject/project.properties new file mode 100644 index 0000000..db56b56 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_01/nbproject/project.properties @@ -0,0 +1,72 @@ +annotation.processing.enabled=true +annotation.processing.enabled.in.editor=false +annotation.processing.run.all.processors=true +annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output +application.title=fv_01 +application.vendor=Leo +build.classes.dir=${build.dir}/classes +build.classes.excludes=**/*.java,**/*.form +# This directory is removed when the project is cleaned: +build.dir=build +build.generated.dir=${build.dir}/generated +build.generated.sources.dir=${build.dir}/generated-sources +# Only compile against the classpath explicitly listed here: +build.sysclasspath=ignore +build.test.classes.dir=${build.dir}/test/classes +build.test.results.dir=${build.dir}/test/results +# Uncomment to specify the preferred debugger connection transport: +#debug.transport=dt_socket +debug.classpath=\ + ${run.classpath} +debug.test.classpath=\ + ${run.test.classpath} +# This directory is removed when the project is cleaned: +dist.dir=dist +dist.jar=${dist.dir}/fv_01.jar +dist.javadoc.dir=${dist.dir}/javadoc +endorsed.classpath= +excludes= +includes=** +jar.compress=false +javac.classpath= +# Space-separated list of extra javac options +javac.compilerargs= +javac.deprecation=false +javac.processorpath=\ + ${javac.classpath} +javac.source=1.7 +javac.target=1.7 +javac.test.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +javac.test.processorpath=\ + ${javac.test.classpath} +javadoc.additionalparam= +javadoc.author=false +javadoc.encoding=${source.encoding} +javadoc.noindex=false +javadoc.nonavbar=false +javadoc.notree=false +javadoc.private=false +javadoc.splitindex=true +javadoc.use=true +javadoc.version=false +javadoc.windowtitle= +main.class=fv_01.Main +manifest.file=manifest.mf +meta.inf.dir=${src.dir}/META-INF +mkdist.disabled=false +platform.active=default_platform +run.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +# Space-separated list of JVM arguments used when running the project +# (you may also define separate properties like run-sys-prop.name=value instead of -Dname=value +# or test-sys-prop.name=value to set system properties for unit tests): +run.jvmargs= +run.test.classpath=\ + ${javac.test.classpath}:\ + ${build.test.classes.dir} +source.encoding=UTF-8 +src.dir=src +test.src.dir=test diff --git a/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_01/nbproject/project.xml b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_01/nbproject/project.xml new file mode 100644 index 0000000..101090c --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_01/nbproject/project.xml @@ -0,0 +1,15 @@ + + + org.netbeans.modules.java.j2seproject + + + fv_01 + + + + + + + + + diff --git a/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_01/src/fv_01/Main.java b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_01/src/fv_01/Main.java new file mode 100644 index 0000000..0025bcb --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_01/src/fv_01/Main.java @@ -0,0 +1,82 @@ +package fv_01; + +import java.io.IOException; +import java.nio.file.FileSystems; +import java.nio.file.FileVisitOption; +import java.nio.file.FileVisitResult; +import java.nio.file.FileVisitor; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.nio.file.attribute.BasicFileAttributes; +import java.util.EnumSet; + +/** + * + * @author Apress + */ +class Search implements FileVisitor { + + private final Path searchedFile; + public boolean found; + + public Search(Path searchedFile) { + this.searchedFile = searchedFile; + this.found = false; + } + + void search(Path file) throws IOException { + Path name = file.getFileName(); + if (name != null && name.equals(searchedFile)) { + System.out.println("Searched file was found: " + searchedFile + " in " + file.toRealPath().toString()); + found = true; + } + } + + @Override + public FileVisitResult postVisitDirectory(Object dir, IOException exc) throws IOException { + System.out.println("Visited: " + (Path) dir); + return FileVisitResult.CONTINUE; + } + + @Override + public FileVisitResult preVisitDirectory(Object dir, BasicFileAttributes attrs) throws IOException { + return FileVisitResult.CONTINUE; + } + + @Override + public FileVisitResult visitFile(Object file, BasicFileAttributes attrs) throws IOException { + search((Path) file); + if (!found) { + return FileVisitResult.CONTINUE; + } else { + return FileVisitResult.TERMINATE; + } + } + + @Override + public FileVisitResult visitFileFailed(Object file, IOException exc) throws IOException { + return FileVisitResult.CONTINUE; + } +} + +class Main { + + public static void main(String[] args) throws IOException { + + Path searchFile = Paths.get("rafa_1.jpg"); + Search walk = new Search(searchFile); + EnumSet opts = EnumSet.of(FileVisitOption.FOLLOW_LINKS); + + Iterable dirs = FileSystems.getDefault().getRootDirectories(); + for (Path root : dirs) { + if (!walk.found) { + Files.walkFileTree(root, opts, Integer.MAX_VALUE, walk); + } + } + + if (!walk.found) { + System.out.println("The file " + searchFile + " was not found!"); + } + } +} diff --git a/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_02/build.xml b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_02/build.xml new file mode 100644 index 0000000..632d529 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_02/build.xml @@ -0,0 +1,74 @@ + + + + + + + + + + + Builds, tests, and runs the project fv_02. + + + diff --git a/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_02/build/built-jar.properties b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_02/build/built-jar.properties new file mode 100644 index 0000000..29b1397 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_02/build/built-jar.properties @@ -0,0 +1,4 @@ +#Mon, 17 Oct 2011 09:04:54 +0200 + + +C\:\\NIO\\filevisitor\\fv_02= diff --git a/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_02/build/classes/.netbeans_automatic_build b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_02/build/classes/.netbeans_automatic_build new file mode 100644 index 0000000..e69de29 diff --git a/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_02/build/classes/fv_02/Main.class b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_02/build/classes/fv_02/Main.class new file mode 100644 index 0000000..0d1e11d Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_02/build/classes/fv_02/Main.class differ diff --git a/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_02/build/classes/fv_02/Main.rs b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_02/build/classes/fv_02/Main.rs new file mode 100644 index 0000000..99be4a2 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_02/build/classes/fv_02/Main.rs @@ -0,0 +1,2 @@ +fv_02.Search +fv_02.Main diff --git a/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_02/build/classes/fv_02/Search.class b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_02/build/classes/fv_02/Search.class new file mode 100644 index 0000000..5a454b1 Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_02/build/classes/fv_02/Search.class differ diff --git a/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_02/dist/README.TXT b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_02/dist/README.TXT new file mode 100644 index 0000000..1247588 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_02/dist/README.TXT @@ -0,0 +1,32 @@ +======================== +BUILD OUTPUT DESCRIPTION +======================== + +When you build an Java application project that has a main class, the IDE +automatically copies all of the JAR +files on the projects classpath to your projects dist/lib folder. The IDE +also adds each of the JAR files to the Class-Path element in the application +JAR files manifest file (MANIFEST.MF). + +To run the project from the command line, go to the dist folder and +type the following: + +java -jar "fv_02.jar" + +To distribute this project, zip up the dist folder (including the lib folder) +and distribute the ZIP file. + +Notes: + +* If two JAR files on the project classpath have the same name, only the first +JAR file is copied to the lib folder. +* Only JAR files are copied to the lib folder. +If the classpath contains other types of files or folders, these files (folders) +are not copied. +* If a library on the projects classpath also has a Class-Path element +specified in the manifest,the content of the Class-Path element has to be on +the projects runtime path. +* To set a main class in a standard Java project, right-click the project node +in the Projects window and choose Properties. Then click Run and enter the +class name in the Main Class field. Alternatively, you can manually type the +class name in the manifest Main-Class element. diff --git a/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_02/dist/fv_02.jar b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_02/dist/fv_02.jar new file mode 100644 index 0000000..a7382ed Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_02/dist/fv_02.jar differ diff --git a/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_02/manifest.mf b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_02/manifest.mf new file mode 100644 index 0000000..328e8e5 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_02/manifest.mf @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +X-COMMENT: Main-Class will be added automatically by build + diff --git a/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_02/nbproject/build-impl.xml b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_02/nbproject/build-impl.xml new file mode 100644 index 0000000..6e0d2bd --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_02/nbproject/build-impl.xml @@ -0,0 +1,1041 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set src.dir + Must set test.src.dir + Must set build.dir + Must set dist.dir + Must set build.classes.dir + Must set dist.javadoc.dir + Must set build.test.classes.dir + Must set build.test.results.dir + Must set build.classes.excludes + Must set dist.jar + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set JVM to use for profiling in profiler.info.jvm + Must set profiler agent JVM arguments in profiler.info.jvmargs.agent + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + + + + + + java -cp "${run.classpath.with.dist.jar}" ${main.class} + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + java -jar "${dist.jar.resolved}" + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set run.class + + + + Must select one file in the IDE or set run.class + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set debug.class + + + + + Must select one file in the IDE or set debug.class + + + + + Must set fix.includes + + + + + + + + + + + + + + + + + Must select one file in the IDE or set profile.class + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + Some tests failed; see details above. + + + + + + + + + Must select some files in the IDE or set test.includes + + + + Some tests failed; see details above. + + + + + Must select one file in the IDE or set test.class + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_02/nbproject/genfiles.properties b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_02/nbproject/genfiles.properties new file mode 100644 index 0000000..6785e2c --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_02/nbproject/genfiles.properties @@ -0,0 +1,8 @@ +build.xml.data.CRC32=a8e958c0 +build.xml.script.CRC32=c5b790d8 +build.xml.stylesheet.CRC32=28e38971@1.43.1.45 +# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. +# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. +nbproject/build-impl.xml.data.CRC32=a8e958c0 +nbproject/build-impl.xml.script.CRC32=69899513 +nbproject/build-impl.xml.stylesheet.CRC32=0c01fd8e@1.43.1.45 diff --git a/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_02/nbproject/private/config.properties b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_02/nbproject/private/config.properties new file mode 100644 index 0000000..e69de29 diff --git a/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_02/nbproject/private/private.properties b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_02/nbproject/private/private.properties new file mode 100644 index 0000000..a5ab360 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_02/nbproject/private/private.properties @@ -0,0 +1,6 @@ +compile.on.save=true +do.depend=false +do.jar=true +javac.debug=true +javadoc.preview=true +user.properties.file=C:\\Users\\Leo\\.netbeans\\7.0\\build.properties diff --git a/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_02/nbproject/private/private.xml b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_02/nbproject/private/private.xml new file mode 100644 index 0000000..c1f155a --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_02/nbproject/private/private.xml @@ -0,0 +1,4 @@ + + + + diff --git a/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_02/nbproject/project.properties b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_02/nbproject/project.properties new file mode 100644 index 0000000..9cd711d --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_02/nbproject/project.properties @@ -0,0 +1,72 @@ +annotation.processing.enabled=true +annotation.processing.enabled.in.editor=false +annotation.processing.run.all.processors=true +annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output +application.title=fv_02 +application.vendor=Leo +build.classes.dir=${build.dir}/classes +build.classes.excludes=**/*.java,**/*.form +# This directory is removed when the project is cleaned: +build.dir=build +build.generated.dir=${build.dir}/generated +build.generated.sources.dir=${build.dir}/generated-sources +# Only compile against the classpath explicitly listed here: +build.sysclasspath=ignore +build.test.classes.dir=${build.dir}/test/classes +build.test.results.dir=${build.dir}/test/results +# Uncomment to specify the preferred debugger connection transport: +#debug.transport=dt_socket +debug.classpath=\ + ${run.classpath} +debug.test.classpath=\ + ${run.test.classpath} +# This directory is removed when the project is cleaned: +dist.dir=dist +dist.jar=${dist.dir}/fv_02.jar +dist.javadoc.dir=${dist.dir}/javadoc +endorsed.classpath= +excludes= +includes=** +jar.compress=false +javac.classpath= +# Space-separated list of extra javac options +javac.compilerargs= +javac.deprecation=false +javac.processorpath=\ + ${javac.classpath} +javac.source=1.7 +javac.target=1.7 +javac.test.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +javac.test.processorpath=\ + ${javac.test.classpath} +javadoc.additionalparam= +javadoc.author=false +javadoc.encoding=${source.encoding} +javadoc.noindex=false +javadoc.nonavbar=false +javadoc.notree=false +javadoc.private=false +javadoc.splitindex=true +javadoc.use=true +javadoc.version=false +javadoc.windowtitle= +main.class=fv_02.Main +manifest.file=manifest.mf +meta.inf.dir=${src.dir}/META-INF +mkdist.disabled=false +platform.active=default_platform +run.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +# Space-separated list of JVM arguments used when running the project +# (you may also define separate properties like run-sys-prop.name=value instead of -Dname=value +# or test-sys-prop.name=value to set system properties for unit tests): +run.jvmargs= +run.test.classpath=\ + ${javac.test.classpath}:\ + ${build.test.classes.dir} +source.encoding=UTF-8 +src.dir=src +test.src.dir=test diff --git a/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_02/nbproject/project.xml b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_02/nbproject/project.xml new file mode 100644 index 0000000..4304aea --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_02/nbproject/project.xml @@ -0,0 +1,15 @@ + + + org.netbeans.modules.java.j2seproject + + + fv_02 + + + + + + + + + diff --git a/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_02/src/fv_02/Main.java b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_02/src/fv_02/Main.java new file mode 100644 index 0000000..985885f --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_02/src/fv_02/Main.java @@ -0,0 +1,69 @@ +package fv_02; + +import java.io.IOException; +import java.nio.file.FileSystems; +import java.nio.file.FileVisitOption; +import java.nio.file.FileVisitResult; +import java.nio.file.FileVisitor; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.PathMatcher; +import java.nio.file.Paths; +import java.nio.file.attribute.BasicFileAttributes; +import java.util.EnumSet; + +/** + * + * @author Apress + */ +class Search implements FileVisitor { + + private final PathMatcher matcher; + + public Search(String glob) { + matcher = FileSystems.getDefault().getPathMatcher("glob:" + glob); + } + + void search(Path file) throws IOException { + Path name = file.getFileName(); + if (name != null && matcher.matches(name)) { + System.out.println("Searched file was found: " + name + " in " + file.toRealPath().toString()); + } + } + + @Override + public FileVisitResult postVisitDirectory(Object dir, IOException exc) throws IOException { + System.out.println("Visited: " + (Path) dir); + return FileVisitResult.CONTINUE; + } + + @Override + public FileVisitResult preVisitDirectory(Object dir, BasicFileAttributes attrs) throws IOException { + return FileVisitResult.CONTINUE; + } + + @Override + public FileVisitResult visitFile(Object file, BasicFileAttributes attrs) throws IOException { + search((Path) file); + return FileVisitResult.CONTINUE; + } + + @Override + public FileVisitResult visitFileFailed(Object file, IOException exc) throws IOException { + return FileVisitResult.CONTINUE; + } +} + +class Main { + + public static void main(String[] args) throws IOException { + + String glob = "*.jpg"; + Path fileTree = Paths.get("C:/rafaelnadal/"); + Search walk = new Search(glob); + EnumSet opts = EnumSet.of(FileVisitOption.FOLLOW_LINKS); + + Files.walkFileTree(fileTree, opts, Integer.MAX_VALUE, walk); + + } +} diff --git a/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_03/build.xml b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_03/build.xml new file mode 100644 index 0000000..f5b3ed8 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_03/build.xml @@ -0,0 +1,74 @@ + + + + + + + + + + + Builds, tests, and runs the project fv_03. + + + diff --git a/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_03/build/built-jar.properties b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_03/build/built-jar.properties new file mode 100644 index 0000000..e9462e2 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_03/build/built-jar.properties @@ -0,0 +1,4 @@ +#Mon, 17 Oct 2011 09:09:11 +0200 + + +C\:\\NIO\\filevisitor\\fv_03= diff --git a/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_03/build/classes/fv_03/Main.class b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_03/build/classes/fv_03/Main.class new file mode 100644 index 0000000..f562fdd Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_03/build/classes/fv_03/Main.class differ diff --git a/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_03/build/classes/fv_03/Search.class b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_03/build/classes/fv_03/Search.class new file mode 100644 index 0000000..4f88a93 Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_03/build/classes/fv_03/Search.class differ diff --git a/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_03/dist/README.TXT b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_03/dist/README.TXT new file mode 100644 index 0000000..834ed17 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_03/dist/README.TXT @@ -0,0 +1,32 @@ +======================== +BUILD OUTPUT DESCRIPTION +======================== + +When you build an Java application project that has a main class, the IDE +automatically copies all of the JAR +files on the projects classpath to your projects dist/lib folder. The IDE +also adds each of the JAR files to the Class-Path element in the application +JAR files manifest file (MANIFEST.MF). + +To run the project from the command line, go to the dist folder and +type the following: + +java -jar "fv_03.jar" + +To distribute this project, zip up the dist folder (including the lib folder) +and distribute the ZIP file. + +Notes: + +* If two JAR files on the project classpath have the same name, only the first +JAR file is copied to the lib folder. +* Only JAR files are copied to the lib folder. +If the classpath contains other types of files or folders, these files (folders) +are not copied. +* If a library on the projects classpath also has a Class-Path element +specified in the manifest,the content of the Class-Path element has to be on +the projects runtime path. +* To set a main class in a standard Java project, right-click the project node +in the Projects window and choose Properties. Then click Run and enter the +class name in the Main Class field. Alternatively, you can manually type the +class name in the manifest Main-Class element. diff --git a/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_03/dist/fv_03.jar b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_03/dist/fv_03.jar new file mode 100644 index 0000000..c8fe3e5 Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_03/dist/fv_03.jar differ diff --git a/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_03/manifest.mf b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_03/manifest.mf new file mode 100644 index 0000000..328e8e5 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_03/manifest.mf @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +X-COMMENT: Main-Class will be added automatically by build + diff --git a/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_03/nbproject/build-impl.xml b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_03/nbproject/build-impl.xml new file mode 100644 index 0000000..11aa2a0 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_03/nbproject/build-impl.xml @@ -0,0 +1,1041 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set src.dir + Must set test.src.dir + Must set build.dir + Must set dist.dir + Must set build.classes.dir + Must set dist.javadoc.dir + Must set build.test.classes.dir + Must set build.test.results.dir + Must set build.classes.excludes + Must set dist.jar + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set JVM to use for profiling in profiler.info.jvm + Must set profiler agent JVM arguments in profiler.info.jvmargs.agent + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + + + + + + java -cp "${run.classpath.with.dist.jar}" ${main.class} + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + java -jar "${dist.jar.resolved}" + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set run.class + + + + Must select one file in the IDE or set run.class + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set debug.class + + + + + Must select one file in the IDE or set debug.class + + + + + Must set fix.includes + + + + + + + + + + + + + + + + + Must select one file in the IDE or set profile.class + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + Some tests failed; see details above. + + + + + + + + + Must select some files in the IDE or set test.includes + + + + Some tests failed; see details above. + + + + + Must select one file in the IDE or set test.class + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_03/nbproject/genfiles.properties b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_03/nbproject/genfiles.properties new file mode 100644 index 0000000..67eb88c --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_03/nbproject/genfiles.properties @@ -0,0 +1,8 @@ +build.xml.data.CRC32=a0fad4e6 +build.xml.script.CRC32=395b605c +build.xml.stylesheet.CRC32=28e38971@1.43.1.45 +# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. +# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. +nbproject/build-impl.xml.data.CRC32=a0fad4e6 +nbproject/build-impl.xml.script.CRC32=de006168 +nbproject/build-impl.xml.stylesheet.CRC32=0c01fd8e@1.43.1.45 diff --git a/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_03/nbproject/private/config.properties b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_03/nbproject/private/config.properties new file mode 100644 index 0000000..e69de29 diff --git a/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_03/nbproject/private/private.properties b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_03/nbproject/private/private.properties new file mode 100644 index 0000000..a5ab360 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_03/nbproject/private/private.properties @@ -0,0 +1,6 @@ +compile.on.save=true +do.depend=false +do.jar=true +javac.debug=true +javadoc.preview=true +user.properties.file=C:\\Users\\Leo\\.netbeans\\7.0\\build.properties diff --git a/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_03/nbproject/private/private.xml b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_03/nbproject/private/private.xml new file mode 100644 index 0000000..c1f155a --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_03/nbproject/private/private.xml @@ -0,0 +1,4 @@ + + + + diff --git a/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_03/nbproject/project.properties b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_03/nbproject/project.properties new file mode 100644 index 0000000..9f5eae8 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_03/nbproject/project.properties @@ -0,0 +1,72 @@ +annotation.processing.enabled=true +annotation.processing.enabled.in.editor=false +annotation.processing.run.all.processors=true +annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output +application.title=fv_03 +application.vendor=Leo +build.classes.dir=${build.dir}/classes +build.classes.excludes=**/*.java,**/*.form +# This directory is removed when the project is cleaned: +build.dir=build +build.generated.dir=${build.dir}/generated +build.generated.sources.dir=${build.dir}/generated-sources +# Only compile against the classpath explicitly listed here: +build.sysclasspath=ignore +build.test.classes.dir=${build.dir}/test/classes +build.test.results.dir=${build.dir}/test/results +# Uncomment to specify the preferred debugger connection transport: +#debug.transport=dt_socket +debug.classpath=\ + ${run.classpath} +debug.test.classpath=\ + ${run.test.classpath} +# This directory is removed when the project is cleaned: +dist.dir=dist +dist.jar=${dist.dir}/fv_03.jar +dist.javadoc.dir=${dist.dir}/javadoc +endorsed.classpath= +excludes= +includes=** +jar.compress=false +javac.classpath= +# Space-separated list of extra javac options +javac.compilerargs= +javac.deprecation=false +javac.processorpath=\ + ${javac.classpath} +javac.source=1.7 +javac.target=1.7 +javac.test.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +javac.test.processorpath=\ + ${javac.test.classpath} +javadoc.additionalparam= +javadoc.author=false +javadoc.encoding=${source.encoding} +javadoc.noindex=false +javadoc.nonavbar=false +javadoc.notree=false +javadoc.private=false +javadoc.splitindex=true +javadoc.use=true +javadoc.version=false +javadoc.windowtitle= +main.class=fv_03.Main +manifest.file=manifest.mf +meta.inf.dir=${src.dir}/META-INF +mkdist.disabled=false +platform.active=default_platform +run.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +# Space-separated list of JVM arguments used when running the project +# (you may also define separate properties like run-sys-prop.name=value instead of -Dname=value +# or test-sys-prop.name=value to set system properties for unit tests): +run.jvmargs= +run.test.classpath=\ + ${javac.test.classpath}:\ + ${build.test.classes.dir} +source.encoding=UTF-8 +src.dir=src +test.src.dir=test diff --git a/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_03/nbproject/project.xml b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_03/nbproject/project.xml new file mode 100644 index 0000000..b42ccba --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_03/nbproject/project.xml @@ -0,0 +1,15 @@ + + + org.netbeans.modules.java.j2seproject + + + fv_03 + + + + + + + + + diff --git a/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_03/src/fv_03/Main.java b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_03/src/fv_03/Main.java new file mode 100644 index 0000000..83392fe --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_03/src/fv_03/Main.java @@ -0,0 +1,73 @@ +package fv_03; + +import java.io.IOException; +import java.nio.file.FileSystems; +import java.nio.file.FileVisitOption; +import java.nio.file.FileVisitResult; +import java.nio.file.FileVisitor; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.PathMatcher; +import java.nio.file.Paths; +import java.nio.file.attribute.BasicFileAttributes; +import java.util.EnumSet; + +/** + * + * @author Apress + */ +class Search implements FileVisitor { + + private final PathMatcher matcher; + private final long accepted_size; + + public Search(String glob, long accepted_size) { + matcher = FileSystems.getDefault().getPathMatcher("glob:" + glob); + this.accepted_size = accepted_size; + } + + void search(Path file) throws IOException { + Path name = file.getFileName(); + long size = (Long) Files.getAttribute(file, "basic:size"); + + if (name != null && matcher.matches(name) && size <= accepted_size) { + System.out.println("Searched file was found: " + name + " in " + file.toRealPath().toString() + " size (bytes):" + size); + } + } + + @Override + public FileVisitResult postVisitDirectory(Object dir, IOException exc) throws IOException { + System.out.println("Visited: " + (Path) dir); + return FileVisitResult.CONTINUE; + } + + @Override + public FileVisitResult preVisitDirectory(Object dir, BasicFileAttributes attrs) throws IOException { + return FileVisitResult.CONTINUE; + } + + @Override + public FileVisitResult visitFile(Object file, BasicFileAttributes attrs) throws IOException { + search((Path) file); + return FileVisitResult.CONTINUE; + } + + @Override + public FileVisitResult visitFileFailed(Object file, IOException exc) throws IOException { + return FileVisitResult.CONTINUE; + } +} + +class Main { + + public static void main(String[] args) throws IOException { + + String glob = "*.jpg"; + long size = 102400; //100 kilobytes in bytes + Path fileTree = Paths.get("C:/rafaelnadal/"); + Search walk = new Search(glob, size); + EnumSet opts = EnumSet.of(FileVisitOption.FOLLOW_LINKS); + + Files.walkFileTree(fileTree, opts, Integer.MAX_VALUE, walk); + } +} diff --git a/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_04/build.xml b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_04/build.xml new file mode 100644 index 0000000..45d05b0 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_04/build.xml @@ -0,0 +1,74 @@ + + + + + + + + + + + Builds, tests, and runs the project fv_04. + + + diff --git a/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_04/build/built-jar.properties b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_04/build/built-jar.properties new file mode 100644 index 0000000..27281b6 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_04/build/built-jar.properties @@ -0,0 +1,4 @@ +#Mon, 17 Oct 2011 09:15:22 +0200 + + +C\:\\NIO\\filevisitor\\fv_04= diff --git a/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_04/build/classes/fv_04/Main.class b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_04/build/classes/fv_04/Main.class new file mode 100644 index 0000000..5789ccb Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_04/build/classes/fv_04/Main.class differ diff --git a/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_04/build/classes/fv_04/Search.class b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_04/build/classes/fv_04/Search.class new file mode 100644 index 0000000..32bb09b Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_04/build/classes/fv_04/Search.class differ diff --git a/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_04/dist/README.TXT b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_04/dist/README.TXT new file mode 100644 index 0000000..9a914f0 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_04/dist/README.TXT @@ -0,0 +1,32 @@ +======================== +BUILD OUTPUT DESCRIPTION +======================== + +When you build an Java application project that has a main class, the IDE +automatically copies all of the JAR +files on the projects classpath to your projects dist/lib folder. The IDE +also adds each of the JAR files to the Class-Path element in the application +JAR files manifest file (MANIFEST.MF). + +To run the project from the command line, go to the dist folder and +type the following: + +java -jar "fv_04.jar" + +To distribute this project, zip up the dist folder (including the lib folder) +and distribute the ZIP file. + +Notes: + +* If two JAR files on the project classpath have the same name, only the first +JAR file is copied to the lib folder. +* Only JAR files are copied to the lib folder. +If the classpath contains other types of files or folders, these files (folders) +are not copied. +* If a library on the projects classpath also has a Class-Path element +specified in the manifest,the content of the Class-Path element has to be on +the projects runtime path. +* To set a main class in a standard Java project, right-click the project node +in the Projects window and choose Properties. Then click Run and enter the +class name in the Main Class field. Alternatively, you can manually type the +class name in the manifest Main-Class element. diff --git a/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_04/dist/fv_04.jar b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_04/dist/fv_04.jar new file mode 100644 index 0000000..186a7c0 Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_04/dist/fv_04.jar differ diff --git a/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_04/dist/lib/commons-logging-1.1.jar b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_04/dist/lib/commons-logging-1.1.jar new file mode 100644 index 0000000..2ff9bbd Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_04/dist/lib/commons-logging-1.1.jar differ diff --git a/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_04/dist/lib/dom4j-1.6.1.jar b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_04/dist/lib/dom4j-1.6.1.jar new file mode 100644 index 0000000..c8c4dbb Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_04/dist/lib/dom4j-1.6.1.jar differ diff --git a/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_04/dist/lib/fontbox-1.6.0.jar b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_04/dist/lib/fontbox-1.6.0.jar new file mode 100644 index 0000000..c3492fc Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_04/dist/lib/fontbox-1.6.0.jar differ diff --git a/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_04/dist/lib/geronimo-stax-api_1.0_spec-1.0.jar b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_04/dist/lib/geronimo-stax-api_1.0_spec-1.0.jar new file mode 100644 index 0000000..0d6d374 Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_04/dist/lib/geronimo-stax-api_1.0_spec-1.0.jar differ diff --git a/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_04/dist/lib/itext-xtra-5.1.2-javadoc.jar b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_04/dist/lib/itext-xtra-5.1.2-javadoc.jar new file mode 100644 index 0000000..94b9166 Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_04/dist/lib/itext-xtra-5.1.2-javadoc.jar differ diff --git a/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_04/dist/lib/itext-xtra-5.1.2-sources.jar b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_04/dist/lib/itext-xtra-5.1.2-sources.jar new file mode 100644 index 0000000..82db9a7 Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_04/dist/lib/itext-xtra-5.1.2-sources.jar differ diff --git a/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_04/dist/lib/itext-xtra-5.1.2.jar b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_04/dist/lib/itext-xtra-5.1.2.jar new file mode 100644 index 0000000..263ecee Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_04/dist/lib/itext-xtra-5.1.2.jar differ diff --git a/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_04/dist/lib/itextpdf-5.1.2-javadoc.jar b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_04/dist/lib/itextpdf-5.1.2-javadoc.jar new file mode 100644 index 0000000..ea7180e Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_04/dist/lib/itextpdf-5.1.2-javadoc.jar differ diff --git a/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_04/dist/lib/itextpdf-5.1.2-sources.jar b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_04/dist/lib/itextpdf-5.1.2-sources.jar new file mode 100644 index 0000000..04f3dc0 Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_04/dist/lib/itextpdf-5.1.2-sources.jar differ diff --git a/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_04/dist/lib/itextpdf-5.1.2.jar b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_04/dist/lib/itextpdf-5.1.2.jar new file mode 100644 index 0000000..b77aaf2 Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_04/dist/lib/itextpdf-5.1.2.jar differ diff --git a/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_04/dist/lib/jempbox-1.6.0.jar b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_04/dist/lib/jempbox-1.6.0.jar new file mode 100644 index 0000000..5ca6d7a Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_04/dist/lib/jempbox-1.6.0.jar differ diff --git a/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_04/dist/lib/junit-3.8.1.jar b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_04/dist/lib/junit-3.8.1.jar new file mode 100644 index 0000000..674d71e Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_04/dist/lib/junit-3.8.1.jar differ diff --git a/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_04/dist/lib/log4j-1.2.13.jar b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_04/dist/lib/log4j-1.2.13.jar new file mode 100644 index 0000000..dde9972 Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_04/dist/lib/log4j-1.2.13.jar differ diff --git a/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_04/dist/lib/pdfbox-1.6.0.jar b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_04/dist/lib/pdfbox-1.6.0.jar new file mode 100644 index 0000000..75efe03 Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_04/dist/lib/pdfbox-1.6.0.jar differ diff --git a/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_04/dist/lib/pdfbox-app-1.6.0.jar b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_04/dist/lib/pdfbox-app-1.6.0.jar new file mode 100644 index 0000000..52b5cf9 Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_04/dist/lib/pdfbox-app-1.6.0.jar differ diff --git a/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_04/dist/lib/poi-3.7-20101029.jar b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_04/dist/lib/poi-3.7-20101029.jar new file mode 100644 index 0000000..a08d953 Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_04/dist/lib/poi-3.7-20101029.jar differ diff --git a/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_04/dist/lib/poi-examples-3.7-20101029.jar b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_04/dist/lib/poi-examples-3.7-20101029.jar new file mode 100644 index 0000000..914243d Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_04/dist/lib/poi-examples-3.7-20101029.jar differ diff --git a/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_04/dist/lib/poi-ooxml-3.7-20101029.jar b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_04/dist/lib/poi-ooxml-3.7-20101029.jar new file mode 100644 index 0000000..5f36eb4 Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_04/dist/lib/poi-ooxml-3.7-20101029.jar differ diff --git a/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_04/dist/lib/poi-ooxml-schemas-3.7-20101029.jar b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_04/dist/lib/poi-ooxml-schemas-3.7-20101029.jar new file mode 100644 index 0000000..82282b5 Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_04/dist/lib/poi-ooxml-schemas-3.7-20101029.jar differ diff --git a/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_04/dist/lib/poi-scratchpad-3.7-20101029.jar b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_04/dist/lib/poi-scratchpad-3.7-20101029.jar new file mode 100644 index 0000000..6fd02d4 Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_04/dist/lib/poi-scratchpad-3.7-20101029.jar differ diff --git a/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_04/dist/lib/xmlbeans-2.3.0.jar b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_04/dist/lib/xmlbeans-2.3.0.jar new file mode 100644 index 0000000..ccd8163 Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_04/dist/lib/xmlbeans-2.3.0.jar differ diff --git a/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_04/manifest.mf b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_04/manifest.mf new file mode 100644 index 0000000..328e8e5 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_04/manifest.mf @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +X-COMMENT: Main-Class will be added automatically by build + diff --git a/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_04/nbproject/build-impl.xml b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_04/nbproject/build-impl.xml new file mode 100644 index 0000000..8506f84 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_04/nbproject/build-impl.xml @@ -0,0 +1,1041 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set src.dir + Must set test.src.dir + Must set build.dir + Must set dist.dir + Must set build.classes.dir + Must set dist.javadoc.dir + Must set build.test.classes.dir + Must set build.test.results.dir + Must set build.classes.excludes + Must set dist.jar + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set JVM to use for profiling in profiler.info.jvm + Must set profiler agent JVM arguments in profiler.info.jvmargs.agent + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + + + + + + java -cp "${run.classpath.with.dist.jar}" ${main.class} + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + java -jar "${dist.jar.resolved}" + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set run.class + + + + Must select one file in the IDE or set run.class + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set debug.class + + + + + Must select one file in the IDE or set debug.class + + + + + Must set fix.includes + + + + + + + + + + + + + + + + + Must select one file in the IDE or set profile.class + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + Some tests failed; see details above. + + + + + + + + + Must select some files in the IDE or set test.includes + + + + Some tests failed; see details above. + + + + + Must select one file in the IDE or set test.class + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_04/nbproject/genfiles.properties b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_04/nbproject/genfiles.properties new file mode 100644 index 0000000..f263c9a --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_04/nbproject/genfiles.properties @@ -0,0 +1,8 @@ +build.xml.data.CRC32=98807014 +build.xml.script.CRC32=a24eb903 +build.xml.stylesheet.CRC32=28e38971@1.43.1.45 +# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. +# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. +nbproject/build-impl.xml.data.CRC32=98807014 +nbproject/build-impl.xml.script.CRC32=6e5fa08b +nbproject/build-impl.xml.stylesheet.CRC32=0c01fd8e@1.43.1.45 diff --git a/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_04/nbproject/private/config.properties b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_04/nbproject/private/config.properties new file mode 100644 index 0000000..e69de29 diff --git a/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_04/nbproject/private/private.properties b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_04/nbproject/private/private.properties new file mode 100644 index 0000000..a5ab360 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_04/nbproject/private/private.properties @@ -0,0 +1,6 @@ +compile.on.save=true +do.depend=false +do.jar=true +javac.debug=true +javadoc.preview=true +user.properties.file=C:\\Users\\Leo\\.netbeans\\7.0\\build.properties diff --git a/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_04/nbproject/private/private.xml b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_04/nbproject/private/private.xml new file mode 100644 index 0000000..c1f155a --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_04/nbproject/private/private.xml @@ -0,0 +1,4 @@ + + + + diff --git a/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_04/nbproject/project.properties b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_04/nbproject/project.properties new file mode 100644 index 0000000..e5c04ec --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_04/nbproject/project.properties @@ -0,0 +1,114 @@ +annotation.processing.enabled=true +annotation.processing.enabled.in.editor=false +annotation.processing.run.all.processors=true +annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output +application.title=fv_04 +application.vendor=Leo +build.classes.dir=${build.dir}/classes +build.classes.excludes=**/*.java,**/*.form +# This directory is removed when the project is cleaned: +build.dir=build +build.generated.dir=${build.dir}/generated +build.generated.sources.dir=${build.dir}/generated-sources +# Only compile against the classpath explicitly listed here: +build.sysclasspath=ignore +build.test.classes.dir=${build.dir}/test/classes +build.test.results.dir=${build.dir}/test/results +# Uncomment to specify the preferred debugger connection transport: +#debug.transport=dt_socket +debug.classpath=\ + ${run.classpath} +debug.test.classpath=\ + ${run.test.classpath} +# This directory is removed when the project is cleaned: +dist.dir=dist +dist.jar=${dist.dir}/fv_04.jar +dist.javadoc.dir=${dist.dir}/javadoc +endorsed.classpath= +excludes= +file.reference.commons-logging-1.1.jar=D:\\JARsFORDOCs\\poi-3.7\\lib\\commons-logging-1.1.jar +file.reference.dom4j-1.6.1.jar=D:\\JARsFORDOCs\\poi-3.7\\ooxml-lib\\dom4j-1.6.1.jar +file.reference.fontbox-1.6.0.jar=D:\\JARsFORDOCs\\PDFBox\\fontbox-1.6.0.jar +file.reference.geronimo-stax-api_1.0_spec-1.0.jar=D:\\JARsFORDOCs\\poi-3.7\\ooxml-lib\\geronimo-stax-api_1.0_spec-1.0.jar +file.reference.itext-xtra-5.1.2-javadoc.jar=D:\\JARsFORDOCs\\itext-5.1.2\\itext-xtra-5.1.2-javadoc.jar +file.reference.itext-xtra-5.1.2-sources.jar=D:\\JARsFORDOCs\\itext-5.1.2\\itext-xtra-5.1.2-sources.jar +file.reference.itext-xtra-5.1.2.jar=D:\\JARsFORDOCs\\itext-5.1.2\\itext-xtra-5.1.2.jar +file.reference.itextpdf-5.1.2-javadoc.jar=D:\\JARsFORDOCs\\itext-5.1.2\\itextpdf-5.1.2-javadoc.jar +file.reference.itextpdf-5.1.2-sources.jar=D:\\JARsFORDOCs\\itext-5.1.2\\itextpdf-5.1.2-sources.jar +file.reference.itextpdf-5.1.2.jar=D:\\JARsFORDOCs\\itext-5.1.2\\itextpdf-5.1.2.jar +file.reference.jempbox-1.6.0.jar=D:\\JARsFORDOCs\\PDFBox\\jempbox-1.6.0.jar +file.reference.junit-3.8.1.jar=D:\\JARsFORDOCs\\poi-3.7\\lib\\junit-3.8.1.jar +file.reference.log4j-1.2.13.jar=D:\\JARsFORDOCs\\poi-3.7\\lib\\log4j-1.2.13.jar +file.reference.pdfbox-1.6.0.jar=D:\\JARsFORDOCs\\PDFBox\\pdfbox-1.6.0.jar +file.reference.pdfbox-app-1.6.0.jar=D:\\JARsFORDOCs\\PDFBox\\pdfbox-app-1.6.0.jar +file.reference.poi-3.7-20101029.jar=D:\\JARsFORDOCs\\poi-3.7\\poi-3.7-20101029.jar +file.reference.poi-examples-3.7-20101029.jar=D:\\JARsFORDOCs\\poi-3.7\\poi-examples-3.7-20101029.jar +file.reference.poi-ooxml-3.7-20101029.jar=D:\\JARsFORDOCs\\poi-3.7\\poi-ooxml-3.7-20101029.jar +file.reference.poi-ooxml-schemas-3.7-20101029.jar=D:\\JARsFORDOCs\\poi-3.7\\poi-ooxml-schemas-3.7-20101029.jar +file.reference.poi-scratchpad-3.7-20101029.jar=D:\\JARsFORDOCs\\poi-3.7\\poi-scratchpad-3.7-20101029.jar +file.reference.xmlbeans-2.3.0.jar=D:\\JARsFORDOCs\\poi-3.7\\ooxml-lib\\xmlbeans-2.3.0.jar +includes=** +jar.compress=false +javac.classpath=\ + ${file.reference.itext-xtra-5.1.2-javadoc.jar}:\ + ${file.reference.itext-xtra-5.1.2-sources.jar}:\ + ${file.reference.itext-xtra-5.1.2.jar}:\ + ${file.reference.itextpdf-5.1.2-javadoc.jar}:\ + ${file.reference.itextpdf-5.1.2-sources.jar}:\ + ${file.reference.itextpdf-5.1.2.jar}:\ + ${file.reference.poi-3.7-20101029.jar}:\ + ${file.reference.poi-examples-3.7-20101029.jar}:\ + ${file.reference.poi-ooxml-3.7-20101029.jar}:\ + ${file.reference.poi-ooxml-schemas-3.7-20101029.jar}:\ + ${file.reference.poi-scratchpad-3.7-20101029.jar}:\ + ${file.reference.dom4j-1.6.1.jar}:\ + ${file.reference.geronimo-stax-api_1.0_spec-1.0.jar}:\ + ${file.reference.xmlbeans-2.3.0.jar}:\ + ${file.reference.commons-logging-1.1.jar}:\ + ${file.reference.junit-3.8.1.jar}:\ + ${file.reference.log4j-1.2.13.jar}:\ + ${file.reference.fontbox-1.6.0.jar}:\ + ${file.reference.jempbox-1.6.0.jar}:\ + ${file.reference.pdfbox-1.6.0.jar}:\ + ${file.reference.pdfbox-app-1.6.0.jar} +# Space-separated list of extra javac options +javac.compilerargs= +javac.deprecation=false +javac.processorpath=\ + ${javac.classpath} +javac.source=1.7 +javac.target=1.7 +javac.test.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +javac.test.processorpath=\ + ${javac.test.classpath} +javadoc.additionalparam= +javadoc.author=false +javadoc.encoding=${source.encoding} +javadoc.noindex=false +javadoc.nonavbar=false +javadoc.notree=false +javadoc.private=false +javadoc.splitindex=true +javadoc.use=true +javadoc.version=false +javadoc.windowtitle= +main.class=fv_04.Main +manifest.file=manifest.mf +meta.inf.dir=${src.dir}/META-INF +mkdist.disabled=false +platform.active=default_platform +run.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +# Space-separated list of JVM arguments used when running the project +# (you may also define separate properties like run-sys-prop.name=value instead of -Dname=value +# or test-sys-prop.name=value to set system properties for unit tests): +run.jvmargs= +run.test.classpath=\ + ${javac.test.classpath}:\ + ${build.test.classes.dir} +source.encoding=UTF-8 +src.dir=src +test.src.dir=test diff --git a/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_04/nbproject/project.xml b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_04/nbproject/project.xml new file mode 100644 index 0000000..3c68c50 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_04/nbproject/project.xml @@ -0,0 +1,15 @@ + + + org.netbeans.modules.java.j2seproject + + + fv_04 + + + + + + + + + diff --git a/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_04/src/fv_04/Main.java b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_04/src/fv_04/Main.java new file mode 100644 index 0000000..c725792 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_04/src/fv_04/Main.java @@ -0,0 +1,393 @@ +package fv_04; + +import com.itextpdf.text.pdf.PdfReader; +import com.itextpdf.text.pdf.parser.PdfTextExtractor; +import java.io.BufferedReader; +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.nio.charset.Charset; +import java.nio.file.FileSystems; +import java.nio.file.FileVisitOption; +import java.nio.file.FileVisitResult; +import java.nio.file.FileVisitor; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.attribute.BasicFileAttributes; +import java.util.ArrayList; +import java.util.EnumSet; +import java.util.Iterator; +import java.util.StringTokenizer; +import org.apache.pdfbox.cos.COSDocument; +import org.apache.pdfbox.pdfparser.PDFParser; +import org.apache.pdfbox.pdmodel.PDDocument; +import org.apache.pdfbox.util.PDFTextStripper; +import org.apache.poi.hslf.HSLFSlideShow; +import org.apache.poi.hslf.model.Notes; +import org.apache.poi.hslf.model.Slide; +import org.apache.poi.hslf.model.TextRun; +import org.apache.poi.hslf.record.TextHeaderAtom; +import org.apache.poi.hslf.usermodel.SlideShow; +import org.apache.poi.hssf.usermodel.HSSFCell; +import org.apache.poi.hssf.usermodel.HSSFSheet; +import org.apache.poi.hssf.usermodel.HSSFWorkbook; +import org.apache.poi.hwpf.HWPFDocument; +import org.apache.poi.hwpf.extractor.WordExtractor; +import org.apache.poi.poifs.filesystem.POIFSFileSystem; +import org.apache.poi.ss.usermodel.Cell; +import org.apache.poi.ss.usermodel.Row; + +/** + * + * @author Apress + */ +class Search implements FileVisitor { + + ArrayList wordsarray = new ArrayList<>(); + ArrayList documents = new ArrayList<>(); + boolean found = false; + + public Search(String words) { + wordsarray.clear(); + documents.clear(); + + StringTokenizer st = new StringTokenizer(words, ","); + while (st.hasMoreTokens()) { + wordsarray.add(st.nextToken().trim()); + } + } + + void search(Path file) throws IOException { + + found = false; + + String name = file.getFileName().toString(); + int mid = name.lastIndexOf("."); + String ext = name.substring(mid + 1, name.length()); + + if (ext.equalsIgnoreCase("pdf")) { + found = searchInPDF_iText(file.toString()); + if (!found) { + found = searchInPDF_PDFBox(file.toString()); + } + } + + if (ext.equalsIgnoreCase("doc") || ext.equalsIgnoreCase("docx")) { + found = searchInWord(file.toString()); + } + + if (ext.equalsIgnoreCase("ppt")) { + searchInPPT(file.toString()); + } + + if (ext.equalsIgnoreCase("xls")) { + searchInExcel(file.toString()); + } + + if ((ext.equalsIgnoreCase("txt")) || (ext.equalsIgnoreCase("xml") || ext.equalsIgnoreCase("html")) + || ext.equalsIgnoreCase("htm") || ext.equalsIgnoreCase("xhtml") || ext.equalsIgnoreCase("rtf")) { + searchInText(file); + } + + if (found) { + documents.add(file.toString()); + } + } + + //search in text files + boolean searchInText(Path file) { + + boolean flag = false; + Charset charset = Charset.forName("UTF-8"); + try (BufferedReader reader = Files.newBufferedReader(file, charset)) { + String line = null; + + OUTERMOST: + while ((line = reader.readLine()) != null) { + flag = searchText(line); + if (flag) { + break OUTERMOST; + } + } + + } catch (IOException e) { + } finally { + return flag; + } + } + + //search in Excel + boolean searchInExcel(String file) { + + Row row; + Cell cell; + String text; + boolean flag = false; + InputStream xls = null; + + try { + xls = new FileInputStream(file); + HSSFWorkbook wb = new HSSFWorkbook(xls); + + int sheets = wb.getNumberOfSheets(); + + OUTERMOST: + for (int i = 0; i < sheets; i++) { + HSSFSheet sheet = wb.getSheetAt(i); + + Iterator row_iterator = sheet.rowIterator(); + while (row_iterator.hasNext()) { + row = (Row) row_iterator.next(); + Iterator cell_iterator = row.cellIterator(); + while (cell_iterator.hasNext()) { + cell = cell_iterator.next(); + int type = cell.getCellType(); + if (type == HSSFCell.CELL_TYPE_STRING) { + text = cell.getStringCellValue(); + flag = searchText(text); + if (flag) { + break OUTERMOST; + } + } + } + } + } + + } catch (IOException e) { + } finally { + try { + if (xls != null) { + xls.close(); + } + } catch (IOException e) { + } + return flag; + } + } + + //search in PowerPoint files + boolean searchInPPT(String file) { + + boolean flag = false; + InputStream fis = null; + String text; + + try { + fis = new FileInputStream(new File(file)); + POIFSFileSystem fs = new POIFSFileSystem(fis); + HSLFSlideShow show = new HSLFSlideShow(fs); + + SlideShow ss = new SlideShow(show); + Slide[] slides = ss.getSlides(); + + OUTERMOST: + for (int i = 0; i < slides.length; i++) { + + TextRun[] runs = slides[i].getTextRuns(); + for (int j = 0; j < runs.length; j++) { + TextRun run = runs[j]; + if (run.getRunType() == TextHeaderAtom.TITLE_TYPE) { + text = run.getText(); + } else { + text = run.getRunType() + " " + run.getText(); + } + + flag = searchText(text); + if (flag) { + break OUTERMOST; + } + + } + + Notes notes = slides[i].getNotesSheet(); + if (notes != null) { + runs = notes.getTextRuns(); + for (int j = 0; j < runs.length; j++) { + text = runs[j].getText(); + flag = searchText(text); + if (flag) { + break OUTERMOST; + } + } + } + } + + } catch (IOException e) { + } finally { + try { + if (fis != null) { + fis.close(); + } + } catch (IOException e) { + } + return flag; + } + + } + + //search in Word files + boolean searchInWord(String file) { + + POIFSFileSystem fs = null; + boolean flag = false; + + try { + fs = new POIFSFileSystem(new FileInputStream(file)); + + HWPFDocument doc = new HWPFDocument(fs); + WordExtractor we = new WordExtractor(doc); + String[] paragraphs = we.getParagraphText(); + + OUTERMOST: + for (int i = 0; i < paragraphs.length; i++) { + + flag = searchText(paragraphs[i]); + if (flag) { + break OUTERMOST; + } + } + + } catch (Exception e) { + } finally { + return flag; + } + } + + //search in PDF files using PDFBox library + boolean searchInPDF_PDFBox(String file) { + + PDFParser parser = null; + String parsedText = null; + PDFTextStripper pdfStripper = null; + PDDocument pdDoc = null; + COSDocument cosDoc = null; + boolean flag = false; + int page = 0; + + File pdf = new File(file); + + try { + parser = new PDFParser(new FileInputStream(pdf)); + parser.parse(); + + cosDoc = parser.getDocument(); + pdfStripper = new PDFTextStripper(); + pdDoc = new PDDocument(cosDoc); + + OUTERMOST: + while (page < pdDoc.getNumberOfPages()) { + page++; + pdfStripper.setStartPage(page); + pdfStripper.setEndPage(page + 1); + parsedText = pdfStripper.getText(pdDoc); + + flag = searchText(parsedText); + if (flag) { + break OUTERMOST; + } + } + + } catch (Exception e) { + } finally { + try { + if (cosDoc != null) { + cosDoc.close(); + } + if (pdDoc != null) { + pdDoc.close(); + } + } catch (Exception e) { + } + return flag; + } + } + + //search in PDF files using iText library + boolean searchInPDF_iText(String file) { + + PdfReader reader = null; + boolean flag = false; + + try { + reader = new PdfReader(file); + int n = reader.getNumberOfPages(); + + OUTERMOST: + for (int i = 1; i <= n; i++) { + String str = PdfTextExtractor.getTextFromPage(reader, i); + + flag = searchText(str); + if (flag) { + break OUTERMOST; + } + } + + } catch (Exception e) { + } finally { + if (reader != null) { + reader.close(); + } + return flag; + } + + } + + //search text + private boolean searchText(String text) { + + boolean flag = false; + for (int j = 0; j < wordsarray.size(); j++) { + if ((text.toLowerCase()).contains(wordsarray.get(j).toLowerCase())) { + flag = true; + break; + } + } + + return flag; + } + + @Override + public FileVisitResult postVisitDirectory(Object dir, IOException exc) throws IOException { + System.out.println("Visited: " + (Path) dir); + return FileVisitResult.CONTINUE; + } + + @Override + public FileVisitResult preVisitDirectory(Object dir, BasicFileAttributes attrs) throws IOException { + return FileVisitResult.CONTINUE; + } + + @Override + public FileVisitResult visitFile(Object file, BasicFileAttributes attrs) throws IOException { + search((Path) file); + return FileVisitResult.CONTINUE; + } + + @Override + public FileVisitResult visitFileFailed(Object file, IOException exc) throws IOException { + return FileVisitResult.CONTINUE; + } +} + +class Main { + + public static void main(String[] args) throws IOException { + + String words = "Rafael Nadal,tennis,winner of Roland Garros,BNP Paribas tournament draws"; + Search walk = new Search(words); + EnumSet opts = EnumSet.of(FileVisitOption.FOLLOW_LINKS); + + Iterable dirs = FileSystems.getDefault().getRootDirectories(); + for (Path root : dirs) { + Files.walkFileTree(root, opts, Integer.MAX_VALUE, walk); + } + + System.out.println("____________________________________________________________"); + for(String path_string: walk.documents){ + System.out.println(path_string); + } + System.out.println("____________________________________________________________"); + + } +} \ No newline at end of file diff --git a/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_05/build.xml b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_05/build.xml new file mode 100644 index 0000000..938593f --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_05/build.xml @@ -0,0 +1,74 @@ + + + + + + + + + + + Builds, tests, and runs the project fv_05. + + + diff --git a/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_05/build/built-jar.properties b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_05/build/built-jar.properties new file mode 100644 index 0000000..ead42e3 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_05/build/built-jar.properties @@ -0,0 +1,4 @@ +#Mon, 17 Oct 2011 09:57:06 +0200 + + +C\:\\NIO\\filevisitor\\fv_05= diff --git a/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_05/build/classes/fv_05/DeleteDirectory.class b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_05/build/classes/fv_05/DeleteDirectory.class new file mode 100644 index 0000000..d665180 Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_05/build/classes/fv_05/DeleteDirectory.class differ diff --git a/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_05/build/classes/fv_05/Main.class b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_05/build/classes/fv_05/Main.class new file mode 100644 index 0000000..045f03a Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_05/build/classes/fv_05/Main.class differ diff --git a/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_05/dist/README.TXT b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_05/dist/README.TXT new file mode 100644 index 0000000..9fd28b9 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_05/dist/README.TXT @@ -0,0 +1,32 @@ +======================== +BUILD OUTPUT DESCRIPTION +======================== + +When you build an Java application project that has a main class, the IDE +automatically copies all of the JAR +files on the projects classpath to your projects dist/lib folder. The IDE +also adds each of the JAR files to the Class-Path element in the application +JAR files manifest file (MANIFEST.MF). + +To run the project from the command line, go to the dist folder and +type the following: + +java -jar "fv_05.jar" + +To distribute this project, zip up the dist folder (including the lib folder) +and distribute the ZIP file. + +Notes: + +* If two JAR files on the project classpath have the same name, only the first +JAR file is copied to the lib folder. +* Only JAR files are copied to the lib folder. +If the classpath contains other types of files or folders, these files (folders) +are not copied. +* If a library on the projects classpath also has a Class-Path element +specified in the manifest,the content of the Class-Path element has to be on +the projects runtime path. +* To set a main class in a standard Java project, right-click the project node +in the Projects window and choose Properties. Then click Run and enter the +class name in the Main Class field. Alternatively, you can manually type the +class name in the manifest Main-Class element. diff --git a/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_05/dist/fv_05.jar b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_05/dist/fv_05.jar new file mode 100644 index 0000000..05d1c3f Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_05/dist/fv_05.jar differ diff --git a/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_05/manifest.mf b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_05/manifest.mf new file mode 100644 index 0000000..328e8e5 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_05/manifest.mf @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +X-COMMENT: Main-Class will be added automatically by build + diff --git a/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_05/nbproject/build-impl.xml b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_05/nbproject/build-impl.xml new file mode 100644 index 0000000..34adff0 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_05/nbproject/build-impl.xml @@ -0,0 +1,1041 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set src.dir + Must set test.src.dir + Must set build.dir + Must set dist.dir + Must set build.classes.dir + Must set dist.javadoc.dir + Must set build.test.classes.dir + Must set build.test.results.dir + Must set build.classes.excludes + Must set dist.jar + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set JVM to use for profiling in profiler.info.jvm + Must set profiler agent JVM arguments in profiler.info.jvmargs.agent + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + + + + + + java -cp "${run.classpath.with.dist.jar}" ${main.class} + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + java -jar "${dist.jar.resolved}" + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set run.class + + + + Must select one file in the IDE or set run.class + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set debug.class + + + + + Must select one file in the IDE or set debug.class + + + + + Must set fix.includes + + + + + + + + + + + + + + + + + Must select one file in the IDE or set profile.class + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + Some tests failed; see details above. + + + + + + + + + Must select some files in the IDE or set test.includes + + + + Some tests failed; see details above. + + + + + Must select one file in the IDE or set test.class + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_05/nbproject/genfiles.properties b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_05/nbproject/genfiles.properties new file mode 100644 index 0000000..b206608 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_05/nbproject/genfiles.properties @@ -0,0 +1,8 @@ +build.xml.data.CRC32=9093fc32 +build.xml.script.CRC32=5ea24987 +build.xml.stylesheet.CRC32=28e38971@1.43.1.45 +# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. +# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. +nbproject/build-impl.xml.data.CRC32=9093fc32 +nbproject/build-impl.xml.script.CRC32=d9d654f0 +nbproject/build-impl.xml.stylesheet.CRC32=0c01fd8e@1.43.1.45 diff --git a/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_05/nbproject/private/config.properties b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_05/nbproject/private/config.properties new file mode 100644 index 0000000..e69de29 diff --git a/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_05/nbproject/private/private.properties b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_05/nbproject/private/private.properties new file mode 100644 index 0000000..a5ab360 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_05/nbproject/private/private.properties @@ -0,0 +1,6 @@ +compile.on.save=true +do.depend=false +do.jar=true +javac.debug=true +javadoc.preview=true +user.properties.file=C:\\Users\\Leo\\.netbeans\\7.0\\build.properties diff --git a/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_05/nbproject/private/private.xml b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_05/nbproject/private/private.xml new file mode 100644 index 0000000..c1f155a --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_05/nbproject/private/private.xml @@ -0,0 +1,4 @@ + + + + diff --git a/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_05/nbproject/project.properties b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_05/nbproject/project.properties new file mode 100644 index 0000000..2d65bad --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_05/nbproject/project.properties @@ -0,0 +1,72 @@ +annotation.processing.enabled=true +annotation.processing.enabled.in.editor=false +annotation.processing.run.all.processors=true +annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output +application.title=fv_05 +application.vendor=Leo +build.classes.dir=${build.dir}/classes +build.classes.excludes=**/*.java,**/*.form +# This directory is removed when the project is cleaned: +build.dir=build +build.generated.dir=${build.dir}/generated +build.generated.sources.dir=${build.dir}/generated-sources +# Only compile against the classpath explicitly listed here: +build.sysclasspath=ignore +build.test.classes.dir=${build.dir}/test/classes +build.test.results.dir=${build.dir}/test/results +# Uncomment to specify the preferred debugger connection transport: +#debug.transport=dt_socket +debug.classpath=\ + ${run.classpath} +debug.test.classpath=\ + ${run.test.classpath} +# This directory is removed when the project is cleaned: +dist.dir=dist +dist.jar=${dist.dir}/fv_05.jar +dist.javadoc.dir=${dist.dir}/javadoc +endorsed.classpath= +excludes= +includes=** +jar.compress=false +javac.classpath= +# Space-separated list of extra javac options +javac.compilerargs= +javac.deprecation=false +javac.processorpath=\ + ${javac.classpath} +javac.source=1.7 +javac.target=1.7 +javac.test.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +javac.test.processorpath=\ + ${javac.test.classpath} +javadoc.additionalparam= +javadoc.author=false +javadoc.encoding=${source.encoding} +javadoc.noindex=false +javadoc.nonavbar=false +javadoc.notree=false +javadoc.private=false +javadoc.splitindex=true +javadoc.use=true +javadoc.version=false +javadoc.windowtitle= +main.class=fv_05.Main +manifest.file=manifest.mf +meta.inf.dir=${src.dir}/META-INF +mkdist.disabled=false +platform.active=default_platform +run.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +# Space-separated list of JVM arguments used when running the project +# (you may also define separate properties like run-sys-prop.name=value instead of -Dname=value +# or test-sys-prop.name=value to set system properties for unit tests): +run.jvmargs= +run.test.classpath=\ + ${javac.test.classpath}:\ + ${build.test.classes.dir} +source.encoding=UTF-8 +src.dir=src +test.src.dir=test diff --git a/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_05/nbproject/project.xml b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_05/nbproject/project.xml new file mode 100644 index 0000000..3b4b45a --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_05/nbproject/project.xml @@ -0,0 +1,15 @@ + + + org.netbeans.modules.java.j2seproject + + + fv_05 + + + + + + + + + diff --git a/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_05/src/fv_05/Main.java b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_05/src/fv_05/Main.java new file mode 100644 index 0000000..5d045f4 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_05/src/fv_05/Main.java @@ -0,0 +1,76 @@ +package fv_05; + +import java.io.IOException; +import java.nio.file.FileVisitOption; +import java.nio.file.FileVisitResult; +import java.nio.file.FileVisitor; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.nio.file.attribute.BasicFileAttributes; +import java.util.EnumSet; + +/** + * + * @author Apress + */ +class DeleteDirectory implements FileVisitor { + + boolean deleteFileByFile(Path file) throws IOException { + return Files.deleteIfExists(file); + } + + @Override + public FileVisitResult postVisitDirectory(Object dir, IOException exc) throws IOException { + + if (exc == null) { + System.out.println("Visited: " + (Path) dir); + + boolean success = deleteFileByFile((Path) dir); + + if (success) { + System.out.println("Deleted: " + (Path) dir); + } else { + System.out.println("Not deleted: " + (Path) dir); + } + } else { + throw exc; + } + return FileVisitResult.CONTINUE; + } + + @Override + public FileVisitResult preVisitDirectory(Object dir, BasicFileAttributes attrs) throws IOException { + return FileVisitResult.CONTINUE; + } + + @Override + public FileVisitResult visitFile(Object file, BasicFileAttributes attrs) throws IOException { + boolean success = deleteFileByFile((Path) file); + + if (success) { + System.out.println("Deleted: " + (Path) file); + } else { + System.out.println("Not deleted: " + (Path) file); + } + + return FileVisitResult.CONTINUE; + } + + @Override + public FileVisitResult visitFileFailed(Object file, IOException exc) throws IOException { + return FileVisitResult.CONTINUE; + } +} + +class Main { + + public static void main(String[] args) throws IOException { + + Path directory = Paths.get("C:/rafaelnadal"); + DeleteDirectory walk = new DeleteDirectory(); + EnumSet opts = EnumSet.of(FileVisitOption.FOLLOW_LINKS); + + Files.walkFileTree(directory, opts, Integer.MAX_VALUE, walk); + } +} diff --git a/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_06/build.xml b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_06/build.xml new file mode 100644 index 0000000..e8fd88d --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_06/build.xml @@ -0,0 +1,74 @@ + + + + + + + + + + + Builds, tests, and runs the project fv_06. + + + diff --git a/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_06/build/built-jar.properties b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_06/build/built-jar.properties new file mode 100644 index 0000000..f15be4a --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_06/build/built-jar.properties @@ -0,0 +1,4 @@ +#Mon, 17 Oct 2011 09:56:54 +0200 + + +C\:\\NIO\\filevisitor\\fv_06= diff --git a/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_06/build/classes/fv_06/CopyTree.class b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_06/build/classes/fv_06/CopyTree.class new file mode 100644 index 0000000..81229f1 Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_06/build/classes/fv_06/CopyTree.class differ diff --git a/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_06/build/classes/fv_06/Main.class b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_06/build/classes/fv_06/Main.class new file mode 100644 index 0000000..4a62d6e Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_06/build/classes/fv_06/Main.class differ diff --git a/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_06/dist/README.TXT b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_06/dist/README.TXT new file mode 100644 index 0000000..2961d01 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_06/dist/README.TXT @@ -0,0 +1,32 @@ +======================== +BUILD OUTPUT DESCRIPTION +======================== + +When you build an Java application project that has a main class, the IDE +automatically copies all of the JAR +files on the projects classpath to your projects dist/lib folder. The IDE +also adds each of the JAR files to the Class-Path element in the application +JAR files manifest file (MANIFEST.MF). + +To run the project from the command line, go to the dist folder and +type the following: + +java -jar "fv_06.jar" + +To distribute this project, zip up the dist folder (including the lib folder) +and distribute the ZIP file. + +Notes: + +* If two JAR files on the project classpath have the same name, only the first +JAR file is copied to the lib folder. +* Only JAR files are copied to the lib folder. +If the classpath contains other types of files or folders, these files (folders) +are not copied. +* If a library on the projects classpath also has a Class-Path element +specified in the manifest,the content of the Class-Path element has to be on +the projects runtime path. +* To set a main class in a standard Java project, right-click the project node +in the Projects window and choose Properties. Then click Run and enter the +class name in the Main Class field. Alternatively, you can manually type the +class name in the manifest Main-Class element. diff --git a/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_06/dist/fv_06.jar b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_06/dist/fv_06.jar new file mode 100644 index 0000000..56646e1 Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_06/dist/fv_06.jar differ diff --git a/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_06/manifest.mf b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_06/manifest.mf new file mode 100644 index 0000000..328e8e5 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_06/manifest.mf @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +X-COMMENT: Main-Class will be added automatically by build + diff --git a/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_06/nbproject/build-impl.xml b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_06/nbproject/build-impl.xml new file mode 100644 index 0000000..5837f1c --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_06/nbproject/build-impl.xml @@ -0,0 +1,1041 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set src.dir + Must set test.src.dir + Must set build.dir + Must set dist.dir + Must set build.classes.dir + Must set dist.javadoc.dir + Must set build.test.classes.dir + Must set build.test.results.dir + Must set build.classes.excludes + Must set dist.jar + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set JVM to use for profiling in profiler.info.jvm + Must set profiler agent JVM arguments in profiler.info.jvmargs.agent + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + + + + + + java -cp "${run.classpath.with.dist.jar}" ${main.class} + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + java -jar "${dist.jar.resolved}" + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set run.class + + + + Must select one file in the IDE or set run.class + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set debug.class + + + + + Must select one file in the IDE or set debug.class + + + + + Must set fix.includes + + + + + + + + + + + + + + + + + Must select one file in the IDE or set profile.class + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + Some tests failed; see details above. + + + + + + + + + Must select some files in the IDE or set test.includes + + + + Some tests failed; see details above. + + + + + Must select one file in the IDE or set test.class + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_06/nbproject/genfiles.properties b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_06/nbproject/genfiles.properties new file mode 100644 index 0000000..3a0b31d --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_06/nbproject/genfiles.properties @@ -0,0 +1,8 @@ +build.xml.data.CRC32=88a76858 +build.xml.script.CRC32=80e65e4a +build.xml.stylesheet.CRC32=28e38971@1.43.1.45 +# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. +# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. +nbproject/build-impl.xml.data.CRC32=88a76858 +nbproject/build-impl.xml.script.CRC32=da3d4e3c +nbproject/build-impl.xml.stylesheet.CRC32=0c01fd8e@1.43.1.45 diff --git a/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_06/nbproject/private/config.properties b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_06/nbproject/private/config.properties new file mode 100644 index 0000000..e69de29 diff --git a/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_06/nbproject/private/private.properties b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_06/nbproject/private/private.properties new file mode 100644 index 0000000..a5ab360 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_06/nbproject/private/private.properties @@ -0,0 +1,6 @@ +compile.on.save=true +do.depend=false +do.jar=true +javac.debug=true +javadoc.preview=true +user.properties.file=C:\\Users\\Leo\\.netbeans\\7.0\\build.properties diff --git a/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_06/nbproject/private/private.xml b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_06/nbproject/private/private.xml new file mode 100644 index 0000000..c1f155a --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_06/nbproject/private/private.xml @@ -0,0 +1,4 @@ + + + + diff --git a/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_06/nbproject/project.properties b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_06/nbproject/project.properties new file mode 100644 index 0000000..ab8aaaa --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_06/nbproject/project.properties @@ -0,0 +1,72 @@ +annotation.processing.enabled=true +annotation.processing.enabled.in.editor=false +annotation.processing.run.all.processors=true +annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output +application.title=fv_06 +application.vendor=Leo +build.classes.dir=${build.dir}/classes +build.classes.excludes=**/*.java,**/*.form +# This directory is removed when the project is cleaned: +build.dir=build +build.generated.dir=${build.dir}/generated +build.generated.sources.dir=${build.dir}/generated-sources +# Only compile against the classpath explicitly listed here: +build.sysclasspath=ignore +build.test.classes.dir=${build.dir}/test/classes +build.test.results.dir=${build.dir}/test/results +# Uncomment to specify the preferred debugger connection transport: +#debug.transport=dt_socket +debug.classpath=\ + ${run.classpath} +debug.test.classpath=\ + ${run.test.classpath} +# This directory is removed when the project is cleaned: +dist.dir=dist +dist.jar=${dist.dir}/fv_06.jar +dist.javadoc.dir=${dist.dir}/javadoc +endorsed.classpath= +excludes= +includes=** +jar.compress=false +javac.classpath= +# Space-separated list of extra javac options +javac.compilerargs= +javac.deprecation=false +javac.processorpath=\ + ${javac.classpath} +javac.source=1.7 +javac.target=1.7 +javac.test.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +javac.test.processorpath=\ + ${javac.test.classpath} +javadoc.additionalparam= +javadoc.author=false +javadoc.encoding=${source.encoding} +javadoc.noindex=false +javadoc.nonavbar=false +javadoc.notree=false +javadoc.private=false +javadoc.splitindex=true +javadoc.use=true +javadoc.version=false +javadoc.windowtitle= +main.class=fv_06.Main +manifest.file=manifest.mf +meta.inf.dir=${src.dir}/META-INF +mkdist.disabled=false +platform.active=default_platform +run.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +# Space-separated list of JVM arguments used when running the project +# (you may also define separate properties like run-sys-prop.name=value instead of -Dname=value +# or test-sys-prop.name=value to set system properties for unit tests): +run.jvmargs= +run.test.classpath=\ + ${javac.test.classpath}:\ + ${build.test.classes.dir} +source.encoding=UTF-8 +src.dir=src +test.src.dir=test diff --git a/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_06/nbproject/project.xml b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_06/nbproject/project.xml new file mode 100644 index 0000000..44416c8 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_06/nbproject/project.xml @@ -0,0 +1,15 @@ + + + org.netbeans.modules.java.j2seproject + + + fv_06 + + + + + + + + + diff --git a/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_06/src/fv_06/Main.java b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_06/src/fv_06/Main.java new file mode 100644 index 0000000..894bacb --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_06/src/fv_06/Main.java @@ -0,0 +1,102 @@ +package fv_06; + +import java.nio.file.FileSystemLoopException; +import java.nio.file.attribute.FileTime; +import java.io.IOException; +import java.nio.file.FileVisitOption; +import java.nio.file.FileVisitResult; +import java.nio.file.FileVisitor; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.nio.file.attribute.BasicFileAttributes; +import java.util.EnumSet; +import static java.nio.file.StandardCopyOption.REPLACE_EXISTING; +import static java.nio.file.StandardCopyOption.COPY_ATTRIBUTES; + +/** + * + * @author Apress + */ +class CopyTree implements FileVisitor { + + private final Path copyFrom; + private final Path copyTo; + + public CopyTree(Path copyFrom, Path copyTo) { + this.copyFrom = copyFrom; + this.copyTo = copyTo; + } + + static void copySubTree(Path copyFrom, Path copyTo) throws IOException { + try { + Files.copy(copyFrom, copyTo, REPLACE_EXISTING, COPY_ATTRIBUTES); + } catch (IOException e) { + System.err.println("Unable to copy " + copyFrom + " [" + e + "]"); + } + + } + + @Override + public FileVisitResult postVisitDirectory(Object dir, IOException exc) throws IOException { + if (exc == null) { + Path newdir = copyTo.resolve(copyFrom.relativize((Path) dir)); + try { + FileTime time = Files.getLastModifiedTime((Path) dir); + Files.setLastModifiedTime(newdir, time); + } catch (IOException e) { + System.err.println("Unable to copy all attributes to: " + newdir + " [" + e + "]"); + } + } else { + throw exc; + } + + return FileVisitResult.CONTINUE; + } + + @Override + public FileVisitResult preVisitDirectory(Object dir, BasicFileAttributes attrs) throws IOException { + System.out.println("Copy directory: " + (Path) dir); + Path newdir = copyTo.resolve(copyFrom.relativize((Path) dir)); + try { + Files.copy((Path) dir, newdir, REPLACE_EXISTING, COPY_ATTRIBUTES); + } catch (IOException e) { + System.err.println("Unable to create " + newdir + " [" + e + "]"); + return FileVisitResult.SKIP_SUBTREE; + } + + return FileVisitResult.CONTINUE; + } + + @Override + public FileVisitResult visitFile(Object file, BasicFileAttributes attrs) throws IOException { + System.out.println("Copy file: " + (Path) file); + copySubTree((Path) file, copyTo.resolve(copyFrom.relativize((Path) file))); + return FileVisitResult.CONTINUE; + } + + @Override + public FileVisitResult visitFileFailed(Object file, IOException exc) throws IOException { + if (exc instanceof FileSystemLoopException) { + System.err.println("Cycle was detected: " + (Path) file); + } else { + System.err.println("Error occured, unable to copy:" + (Path) file + " [" + exc + "]"); + } + + return FileVisitResult.CONTINUE; + } +} + +class Main { + + public static void main(String[] args) throws IOException { + + Path copyFrom = Paths.get("C:/rafaelnadal"); + Path copyTo = Paths.get("C:/rafaelnadal_copy"); + + CopyTree walk = new CopyTree(copyFrom, copyTo); + EnumSet opts = EnumSet.of(FileVisitOption.FOLLOW_LINKS); + + Files.walkFileTree(copyFrom, opts, Integer.MAX_VALUE, walk); + } +} diff --git a/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_07/build.xml b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_07/build.xml new file mode 100644 index 0000000..f3d3886 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_07/build.xml @@ -0,0 +1,74 @@ + + + + + + + + + + + Builds, tests, and runs the project fv_07. + + + diff --git a/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_07/build/built-jar.properties b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_07/build/built-jar.properties new file mode 100644 index 0000000..edca38e --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_07/build/built-jar.properties @@ -0,0 +1,4 @@ +#Mon, 17 Oct 2011 09:56:35 +0200 + + +C\:\\NIO\\filevisitor\\fv_07= diff --git a/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_07/build/classes/fv_07/Main.class b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_07/build/classes/fv_07/Main.class new file mode 100644 index 0000000..4c7305b Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_07/build/classes/fv_07/Main.class differ diff --git a/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_07/build/classes/fv_07/MoveTree.class b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_07/build/classes/fv_07/MoveTree.class new file mode 100644 index 0000000..09681d2 Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_07/build/classes/fv_07/MoveTree.class differ diff --git a/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_07/dist/README.TXT b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_07/dist/README.TXT new file mode 100644 index 0000000..c876d90 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_07/dist/README.TXT @@ -0,0 +1,32 @@ +======================== +BUILD OUTPUT DESCRIPTION +======================== + +When you build an Java application project that has a main class, the IDE +automatically copies all of the JAR +files on the projects classpath to your projects dist/lib folder. The IDE +also adds each of the JAR files to the Class-Path element in the application +JAR files manifest file (MANIFEST.MF). + +To run the project from the command line, go to the dist folder and +type the following: + +java -jar "fv_07.jar" + +To distribute this project, zip up the dist folder (including the lib folder) +and distribute the ZIP file. + +Notes: + +* If two JAR files on the project classpath have the same name, only the first +JAR file is copied to the lib folder. +* Only JAR files are copied to the lib folder. +If the classpath contains other types of files or folders, these files (folders) +are not copied. +* If a library on the projects classpath also has a Class-Path element +specified in the manifest,the content of the Class-Path element has to be on +the projects runtime path. +* To set a main class in a standard Java project, right-click the project node +in the Projects window and choose Properties. Then click Run and enter the +class name in the Main Class field. Alternatively, you can manually type the +class name in the manifest Main-Class element. diff --git a/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_07/dist/fv_07.jar b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_07/dist/fv_07.jar new file mode 100644 index 0000000..510be1d Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_07/dist/fv_07.jar differ diff --git a/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_07/manifest.mf b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_07/manifest.mf new file mode 100644 index 0000000..328e8e5 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_07/manifest.mf @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +X-COMMENT: Main-Class will be added automatically by build + diff --git a/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_07/nbproject/build-impl.xml b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_07/nbproject/build-impl.xml new file mode 100644 index 0000000..3d2f069 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_07/nbproject/build-impl.xml @@ -0,0 +1,1041 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set src.dir + Must set test.src.dir + Must set build.dir + Must set dist.dir + Must set build.classes.dir + Must set dist.javadoc.dir + Must set build.test.classes.dir + Must set build.test.results.dir + Must set build.classes.excludes + Must set dist.jar + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set JVM to use for profiling in profiler.info.jvm + Must set profiler agent JVM arguments in profiler.info.jvmargs.agent + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + + + + + + java -cp "${run.classpath.with.dist.jar}" ${main.class} + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + java -jar "${dist.jar.resolved}" + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set run.class + + + + Must select one file in the IDE or set run.class + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set debug.class + + + + + Must select one file in the IDE or set debug.class + + + + + Must set fix.includes + + + + + + + + + + + + + + + + + Must select one file in the IDE or set profile.class + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + Some tests failed; see details above. + + + + + + + + + Must select some files in the IDE or set test.includes + + + + Some tests failed; see details above. + + + + + Must select one file in the IDE or set test.class + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_07/nbproject/genfiles.properties b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_07/nbproject/genfiles.properties new file mode 100644 index 0000000..21339a4 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_07/nbproject/genfiles.properties @@ -0,0 +1,8 @@ +build.xml.data.CRC32=80b4e47e +build.xml.script.CRC32=7c0aaece +build.xml.stylesheet.CRC32=28e38971@1.43.1.45 +# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. +# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. +nbproject/build-impl.xml.data.CRC32=80b4e47e +nbproject/build-impl.xml.script.CRC32=6db4ba47 +nbproject/build-impl.xml.stylesheet.CRC32=0c01fd8e@1.43.1.45 diff --git a/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_07/nbproject/private/config.properties b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_07/nbproject/private/config.properties new file mode 100644 index 0000000..e69de29 diff --git a/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_07/nbproject/private/private.properties b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_07/nbproject/private/private.properties new file mode 100644 index 0000000..a5ab360 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_07/nbproject/private/private.properties @@ -0,0 +1,6 @@ +compile.on.save=true +do.depend=false +do.jar=true +javac.debug=true +javadoc.preview=true +user.properties.file=C:\\Users\\Leo\\.netbeans\\7.0\\build.properties diff --git a/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_07/nbproject/private/private.xml b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_07/nbproject/private/private.xml new file mode 100644 index 0000000..c1f155a --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_07/nbproject/private/private.xml @@ -0,0 +1,4 @@ + + + + diff --git a/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_07/nbproject/project.properties b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_07/nbproject/project.properties new file mode 100644 index 0000000..60ab7c1 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_07/nbproject/project.properties @@ -0,0 +1,72 @@ +annotation.processing.enabled=true +annotation.processing.enabled.in.editor=false +annotation.processing.run.all.processors=true +annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output +application.title=fv_07 +application.vendor=Leo +build.classes.dir=${build.dir}/classes +build.classes.excludes=**/*.java,**/*.form +# This directory is removed when the project is cleaned: +build.dir=build +build.generated.dir=${build.dir}/generated +build.generated.sources.dir=${build.dir}/generated-sources +# Only compile against the classpath explicitly listed here: +build.sysclasspath=ignore +build.test.classes.dir=${build.dir}/test/classes +build.test.results.dir=${build.dir}/test/results +# Uncomment to specify the preferred debugger connection transport: +#debug.transport=dt_socket +debug.classpath=\ + ${run.classpath} +debug.test.classpath=\ + ${run.test.classpath} +# This directory is removed when the project is cleaned: +dist.dir=dist +dist.jar=${dist.dir}/fv_07.jar +dist.javadoc.dir=${dist.dir}/javadoc +endorsed.classpath= +excludes= +includes=** +jar.compress=false +javac.classpath= +# Space-separated list of extra javac options +javac.compilerargs= +javac.deprecation=false +javac.processorpath=\ + ${javac.classpath} +javac.source=1.7 +javac.target=1.7 +javac.test.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +javac.test.processorpath=\ + ${javac.test.classpath} +javadoc.additionalparam= +javadoc.author=false +javadoc.encoding=${source.encoding} +javadoc.noindex=false +javadoc.nonavbar=false +javadoc.notree=false +javadoc.private=false +javadoc.splitindex=true +javadoc.use=true +javadoc.version=false +javadoc.windowtitle= +main.class=fv_07.Main +manifest.file=manifest.mf +meta.inf.dir=${src.dir}/META-INF +mkdist.disabled=false +platform.active=default_platform +run.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +# Space-separated list of JVM arguments used when running the project +# (you may also define separate properties like run-sys-prop.name=value instead of -Dname=value +# or test-sys-prop.name=value to set system properties for unit tests): +run.jvmargs= +run.test.classpath=\ + ${javac.test.classpath}:\ + ${build.test.classes.dir} +source.encoding=UTF-8 +src.dir=src +test.src.dir=test diff --git a/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_07/nbproject/project.xml b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_07/nbproject/project.xml new file mode 100644 index 0000000..e9b1797 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_07/nbproject/project.xml @@ -0,0 +1,15 @@ + + + org.netbeans.modules.java.j2seproject + + + fv_07 + + + + + + + + + diff --git a/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_07/src/fv_07/Main.java b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_07/src/fv_07/Main.java new file mode 100644 index 0000000..cebdb1e --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_07/src/fv_07/Main.java @@ -0,0 +1,94 @@ +package fv_07; + +import java.io.IOException; +import java.nio.file.FileVisitOption; +import java.nio.file.FileVisitResult; +import java.nio.file.FileVisitor; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.nio.file.attribute.BasicFileAttributes; +import java.nio.file.attribute.FileTime; +import java.util.EnumSet; +import static java.nio.file.StandardCopyOption.REPLACE_EXISTING; +import static java.nio.file.StandardCopyOption.COPY_ATTRIBUTES; +import static java.nio.file.StandardCopyOption.ATOMIC_MOVE; + +/** + * + * @author Apress + */ +class MoveTree implements FileVisitor { + + private final Path moveFrom; + private final Path moveTo; + static FileTime time = null; + + public MoveTree(Path moveFrom, Path moveTo) { + this.moveFrom = moveFrom; + this.moveTo = moveTo; + } + + static void moveSubTree(Path moveFrom, Path moveTo) throws IOException { + try { + Files.move(moveFrom, moveTo, REPLACE_EXISTING, ATOMIC_MOVE); + } catch (IOException e) { + System.err.println("Unable to move " + moveFrom + " [" + e + "]"); + } + + } + + @Override + public FileVisitResult postVisitDirectory(Object dir, IOException exc) throws IOException { + Path newdir = moveTo.resolve(moveFrom.relativize((Path) dir)); + try { + Files.setLastModifiedTime(newdir, time); + Files.delete((Path) dir); + } catch (IOException e) { + System.err.println("Unable to copy all attributes to: " + newdir + " [" + e + "]"); + } + + return FileVisitResult.CONTINUE; + } + + @Override + public FileVisitResult preVisitDirectory(Object dir, BasicFileAttributes attrs) throws IOException { + System.out.println("Move directory: " + (Path) dir); + Path newdir = moveTo.resolve(moveFrom.relativize((Path) dir)); + try { + Files.copy((Path) dir, newdir, REPLACE_EXISTING, COPY_ATTRIBUTES); + time = Files.getLastModifiedTime((Path) dir); + } catch (IOException e) { + System.err.println("Unable to move " + newdir + " [" + e + "]"); + return FileVisitResult.SKIP_SUBTREE; + } + + return FileVisitResult.CONTINUE; + } + + @Override + public FileVisitResult visitFile(Object file, BasicFileAttributes attrs) throws IOException { + System.out.println("Move file: " + (Path) file); + moveSubTree((Path) file, moveTo.resolve(moveFrom.relativize((Path) file))); + return FileVisitResult.CONTINUE; + } + + @Override + public FileVisitResult visitFileFailed(Object file, IOException exc) throws IOException { + return FileVisitResult.CONTINUE; + } +} + +class Main { + + public static void main(String[] args) throws IOException { + + Path moveFrom = Paths.get("C:/rafaelnadal"); + Path moveTo = Paths.get("C:/ATP/players/rafaelnadal"); + + MoveTree walk = new MoveTree(moveFrom, moveTo); + EnumSet opts = EnumSet.of(FileVisitOption.FOLLOW_LINKS); + + Files.walkFileTree(moveFrom, opts, Integer.MAX_VALUE, walk); + } +} diff --git a/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_08/build.xml b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_08/build.xml new file mode 100644 index 0000000..8033435 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_08/build.xml @@ -0,0 +1,74 @@ + + + + + + + + + + + Builds, tests, and runs the project fv_08. + + + diff --git a/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_08/build/built-jar.properties b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_08/build/built-jar.properties new file mode 100644 index 0000000..0b7ebb1 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_08/build/built-jar.properties @@ -0,0 +1,4 @@ +#Mon, 17 Oct 2011 09:57:31 +0200 + + +C\:\\NIO\\filevisitor\\fv_08= diff --git a/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_08/build/classes/fv_08/Main.class b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_08/build/classes/fv_08/Main.class new file mode 100644 index 0000000..e1dee44 Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_08/build/classes/fv_08/Main.class differ diff --git a/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_08/build/classes/fv_08/MoveTree.class b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_08/build/classes/fv_08/MoveTree.class new file mode 100644 index 0000000..eb50890 Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_08/build/classes/fv_08/MoveTree.class differ diff --git a/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_08/dist/README.TXT b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_08/dist/README.TXT new file mode 100644 index 0000000..877aca0 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_08/dist/README.TXT @@ -0,0 +1,32 @@ +======================== +BUILD OUTPUT DESCRIPTION +======================== + +When you build an Java application project that has a main class, the IDE +automatically copies all of the JAR +files on the projects classpath to your projects dist/lib folder. The IDE +also adds each of the JAR files to the Class-Path element in the application +JAR files manifest file (MANIFEST.MF). + +To run the project from the command line, go to the dist folder and +type the following: + +java -jar "fv_08.jar" + +To distribute this project, zip up the dist folder (including the lib folder) +and distribute the ZIP file. + +Notes: + +* If two JAR files on the project classpath have the same name, only the first +JAR file is copied to the lib folder. +* Only JAR files are copied to the lib folder. +If the classpath contains other types of files or folders, these files (folders) +are not copied. +* If a library on the projects classpath also has a Class-Path element +specified in the manifest,the content of the Class-Path element has to be on +the projects runtime path. +* To set a main class in a standard Java project, right-click the project node +in the Projects window and choose Properties. Then click Run and enter the +class name in the Main Class field. Alternatively, you can manually type the +class name in the manifest Main-Class element. diff --git a/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_08/dist/fv_08.jar b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_08/dist/fv_08.jar new file mode 100644 index 0000000..0e67beb Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_08/dist/fv_08.jar differ diff --git a/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_08/manifest.mf b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_08/manifest.mf new file mode 100644 index 0000000..328e8e5 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_08/manifest.mf @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +X-COMMENT: Main-Class will be added automatically by build + diff --git a/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_08/nbproject/build-impl.xml b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_08/nbproject/build-impl.xml new file mode 100644 index 0000000..7fe9ac7 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_08/nbproject/build-impl.xml @@ -0,0 +1,1041 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set src.dir + Must set test.src.dir + Must set build.dir + Must set dist.dir + Must set build.classes.dir + Must set dist.javadoc.dir + Must set build.test.classes.dir + Must set build.test.results.dir + Must set build.classes.excludes + Must set dist.jar + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set JVM to use for profiling in profiler.info.jvm + Must set profiler agent JVM arguments in profiler.info.jvmargs.agent + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + + + + + + java -cp "${run.classpath.with.dist.jar}" ${main.class} + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + java -jar "${dist.jar.resolved}" + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set run.class + + + + Must select one file in the IDE or set run.class + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set debug.class + + + + + Must select one file in the IDE or set debug.class + + + + + Must set fix.includes + + + + + + + + + + + + + + + + + Must select one file in the IDE or set profile.class + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + Some tests failed; see details above. + + + + + + + + + Must select some files in the IDE or set test.includes + + + + Some tests failed; see details above. + + + + + Must select one file in the IDE or set test.class + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_08/nbproject/genfiles.properties b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_08/nbproject/genfiles.properties new file mode 100644 index 0000000..1c4efae --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_08/nbproject/genfiles.properties @@ -0,0 +1,8 @@ +build.xml.data.CRC32=f85221bc +build.xml.script.CRC32=6dbceab5 +build.xml.stylesheet.CRC32=28e38971@1.43.1.45 +# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. +# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. +nbproject/build-impl.xml.data.CRC32=f85221bc +nbproject/build-impl.xml.script.CRC32=61f3cbbb +nbproject/build-impl.xml.stylesheet.CRC32=0c01fd8e@1.43.1.45 diff --git a/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_08/nbproject/private/private.properties b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_08/nbproject/private/private.properties new file mode 100644 index 0000000..1e08b63 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_08/nbproject/private/private.properties @@ -0,0 +1,2 @@ +compile.on.save=true +user.properties.file=C:\\Users\\Leo\\.netbeans\\7.0\\build.properties diff --git a/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_08/nbproject/private/private.xml b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_08/nbproject/private/private.xml new file mode 100644 index 0000000..c1f155a --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_08/nbproject/private/private.xml @@ -0,0 +1,4 @@ + + + + diff --git a/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_08/nbproject/project.properties b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_08/nbproject/project.properties new file mode 100644 index 0000000..61a2bd9 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_08/nbproject/project.properties @@ -0,0 +1,71 @@ +annotation.processing.enabled=true +annotation.processing.enabled.in.editor=false +annotation.processing.processor.options= +annotation.processing.processors.list= +annotation.processing.run.all.processors=true +annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output +build.classes.dir=${build.dir}/classes +build.classes.excludes=**/*.java,**/*.form +# This directory is removed when the project is cleaned: +build.dir=build +build.generated.dir=${build.dir}/generated +build.generated.sources.dir=${build.dir}/generated-sources +# Only compile against the classpath explicitly listed here: +build.sysclasspath=ignore +build.test.classes.dir=${build.dir}/test/classes +build.test.results.dir=${build.dir}/test/results +# Uncomment to specify the preferred debugger connection transport: +#debug.transport=dt_socket +debug.classpath=\ + ${run.classpath} +debug.test.classpath=\ + ${run.test.classpath} +# This directory is removed when the project is cleaned: +dist.dir=dist +dist.jar=${dist.dir}/fv_08.jar +dist.javadoc.dir=${dist.dir}/javadoc +excludes= +includes=** +jar.compress=false +javac.classpath= +# Space-separated list of extra javac options +javac.compilerargs= +javac.deprecation=false +javac.processorpath=\ + ${javac.classpath} +javac.source=1.6 +javac.target=1.6 +javac.test.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +javac.test.processorpath=\ + ${javac.test.classpath} +javadoc.additionalparam= +javadoc.author=false +javadoc.encoding=${source.encoding} +javadoc.noindex=false +javadoc.nonavbar=false +javadoc.notree=false +javadoc.private=false +javadoc.splitindex=true +javadoc.use=true +javadoc.version=false +javadoc.windowtitle= +main.class=fv_08.Main +manifest.file=manifest.mf +meta.inf.dir=${src.dir}/META-INF +mkdist.disabled=false +platform.active=default_platform +run.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +# Space-separated list of JVM arguments used when running the project +# (you may also define separate properties like run-sys-prop.name=value instead of -Dname=value +# or test-sys-prop.name=value to set system properties for unit tests): +run.jvmargs= +run.test.classpath=\ + ${javac.test.classpath}:\ + ${build.test.classes.dir} +source.encoding=UTF-8 +src.dir=src +test.src.dir=test diff --git a/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_08/nbproject/project.xml b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_08/nbproject/project.xml new file mode 100644 index 0000000..09aad2a --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_08/nbproject/project.xml @@ -0,0 +1,15 @@ + + + org.netbeans.modules.java.j2seproject + + + fv_08 + + + + + + + + + diff --git a/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_08/src/fv_08/Main.java b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_08/src/fv_08/Main.java new file mode 100644 index 0000000..e56e619 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_08/src/fv_08/Main.java @@ -0,0 +1,93 @@ +package fv_08; + +import java.io.IOException; +import java.nio.file.FileVisitOption; +import java.nio.file.FileVisitResult; +import java.nio.file.FileVisitor; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.nio.file.attribute.BasicFileAttributes; +import java.nio.file.attribute.FileTime; +import java.util.EnumSet; +import static java.nio.file.StandardCopyOption.REPLACE_EXISTING; +import static java.nio.file.StandardCopyOption.COPY_ATTRIBUTES; + +/** + * + * @author Apress + */ +class MoveTree implements FileVisitor { + + private final Path moveFrom; + private final Path moveTo; + static FileTime time = null; + + public MoveTree(Path moveFrom, Path moveTo) { + this.moveFrom = moveFrom; + this.moveTo = moveTo; + } + + static void moveSubTree(Path moveFrom, Path moveTo) throws IOException { + try { + Files.copy(moveFrom, moveTo, REPLACE_EXISTING, COPY_ATTRIBUTES); + Files.delete(moveFrom); + } catch (IOException e) { + System.err.println("Unable to move " + moveFrom + " [" + e + "]"); + } + } + + @Override + public FileVisitResult postVisitDirectory(Object dir, IOException exc) throws IOException { + Path newdir = moveTo.resolve(moveFrom.relativize((Path) dir)); + try { + Files.setLastModifiedTime(newdir, time); + Files.delete((Path) dir); + } catch (IOException e) { + System.err.println("Unable to delete: " + (Path) dir + " [" + e + "]"); + } + + return FileVisitResult.CONTINUE; + } + + @Override + public FileVisitResult preVisitDirectory(Object dir, BasicFileAttributes attrs) throws IOException { + System.out.println("Move directory: " + (Path) dir); + Path newdir = moveTo.resolve(moveFrom.relativize((Path) dir)); + try { + Files.copy((Path) dir, newdir, REPLACE_EXISTING, COPY_ATTRIBUTES); + time = Files.getLastModifiedTime((Path) dir); + } catch (IOException e) { + System.err.println("Unable to create " + newdir + " [" + e + "]"); + return FileVisitResult.SKIP_SUBTREE; + } + + return FileVisitResult.CONTINUE; + } + + @Override + public FileVisitResult visitFile(Object file, BasicFileAttributes attrs) throws IOException { + System.out.println("Move file: " + (Path) file); + moveSubTree((Path) file, moveTo.resolve(moveFrom.relativize((Path) file))); + return FileVisitResult.CONTINUE; + } + + @Override + public FileVisitResult visitFileFailed(Object file, IOException exc) throws IOException { + return FileVisitResult.CONTINUE; + } +} + +class Main { + + public static void main(String[] args) throws IOException { + + Path moveFrom = Paths.get("C:/rafaelnadal"); + Path moveTo = Paths.get("C:/ATP/players/rafaelnadal"); + + MoveTree walk = new MoveTree(moveFrom, moveTo); + EnumSet opts = EnumSet.of(FileVisitOption.FOLLOW_LINKS); + + Files.walkFileTree(moveFrom, opts, Integer.MAX_VALUE, walk); + } +} diff --git a/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_09/build.xml b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_09/build.xml new file mode 100644 index 0000000..6dd891b --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_09/build.xml @@ -0,0 +1,74 @@ + + + + + + + + + + + Builds, tests, and runs the project fv_09. + + + diff --git a/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_09/build/built-jar.properties b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_09/build/built-jar.properties new file mode 100644 index 0000000..586f3d6 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_09/build/built-jar.properties @@ -0,0 +1,4 @@ +#Mon, 17 Oct 2011 09:57:45 +0200 + + +C\:\\NIO\\filevisitor\\fv_09= diff --git a/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_09/build/classes/.netbeans_automatic_build b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_09/build/classes/.netbeans_automatic_build new file mode 100644 index 0000000..e69de29 diff --git a/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_09/build/classes/fv_09/ListTree.class b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_09/build/classes/fv_09/ListTree.class new file mode 100644 index 0000000..78d8eb8 Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_09/build/classes/fv_09/ListTree.class differ diff --git a/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_09/build/classes/fv_09/Main.class b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_09/build/classes/fv_09/Main.class new file mode 100644 index 0000000..0ba3dba Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_09/build/classes/fv_09/Main.class differ diff --git a/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_09/build/classes/fv_09/Main.rs b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_09/build/classes/fv_09/Main.rs new file mode 100644 index 0000000..8d7c1c8 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_09/build/classes/fv_09/Main.rs @@ -0,0 +1,2 @@ +fv_09.ListTree +fv_09.Main diff --git a/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_09/dist/README.TXT b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_09/dist/README.TXT new file mode 100644 index 0000000..f19d46b --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_09/dist/README.TXT @@ -0,0 +1,32 @@ +======================== +BUILD OUTPUT DESCRIPTION +======================== + +When you build an Java application project that has a main class, the IDE +automatically copies all of the JAR +files on the projects classpath to your projects dist/lib folder. The IDE +also adds each of the JAR files to the Class-Path element in the application +JAR files manifest file (MANIFEST.MF). + +To run the project from the command line, go to the dist folder and +type the following: + +java -jar "fv_09.jar" + +To distribute this project, zip up the dist folder (including the lib folder) +and distribute the ZIP file. + +Notes: + +* If two JAR files on the project classpath have the same name, only the first +JAR file is copied to the lib folder. +* Only JAR files are copied to the lib folder. +If the classpath contains other types of files or folders, these files (folders) +are not copied. +* If a library on the projects classpath also has a Class-Path element +specified in the manifest,the content of the Class-Path element has to be on +the projects runtime path. +* To set a main class in a standard Java project, right-click the project node +in the Projects window and choose Properties. Then click Run and enter the +class name in the Main Class field. Alternatively, you can manually type the +class name in the manifest Main-Class element. diff --git a/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_09/dist/fv_09.jar b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_09/dist/fv_09.jar new file mode 100644 index 0000000..c101900 Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_09/dist/fv_09.jar differ diff --git a/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_09/manifest.mf b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_09/manifest.mf new file mode 100644 index 0000000..328e8e5 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_09/manifest.mf @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +X-COMMENT: Main-Class will be added automatically by build + diff --git a/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_09/nbproject/build-impl.xml b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_09/nbproject/build-impl.xml new file mode 100644 index 0000000..d39ba83 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_09/nbproject/build-impl.xml @@ -0,0 +1,1041 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set src.dir + Must set test.src.dir + Must set build.dir + Must set dist.dir + Must set build.classes.dir + Must set dist.javadoc.dir + Must set build.test.classes.dir + Must set build.test.results.dir + Must set build.classes.excludes + Must set dist.jar + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set JVM to use for profiling in profiler.info.jvm + Must set profiler agent JVM arguments in profiler.info.jvmargs.agent + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + + + + + + java -cp "${run.classpath.with.dist.jar}" ${main.class} + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + java -jar "${dist.jar.resolved}" + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set run.class + + + + Must select one file in the IDE or set run.class + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set debug.class + + + + + Must select one file in the IDE or set debug.class + + + + + Must set fix.includes + + + + + + + + + + + + + + + + + Must select one file in the IDE or set profile.class + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + Some tests failed; see details above. + + + + + + + + + Must select some files in the IDE or set test.includes + + + + Some tests failed; see details above. + + + + + Must select one file in the IDE or set test.class + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_09/nbproject/genfiles.properties b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_09/nbproject/genfiles.properties new file mode 100644 index 0000000..04650f8 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_09/nbproject/genfiles.properties @@ -0,0 +1,8 @@ +build.xml.data.CRC32=f041ad9a +build.xml.script.CRC32=91501a31 +build.xml.stylesheet.CRC32=28e38971@1.43.1.45 +# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. +# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. +nbproject/build-impl.xml.data.CRC32=f041ad9a +nbproject/build-impl.xml.script.CRC32=d67a3fc0 +nbproject/build-impl.xml.stylesheet.CRC32=0c01fd8e@1.43.1.45 diff --git a/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_09/nbproject/private/config.properties b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_09/nbproject/private/config.properties new file mode 100644 index 0000000..e69de29 diff --git a/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_09/nbproject/private/private.properties b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_09/nbproject/private/private.properties new file mode 100644 index 0000000..a5ab360 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_09/nbproject/private/private.properties @@ -0,0 +1,6 @@ +compile.on.save=true +do.depend=false +do.jar=true +javac.debug=true +javadoc.preview=true +user.properties.file=C:\\Users\\Leo\\.netbeans\\7.0\\build.properties diff --git a/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_09/nbproject/private/private.xml b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_09/nbproject/private/private.xml new file mode 100644 index 0000000..c1f155a --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_09/nbproject/private/private.xml @@ -0,0 +1,4 @@ + + + + diff --git a/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_09/nbproject/project.properties b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_09/nbproject/project.properties new file mode 100644 index 0000000..514c12c --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_09/nbproject/project.properties @@ -0,0 +1,72 @@ +annotation.processing.enabled=true +annotation.processing.enabled.in.editor=false +annotation.processing.run.all.processors=true +annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output +application.title=fv_09 +application.vendor=Leo +build.classes.dir=${build.dir}/classes +build.classes.excludes=**/*.java,**/*.form +# This directory is removed when the project is cleaned: +build.dir=build +build.generated.dir=${build.dir}/generated +build.generated.sources.dir=${build.dir}/generated-sources +# Only compile against the classpath explicitly listed here: +build.sysclasspath=ignore +build.test.classes.dir=${build.dir}/test/classes +build.test.results.dir=${build.dir}/test/results +# Uncomment to specify the preferred debugger connection transport: +#debug.transport=dt_socket +debug.classpath=\ + ${run.classpath} +debug.test.classpath=\ + ${run.test.classpath} +# This directory is removed when the project is cleaned: +dist.dir=dist +dist.jar=${dist.dir}/fv_09.jar +dist.javadoc.dir=${dist.dir}/javadoc +endorsed.classpath= +excludes= +includes=** +jar.compress=false +javac.classpath= +# Space-separated list of extra javac options +javac.compilerargs= +javac.deprecation=false +javac.processorpath=\ + ${javac.classpath} +javac.source=1.7 +javac.target=1.7 +javac.test.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +javac.test.processorpath=\ + ${javac.test.classpath} +javadoc.additionalparam= +javadoc.author=false +javadoc.encoding=${source.encoding} +javadoc.noindex=false +javadoc.nonavbar=false +javadoc.notree=false +javadoc.private=false +javadoc.splitindex=true +javadoc.use=true +javadoc.version=false +javadoc.windowtitle= +main.class=fv_09.Main +manifest.file=manifest.mf +meta.inf.dir=${src.dir}/META-INF +mkdist.disabled=false +platform.active=default_platform +run.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +# Space-separated list of JVM arguments used when running the project +# (you may also define separate properties like run-sys-prop.name=value instead of -Dname=value +# or test-sys-prop.name=value to set system properties for unit tests): +run.jvmargs= +run.test.classpath=\ + ${javac.test.classpath}:\ + ${build.test.classes.dir} +source.encoding=UTF-8 +src.dir=src +test.src.dir=test diff --git a/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_09/nbproject/project.xml b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_09/nbproject/project.xml new file mode 100644 index 0000000..2ef5d3c --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_09/nbproject/project.xml @@ -0,0 +1,15 @@ + + + org.netbeans.modules.java.j2seproject + + + fv_09 + + + + + + + + + diff --git a/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_09/src/fv_09/Main.java b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_09/src/fv_09/Main.java new file mode 100644 index 0000000..9858dd7 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter05/filevisitor/fv_09/src/fv_09/Main.java @@ -0,0 +1,46 @@ +package fv_09; + +import java.io.IOException; +import java.nio.file.FileVisitOption; +import java.nio.file.FileVisitResult; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.nio.file.SimpleFileVisitor; +import java.util.EnumSet; + +/** + * + * @author Apress + */ +class ListTree extends SimpleFileVisitor { + + @Override + public FileVisitResult postVisitDirectory(Path dir, IOException exc) { + + System.out.println("Visited directory: " + dir.toString()); + + return FileVisitResult.CONTINUE; + } + + @Override + public FileVisitResult visitFileFailed(Path file, IOException exc) { + + System.out.println(exc); + + return FileVisitResult.CONTINUE; + } +} + +public class Main { + + public static void main(String[] args) throws IOException { + + Path listDir = Paths.get("C:/rafaelnadal"); + ListTree walk = new ListTree(); + EnumSet opts = EnumSet.of(FileVisitOption.FOLLOW_LINKS); + + Files.walkFileTree(listDir, opts, Integer.MAX_VALUE, walk); + + } +} diff --git a/Pro Java 7 NIO.2/Chapter06/watch/watch_01/build.xml b/Pro Java 7 NIO.2/Chapter06/watch/watch_01/build.xml new file mode 100644 index 0000000..77d5c76 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter06/watch/watch_01/build.xml @@ -0,0 +1,74 @@ + + + + + + + + + + + Builds, tests, and runs the project watch_01. + + + diff --git a/Pro Java 7 NIO.2/Chapter06/watch/watch_01/build/built-jar.properties b/Pro Java 7 NIO.2/Chapter06/watch/watch_01/build/built-jar.properties new file mode 100644 index 0000000..df5a0a2 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter06/watch/watch_01/build/built-jar.properties @@ -0,0 +1,4 @@ +#Mon, 17 Oct 2011 11:07:17 +0200 + + +C\:\\NIO\\watch\\watch_01= diff --git a/Pro Java 7 NIO.2/Chapter06/watch/watch_01/build/classes/.netbeans_automatic_build b/Pro Java 7 NIO.2/Chapter06/watch/watch_01/build/classes/.netbeans_automatic_build new file mode 100644 index 0000000..e69de29 diff --git a/Pro Java 7 NIO.2/Chapter06/watch/watch_01/build/classes/watch_01/Main.class b/Pro Java 7 NIO.2/Chapter06/watch/watch_01/build/classes/watch_01/Main.class new file mode 100644 index 0000000..ba72e76 Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter06/watch/watch_01/build/classes/watch_01/Main.class differ diff --git a/Pro Java 7 NIO.2/Chapter06/watch/watch_01/build/classes/watch_01/Main.rs b/Pro Java 7 NIO.2/Chapter06/watch/watch_01/build/classes/watch_01/Main.rs new file mode 100644 index 0000000..7d66ff1 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter06/watch/watch_01/build/classes/watch_01/Main.rs @@ -0,0 +1,2 @@ +watch_01.WatchRafaelNadal +watch_01.Main diff --git a/Pro Java 7 NIO.2/Chapter06/watch/watch_01/build/classes/watch_01/WatchRafaelNadal.class b/Pro Java 7 NIO.2/Chapter06/watch/watch_01/build/classes/watch_01/WatchRafaelNadal.class new file mode 100644 index 0000000..c983aca Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter06/watch/watch_01/build/classes/watch_01/WatchRafaelNadal.class differ diff --git a/Pro Java 7 NIO.2/Chapter06/watch/watch_01/dist/README.TXT b/Pro Java 7 NIO.2/Chapter06/watch/watch_01/dist/README.TXT new file mode 100644 index 0000000..d0562ec --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter06/watch/watch_01/dist/README.TXT @@ -0,0 +1,32 @@ +======================== +BUILD OUTPUT DESCRIPTION +======================== + +When you build an Java application project that has a main class, the IDE +automatically copies all of the JAR +files on the projects classpath to your projects dist/lib folder. The IDE +also adds each of the JAR files to the Class-Path element in the application +JAR files manifest file (MANIFEST.MF). + +To run the project from the command line, go to the dist folder and +type the following: + +java -jar "watch_01.jar" + +To distribute this project, zip up the dist folder (including the lib folder) +and distribute the ZIP file. + +Notes: + +* If two JAR files on the project classpath have the same name, only the first +JAR file is copied to the lib folder. +* Only JAR files are copied to the lib folder. +If the classpath contains other types of files or folders, these files (folders) +are not copied. +* If a library on the projects classpath also has a Class-Path element +specified in the manifest,the content of the Class-Path element has to be on +the projects runtime path. +* To set a main class in a standard Java project, right-click the project node +in the Projects window and choose Properties. Then click Run and enter the +class name in the Main Class field. Alternatively, you can manually type the +class name in the manifest Main-Class element. diff --git a/Pro Java 7 NIO.2/Chapter06/watch/watch_01/dist/watch_01.jar b/Pro Java 7 NIO.2/Chapter06/watch/watch_01/dist/watch_01.jar new file mode 100644 index 0000000..6c749d8 Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter06/watch/watch_01/dist/watch_01.jar differ diff --git a/Pro Java 7 NIO.2/Chapter06/watch/watch_01/manifest.mf b/Pro Java 7 NIO.2/Chapter06/watch/watch_01/manifest.mf new file mode 100644 index 0000000..328e8e5 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter06/watch/watch_01/manifest.mf @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +X-COMMENT: Main-Class will be added automatically by build + diff --git a/Pro Java 7 NIO.2/Chapter06/watch/watch_01/nbproject/build-impl.xml b/Pro Java 7 NIO.2/Chapter06/watch/watch_01/nbproject/build-impl.xml new file mode 100644 index 0000000..37a16d8 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter06/watch/watch_01/nbproject/build-impl.xml @@ -0,0 +1,1041 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set src.dir + Must set test.src.dir + Must set build.dir + Must set dist.dir + Must set build.classes.dir + Must set dist.javadoc.dir + Must set build.test.classes.dir + Must set build.test.results.dir + Must set build.classes.excludes + Must set dist.jar + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set JVM to use for profiling in profiler.info.jvm + Must set profiler agent JVM arguments in profiler.info.jvmargs.agent + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + + + + + + java -cp "${run.classpath.with.dist.jar}" ${main.class} + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + java -jar "${dist.jar.resolved}" + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set run.class + + + + Must select one file in the IDE or set run.class + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set debug.class + + + + + Must select one file in the IDE or set debug.class + + + + + Must set fix.includes + + + + + + + + + + + + + + + + + Must select one file in the IDE or set profile.class + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + Some tests failed; see details above. + + + + + + + + + Must select some files in the IDE or set test.includes + + + + Some tests failed; see details above. + + + + + Must select one file in the IDE or set test.class + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Pro Java 7 NIO.2/Chapter06/watch/watch_01/nbproject/genfiles.properties b/Pro Java 7 NIO.2/Chapter06/watch/watch_01/nbproject/genfiles.properties new file mode 100644 index 0000000..a1e0dc3 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter06/watch/watch_01/nbproject/genfiles.properties @@ -0,0 +1,8 @@ +build.xml.data.CRC32=05548c5e +build.xml.script.CRC32=484bc60a +build.xml.stylesheet.CRC32=28e38971@1.43.1.45 +# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. +# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. +nbproject/build-impl.xml.data.CRC32=05548c5e +nbproject/build-impl.xml.script.CRC32=471cab0c +nbproject/build-impl.xml.stylesheet.CRC32=0c01fd8e@1.43.1.45 diff --git a/Pro Java 7 NIO.2/Chapter06/watch/watch_01/nbproject/private/config.properties b/Pro Java 7 NIO.2/Chapter06/watch/watch_01/nbproject/private/config.properties new file mode 100644 index 0000000..e69de29 diff --git a/Pro Java 7 NIO.2/Chapter06/watch/watch_01/nbproject/private/private.properties b/Pro Java 7 NIO.2/Chapter06/watch/watch_01/nbproject/private/private.properties new file mode 100644 index 0000000..a5ab360 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter06/watch/watch_01/nbproject/private/private.properties @@ -0,0 +1,6 @@ +compile.on.save=true +do.depend=false +do.jar=true +javac.debug=true +javadoc.preview=true +user.properties.file=C:\\Users\\Leo\\.netbeans\\7.0\\build.properties diff --git a/Pro Java 7 NIO.2/Chapter06/watch/watch_01/nbproject/private/private.xml b/Pro Java 7 NIO.2/Chapter06/watch/watch_01/nbproject/private/private.xml new file mode 100644 index 0000000..c1f155a --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter06/watch/watch_01/nbproject/private/private.xml @@ -0,0 +1,4 @@ + + + + diff --git a/Pro Java 7 NIO.2/Chapter06/watch/watch_01/nbproject/project.properties b/Pro Java 7 NIO.2/Chapter06/watch/watch_01/nbproject/project.properties new file mode 100644 index 0000000..e92cba1 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter06/watch/watch_01/nbproject/project.properties @@ -0,0 +1,72 @@ +annotation.processing.enabled=true +annotation.processing.enabled.in.editor=false +annotation.processing.run.all.processors=true +annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output +application.title=watch_01 +application.vendor=Leo +build.classes.dir=${build.dir}/classes +build.classes.excludes=**/*.java,**/*.form +# This directory is removed when the project is cleaned: +build.dir=build +build.generated.dir=${build.dir}/generated +build.generated.sources.dir=${build.dir}/generated-sources +# Only compile against the classpath explicitly listed here: +build.sysclasspath=ignore +build.test.classes.dir=${build.dir}/test/classes +build.test.results.dir=${build.dir}/test/results +# Uncomment to specify the preferred debugger connection transport: +#debug.transport=dt_socket +debug.classpath=\ + ${run.classpath} +debug.test.classpath=\ + ${run.test.classpath} +# This directory is removed when the project is cleaned: +dist.dir=dist +dist.jar=${dist.dir}/watch_01.jar +dist.javadoc.dir=${dist.dir}/javadoc +endorsed.classpath= +excludes= +includes=** +jar.compress=false +javac.classpath= +# Space-separated list of extra javac options +javac.compilerargs= +javac.deprecation=false +javac.processorpath=\ + ${javac.classpath} +javac.source=1.7 +javac.target=1.7 +javac.test.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +javac.test.processorpath=\ + ${javac.test.classpath} +javadoc.additionalparam= +javadoc.author=false +javadoc.encoding=${source.encoding} +javadoc.noindex=false +javadoc.nonavbar=false +javadoc.notree=false +javadoc.private=false +javadoc.splitindex=true +javadoc.use=true +javadoc.version=false +javadoc.windowtitle= +main.class=watch_01.Main +manifest.file=manifest.mf +meta.inf.dir=${src.dir}/META-INF +mkdist.disabled=false +platform.active=default_platform +run.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +# Space-separated list of JVM arguments used when running the project +# (you may also define separate properties like run-sys-prop.name=value instead of -Dname=value +# or test-sys-prop.name=value to set system properties for unit tests): +run.jvmargs= +run.test.classpath=\ + ${javac.test.classpath}:\ + ${build.test.classes.dir} +source.encoding=UTF-8 +src.dir=src +test.src.dir=test diff --git a/Pro Java 7 NIO.2/Chapter06/watch/watch_01/nbproject/project.xml b/Pro Java 7 NIO.2/Chapter06/watch/watch_01/nbproject/project.xml new file mode 100644 index 0000000..1932ba4 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter06/watch/watch_01/nbproject/project.xml @@ -0,0 +1,15 @@ + + + org.netbeans.modules.java.j2seproject + + + watch_01 + + + + + + + + + diff --git a/Pro Java 7 NIO.2/Chapter06/watch/watch_01/src/watch_01/Main.java b/Pro Java 7 NIO.2/Chapter06/watch/watch_01/src/watch_01/Main.java new file mode 100644 index 0000000..a3c9532 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter06/watch/watch_01/src/watch_01/Main.java @@ -0,0 +1,75 @@ +package watch_01; + +import java.io.IOException; +import java.nio.file.FileSystems; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.nio.file.StandardWatchEventKinds; +import java.nio.file.WatchEvent; +import java.nio.file.WatchEvent.Kind; +import java.nio.file.WatchKey; +import java.nio.file.WatchService; + +/** + * + * @author Apress + */ +class WatchRafaelNadal { + + public void watchRNDir(Path path) throws IOException, InterruptedException { + try (WatchService watchService = FileSystems.getDefault().newWatchService()) { + path.register(watchService, StandardWatchEventKinds.ENTRY_CREATE, StandardWatchEventKinds.ENTRY_MODIFY, StandardWatchEventKinds.ENTRY_DELETE); + + //start an infinite loop + while (true) { + + //retrieve and remove the next watch key + final WatchKey key = watchService.take(); + + //get list of pending events for the watch key + for (WatchEvent watchEvent : key.pollEvents()) { + + //get the kind of event (create, modify, delete) + final Kind kind = watchEvent.kind(); + + //handle OVERFLOW event + if (kind == StandardWatchEventKinds.OVERFLOW) { + continue; + } + + //get the filename for the event + final WatchEvent watchEventPath = (WatchEvent) watchEvent; + final Path filename = watchEventPath.context(); + + //print it out + System.out.println(kind + " -> " + filename); + } + + //reset the key + boolean valid = key.reset(); + + //exit loop if the key is not valid (if the directory was deleted, per example) + if (!valid) { + break; + } + + } + } + } +} + +public class Main { + + public static void main(String[] args) { + + final Path path = Paths.get("C:/rafaelnadal"); + WatchRafaelNadal watch = new WatchRafaelNadal(); + + try { + watch.watchRNDir(path); + } catch (IOException | InterruptedException ex) { + System.err.println(ex); + } + + } +} diff --git a/Pro Java 7 NIO.2/Chapter06/watch/watch_02/build.xml b/Pro Java 7 NIO.2/Chapter06/watch/watch_02/build.xml new file mode 100644 index 0000000..660d465 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter06/watch/watch_02/build.xml @@ -0,0 +1,74 @@ + + + + + + + + + + + Builds, tests, and runs the project watch_02. + + + diff --git a/Pro Java 7 NIO.2/Chapter06/watch/watch_02/build/built-jar.properties b/Pro Java 7 NIO.2/Chapter06/watch/watch_02/build/built-jar.properties new file mode 100644 index 0000000..5d82285 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter06/watch/watch_02/build/built-jar.properties @@ -0,0 +1,4 @@ +#Mon, 17 Oct 2011 11:21:28 +0200 + + +C\:\\NIO\\watch\\watch_02= diff --git a/Pro Java 7 NIO.2/Chapter06/watch/watch_02/build/classes/watch_02/Main.class b/Pro Java 7 NIO.2/Chapter06/watch/watch_02/build/classes/watch_02/Main.class new file mode 100644 index 0000000..f6e81e5 Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter06/watch/watch_02/build/classes/watch_02/Main.class differ diff --git a/Pro Java 7 NIO.2/Chapter06/watch/watch_02/build/classes/watch_02/SecurityWatch.class b/Pro Java 7 NIO.2/Chapter06/watch/watch_02/build/classes/watch_02/SecurityWatch.class new file mode 100644 index 0000000..c6a4338 Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter06/watch/watch_02/build/classes/watch_02/SecurityWatch.class differ diff --git a/Pro Java 7 NIO.2/Chapter06/watch/watch_02/dist/README.TXT b/Pro Java 7 NIO.2/Chapter06/watch/watch_02/dist/README.TXT new file mode 100644 index 0000000..2fcd99c --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter06/watch/watch_02/dist/README.TXT @@ -0,0 +1,32 @@ +======================== +BUILD OUTPUT DESCRIPTION +======================== + +When you build an Java application project that has a main class, the IDE +automatically copies all of the JAR +files on the projects classpath to your projects dist/lib folder. The IDE +also adds each of the JAR files to the Class-Path element in the application +JAR files manifest file (MANIFEST.MF). + +To run the project from the command line, go to the dist folder and +type the following: + +java -jar "watch_02.jar" + +To distribute this project, zip up the dist folder (including the lib folder) +and distribute the ZIP file. + +Notes: + +* If two JAR files on the project classpath have the same name, only the first +JAR file is copied to the lib folder. +* Only JAR files are copied to the lib folder. +If the classpath contains other types of files or folders, these files (folders) +are not copied. +* If a library on the projects classpath also has a Class-Path element +specified in the manifest,the content of the Class-Path element has to be on +the projects runtime path. +* To set a main class in a standard Java project, right-click the project node +in the Projects window and choose Properties. Then click Run and enter the +class name in the Main Class field. Alternatively, you can manually type the +class name in the manifest Main-Class element. diff --git a/Pro Java 7 NIO.2/Chapter06/watch/watch_02/dist/watch_02.jar b/Pro Java 7 NIO.2/Chapter06/watch/watch_02/dist/watch_02.jar new file mode 100644 index 0000000..65758b5 Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter06/watch/watch_02/dist/watch_02.jar differ diff --git a/Pro Java 7 NIO.2/Chapter06/watch/watch_02/manifest.mf b/Pro Java 7 NIO.2/Chapter06/watch/watch_02/manifest.mf new file mode 100644 index 0000000..328e8e5 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter06/watch/watch_02/manifest.mf @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +X-COMMENT: Main-Class will be added automatically by build + diff --git a/Pro Java 7 NIO.2/Chapter06/watch/watch_02/nbproject/build-impl.xml b/Pro Java 7 NIO.2/Chapter06/watch/watch_02/nbproject/build-impl.xml new file mode 100644 index 0000000..e84944e --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter06/watch/watch_02/nbproject/build-impl.xml @@ -0,0 +1,1041 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set src.dir + Must set test.src.dir + Must set build.dir + Must set dist.dir + Must set build.classes.dir + Must set dist.javadoc.dir + Must set build.test.classes.dir + Must set build.test.results.dir + Must set build.classes.excludes + Must set dist.jar + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set JVM to use for profiling in profiler.info.jvm + Must set profiler agent JVM arguments in profiler.info.jvmargs.agent + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + + + + + + java -cp "${run.classpath.with.dist.jar}" ${main.class} + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + java -jar "${dist.jar.resolved}" + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set run.class + + + + Must select one file in the IDE or set run.class + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set debug.class + + + + + Must select one file in the IDE or set debug.class + + + + + Must set fix.includes + + + + + + + + + + + + + + + + + Must select one file in the IDE or set profile.class + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + Some tests failed; see details above. + + + + + + + + + Must select some files in the IDE or set test.includes + + + + Some tests failed; see details above. + + + + + Must select one file in the IDE or set test.class + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Pro Java 7 NIO.2/Chapter06/watch/watch_02/nbproject/genfiles.properties b/Pro Java 7 NIO.2/Chapter06/watch/watch_02/nbproject/genfiles.properties new file mode 100644 index 0000000..c8516ef --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter06/watch/watch_02/nbproject/genfiles.properties @@ -0,0 +1,8 @@ +build.xml.data.CRC32=1d601834 +build.xml.script.CRC32=b0f6260f +build.xml.stylesheet.CRC32=28e38971@1.43.1.45 +# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. +# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. +nbproject/build-impl.xml.data.CRC32=1d601834 +nbproject/build-impl.xml.script.CRC32=17e52be9 +nbproject/build-impl.xml.stylesheet.CRC32=0c01fd8e@1.43.1.45 diff --git a/Pro Java 7 NIO.2/Chapter06/watch/watch_02/nbproject/private/config.properties b/Pro Java 7 NIO.2/Chapter06/watch/watch_02/nbproject/private/config.properties new file mode 100644 index 0000000..e69de29 diff --git a/Pro Java 7 NIO.2/Chapter06/watch/watch_02/nbproject/private/private.properties b/Pro Java 7 NIO.2/Chapter06/watch/watch_02/nbproject/private/private.properties new file mode 100644 index 0000000..a5ab360 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter06/watch/watch_02/nbproject/private/private.properties @@ -0,0 +1,6 @@ +compile.on.save=true +do.depend=false +do.jar=true +javac.debug=true +javadoc.preview=true +user.properties.file=C:\\Users\\Leo\\.netbeans\\7.0\\build.properties diff --git a/Pro Java 7 NIO.2/Chapter06/watch/watch_02/nbproject/private/private.xml b/Pro Java 7 NIO.2/Chapter06/watch/watch_02/nbproject/private/private.xml new file mode 100644 index 0000000..c1f155a --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter06/watch/watch_02/nbproject/private/private.xml @@ -0,0 +1,4 @@ + + + + diff --git a/Pro Java 7 NIO.2/Chapter06/watch/watch_02/nbproject/project.properties b/Pro Java 7 NIO.2/Chapter06/watch/watch_02/nbproject/project.properties new file mode 100644 index 0000000..6e72a63 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter06/watch/watch_02/nbproject/project.properties @@ -0,0 +1,72 @@ +annotation.processing.enabled=true +annotation.processing.enabled.in.editor=false +annotation.processing.run.all.processors=true +annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output +application.title=watch_02 +application.vendor=Leo +build.classes.dir=${build.dir}/classes +build.classes.excludes=**/*.java,**/*.form +# This directory is removed when the project is cleaned: +build.dir=build +build.generated.dir=${build.dir}/generated +build.generated.sources.dir=${build.dir}/generated-sources +# Only compile against the classpath explicitly listed here: +build.sysclasspath=ignore +build.test.classes.dir=${build.dir}/test/classes +build.test.results.dir=${build.dir}/test/results +# Uncomment to specify the preferred debugger connection transport: +#debug.transport=dt_socket +debug.classpath=\ + ${run.classpath} +debug.test.classpath=\ + ${run.test.classpath} +# This directory is removed when the project is cleaned: +dist.dir=dist +dist.jar=${dist.dir}/watch_02.jar +dist.javadoc.dir=${dist.dir}/javadoc +endorsed.classpath= +excludes= +includes=** +jar.compress=false +javac.classpath= +# Space-separated list of extra javac options +javac.compilerargs= +javac.deprecation=false +javac.processorpath=\ + ${javac.classpath} +javac.source=1.7 +javac.target=1.7 +javac.test.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +javac.test.processorpath=\ + ${javac.test.classpath} +javadoc.additionalparam= +javadoc.author=false +javadoc.encoding=${source.encoding} +javadoc.noindex=false +javadoc.nonavbar=false +javadoc.notree=false +javadoc.private=false +javadoc.splitindex=true +javadoc.use=true +javadoc.version=false +javadoc.windowtitle= +main.class=watch_02.Main +manifest.file=manifest.mf +meta.inf.dir=${src.dir}/META-INF +mkdist.disabled=false +platform.active=default_platform +run.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +# Space-separated list of JVM arguments used when running the project +# (you may also define separate properties like run-sys-prop.name=value instead of -Dname=value +# or test-sys-prop.name=value to set system properties for unit tests): +run.jvmargs= +run.test.classpath=\ + ${javac.test.classpath}:\ + ${build.test.classes.dir} +source.encoding=UTF-8 +src.dir=src +test.src.dir=test diff --git a/Pro Java 7 NIO.2/Chapter06/watch/watch_02/nbproject/project.xml b/Pro Java 7 NIO.2/Chapter06/watch/watch_02/nbproject/project.xml new file mode 100644 index 0000000..4c7713c --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter06/watch/watch_02/nbproject/project.xml @@ -0,0 +1,15 @@ + + + org.netbeans.modules.java.j2seproject + + + watch_02 + + + + + + + + + diff --git a/Pro Java 7 NIO.2/Chapter06/watch/watch_02/src/watch_02/Main.java b/Pro Java 7 NIO.2/Chapter06/watch/watch_02/src/watch_02/Main.java new file mode 100644 index 0000000..94ee919 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter06/watch/watch_02/src/watch_02/Main.java @@ -0,0 +1,105 @@ +package watch_02; + +import java.io.IOException; +import java.nio.file.FileSystems; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.nio.file.StandardWatchEventKinds; +import java.nio.file.WatchEvent; +import java.nio.file.WatchEvent.Kind; +import java.nio.file.WatchKey; +import java.nio.file.WatchService; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.concurrent.TimeUnit; + +/** + * + * @author Apress + */ +class SecurityWatch { + + WatchService watchService; + + private void register(Path path, Kind kind) throws IOException { + //register the directory with the watchService for Kind event + path.register(watchService, kind); + } + + public void watchVideoCamera(Path path) throws IOException, InterruptedException { + + watchService = FileSystems.getDefault().newWatchService(); + register(path, StandardWatchEventKinds.ENTRY_CREATE); + + //start an infinite loop + OUTERMOST: + while (true) { + + //retrieve and remove the next watch key + final WatchKey key = watchService.poll(11, TimeUnit.SECONDS); + + if (key == null) { + System.out.println("The video camera is jammed - security watch system is canceled!"); + break; + } else { + + //get list of events for the watch key + for (WatchEvent watchEvent : key.pollEvents()) { + + //get the kind of event (create, modify, delete) + final Kind kind = watchEvent.kind(); + + //handle OVERFLOW event + if (kind == StandardWatchEventKinds.OVERFLOW) { + continue; + } + + if (kind == StandardWatchEventKinds.ENTRY_CREATE) { + + //get the filename for the event + final WatchEvent watchEventPath = (WatchEvent) watchEvent; + final Path filename = watchEventPath.context(); + final Path child = path.resolve(filename); + + if (Files.probeContentType(child).equals("image/jpeg")) { + + //print it out the video capture time + SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MMM-dd HH:mm:ss"); + System.out.println("Video capture successfully at: " + dateFormat.format(new Date())); + } else { + System.out.println("The video camera capture format failed! This could be a virus!"); + break OUTERMOST; + } + } + } + + //reset the key + boolean valid = key.reset(); + + //exit loop if the key is not valid (if the directory was deleted, per example) + if (!valid) { + break; + } + } + } + + watchService.close(); + } +} + +public class Main { + + public static void main(String[] args) { + + final Path path = Paths.get("C:/security"); + SecurityWatch watch = new SecurityWatch(); + + try { + watch.watchVideoCamera(path); + } catch (IOException | InterruptedException ex) { + System.err.println(ex); + } + + } +} diff --git a/Pro Java 7 NIO.2/Chapter06/watch/watch_03/build.xml b/Pro Java 7 NIO.2/Chapter06/watch/watch_03/build.xml new file mode 100644 index 0000000..c3c9cd0 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter06/watch/watch_03/build.xml @@ -0,0 +1,74 @@ + + + + + + + + + + + Builds, tests, and runs the project watch_03. + + + diff --git a/Pro Java 7 NIO.2/Chapter06/watch/watch_03/build/built-jar.properties b/Pro Java 7 NIO.2/Chapter06/watch/watch_03/build/built-jar.properties new file mode 100644 index 0000000..72dd248 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter06/watch/watch_03/build/built-jar.properties @@ -0,0 +1,4 @@ +#Mon, 17 Oct 2011 11:39:19 +0200 + + +C\:\\NIO\\watch\\watch_03= diff --git a/Pro Java 7 NIO.2/Chapter06/watch/watch_03/build/classes/.netbeans_automatic_build b/Pro Java 7 NIO.2/Chapter06/watch/watch_03/build/classes/.netbeans_automatic_build new file mode 100644 index 0000000..e69de29 diff --git a/Pro Java 7 NIO.2/Chapter06/watch/watch_03/build/classes/watch_03/Main.class b/Pro Java 7 NIO.2/Chapter06/watch/watch_03/build/classes/watch_03/Main.class new file mode 100644 index 0000000..f918495 Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter06/watch/watch_03/build/classes/watch_03/Main.class differ diff --git a/Pro Java 7 NIO.2/Chapter06/watch/watch_03/build/classes/watch_03/Main.rs b/Pro Java 7 NIO.2/Chapter06/watch/watch_03/build/classes/watch_03/Main.rs new file mode 100644 index 0000000..0b1d82c --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter06/watch/watch_03/build/classes/watch_03/Main.rs @@ -0,0 +1,3 @@ +watch_03.Main +watch_03.Print +watch_03.WatchPrinterTray diff --git a/Pro Java 7 NIO.2/Chapter06/watch/watch_03/build/classes/watch_03/Print$Main.class b/Pro Java 7 NIO.2/Chapter06/watch/watch_03/build/classes/watch_03/Print$Main.class new file mode 100644 index 0000000..22597a7 Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter06/watch/watch_03/build/classes/watch_03/Print$Main.class differ diff --git a/Pro Java 7 NIO.2/Chapter06/watch/watch_03/build/classes/watch_03/Print$WatchPrinterTray.class b/Pro Java 7 NIO.2/Chapter06/watch/watch_03/build/classes/watch_03/Print$WatchPrinterTray.class new file mode 100644 index 0000000..c4ff792 Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter06/watch/watch_03/build/classes/watch_03/Print$WatchPrinterTray.class differ diff --git a/Pro Java 7 NIO.2/Chapter06/watch/watch_03/build/classes/watch_03/Print.class b/Pro Java 7 NIO.2/Chapter06/watch/watch_03/build/classes/watch_03/Print.class new file mode 100644 index 0000000..dfd3472 Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter06/watch/watch_03/build/classes/watch_03/Print.class differ diff --git a/Pro Java 7 NIO.2/Chapter06/watch/watch_03/build/classes/watch_03/WatchPrinterTray.class b/Pro Java 7 NIO.2/Chapter06/watch/watch_03/build/classes/watch_03/WatchPrinterTray.class new file mode 100644 index 0000000..2a0a597 Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter06/watch/watch_03/build/classes/watch_03/WatchPrinterTray.class differ diff --git a/Pro Java 7 NIO.2/Chapter06/watch/watch_03/dist/README.TXT b/Pro Java 7 NIO.2/Chapter06/watch/watch_03/dist/README.TXT new file mode 100644 index 0000000..6908b81 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter06/watch/watch_03/dist/README.TXT @@ -0,0 +1,32 @@ +======================== +BUILD OUTPUT DESCRIPTION +======================== + +When you build an Java application project that has a main class, the IDE +automatically copies all of the JAR +files on the projects classpath to your projects dist/lib folder. The IDE +also adds each of the JAR files to the Class-Path element in the application +JAR files manifest file (MANIFEST.MF). + +To run the project from the command line, go to the dist folder and +type the following: + +java -jar "watch_03.jar" + +To distribute this project, zip up the dist folder (including the lib folder) +and distribute the ZIP file. + +Notes: + +* If two JAR files on the project classpath have the same name, only the first +JAR file is copied to the lib folder. +* Only JAR files are copied to the lib folder. +If the classpath contains other types of files or folders, these files (folders) +are not copied. +* If a library on the projects classpath also has a Class-Path element +specified in the manifest,the content of the Class-Path element has to be on +the projects runtime path. +* To set a main class in a standard Java project, right-click the project node +in the Projects window and choose Properties. Then click Run and enter the +class name in the Main Class field. Alternatively, you can manually type the +class name in the manifest Main-Class element. diff --git a/Pro Java 7 NIO.2/Chapter06/watch/watch_03/dist/watch_03.jar b/Pro Java 7 NIO.2/Chapter06/watch/watch_03/dist/watch_03.jar new file mode 100644 index 0000000..d92feaf Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter06/watch/watch_03/dist/watch_03.jar differ diff --git a/Pro Java 7 NIO.2/Chapter06/watch/watch_03/manifest.mf b/Pro Java 7 NIO.2/Chapter06/watch/watch_03/manifest.mf new file mode 100644 index 0000000..328e8e5 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter06/watch/watch_03/manifest.mf @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +X-COMMENT: Main-Class will be added automatically by build + diff --git a/Pro Java 7 NIO.2/Chapter06/watch/watch_03/nbproject/build-impl.xml b/Pro Java 7 NIO.2/Chapter06/watch/watch_03/nbproject/build-impl.xml new file mode 100644 index 0000000..61f4cd0 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter06/watch/watch_03/nbproject/build-impl.xml @@ -0,0 +1,1041 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set src.dir + Must set test.src.dir + Must set build.dir + Must set dist.dir + Must set build.classes.dir + Must set dist.javadoc.dir + Must set build.test.classes.dir + Must set build.test.results.dir + Must set build.classes.excludes + Must set dist.jar + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set JVM to use for profiling in profiler.info.jvm + Must set profiler agent JVM arguments in profiler.info.jvmargs.agent + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + + + + + + java -cp "${run.classpath.with.dist.jar}" ${main.class} + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + java -jar "${dist.jar.resolved}" + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set run.class + + + + Must select one file in the IDE or set run.class + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set debug.class + + + + + Must select one file in the IDE or set debug.class + + + + + Must set fix.includes + + + + + + + + + + + + + + + + + Must select one file in the IDE or set profile.class + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + Some tests failed; see details above. + + + + + + + + + Must select some files in the IDE or set test.includes + + + + Some tests failed; see details above. + + + + + Must select one file in the IDE or set test.class + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Pro Java 7 NIO.2/Chapter06/watch/watch_03/nbproject/genfiles.properties b/Pro Java 7 NIO.2/Chapter06/watch/watch_03/nbproject/genfiles.properties new file mode 100644 index 0000000..2fb0b8a --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter06/watch/watch_03/nbproject/genfiles.properties @@ -0,0 +1,8 @@ +build.xml.data.CRC32=15739412 +build.xml.script.CRC32=e762860c +build.xml.stylesheet.CRC32=28e38971@1.43.1.45 +# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. +# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. +nbproject/build-impl.xml.data.CRC32=15739412 +nbproject/build-impl.xml.script.CRC32=27b2544a +nbproject/build-impl.xml.stylesheet.CRC32=0c01fd8e@1.43.1.45 diff --git a/Pro Java 7 NIO.2/Chapter06/watch/watch_03/nbproject/private/config.properties b/Pro Java 7 NIO.2/Chapter06/watch/watch_03/nbproject/private/config.properties new file mode 100644 index 0000000..e69de29 diff --git a/Pro Java 7 NIO.2/Chapter06/watch/watch_03/nbproject/private/private.properties b/Pro Java 7 NIO.2/Chapter06/watch/watch_03/nbproject/private/private.properties new file mode 100644 index 0000000..a5ab360 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter06/watch/watch_03/nbproject/private/private.properties @@ -0,0 +1,6 @@ +compile.on.save=true +do.depend=false +do.jar=true +javac.debug=true +javadoc.preview=true +user.properties.file=C:\\Users\\Leo\\.netbeans\\7.0\\build.properties diff --git a/Pro Java 7 NIO.2/Chapter06/watch/watch_03/nbproject/private/private.xml b/Pro Java 7 NIO.2/Chapter06/watch/watch_03/nbproject/private/private.xml new file mode 100644 index 0000000..c1f155a --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter06/watch/watch_03/nbproject/private/private.xml @@ -0,0 +1,4 @@ + + + + diff --git a/Pro Java 7 NIO.2/Chapter06/watch/watch_03/nbproject/project.properties b/Pro Java 7 NIO.2/Chapter06/watch/watch_03/nbproject/project.properties new file mode 100644 index 0000000..141ce69 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter06/watch/watch_03/nbproject/project.properties @@ -0,0 +1,72 @@ +annotation.processing.enabled=true +annotation.processing.enabled.in.editor=false +annotation.processing.run.all.processors=true +annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output +application.title=watch_03 +application.vendor=Leo +build.classes.dir=${build.dir}/classes +build.classes.excludes=**/*.java,**/*.form +# This directory is removed when the project is cleaned: +build.dir=build +build.generated.dir=${build.dir}/generated +build.generated.sources.dir=${build.dir}/generated-sources +# Only compile against the classpath explicitly listed here: +build.sysclasspath=ignore +build.test.classes.dir=${build.dir}/test/classes +build.test.results.dir=${build.dir}/test/results +# Uncomment to specify the preferred debugger connection transport: +#debug.transport=dt_socket +debug.classpath=\ + ${run.classpath} +debug.test.classpath=\ + ${run.test.classpath} +# This directory is removed when the project is cleaned: +dist.dir=dist +dist.jar=${dist.dir}/watch_03.jar +dist.javadoc.dir=${dist.dir}/javadoc +endorsed.classpath= +excludes= +includes=** +jar.compress=false +javac.classpath= +# Space-separated list of extra javac options +javac.compilerargs= +javac.deprecation=false +javac.processorpath=\ + ${javac.classpath} +javac.source=1.7 +javac.target=1.7 +javac.test.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +javac.test.processorpath=\ + ${javac.test.classpath} +javadoc.additionalparam= +javadoc.author=false +javadoc.encoding=${source.encoding} +javadoc.noindex=false +javadoc.nonavbar=false +javadoc.notree=false +javadoc.private=false +javadoc.splitindex=true +javadoc.use=true +javadoc.version=false +javadoc.windowtitle= +main.class=watch_03.Main +manifest.file=manifest.mf +meta.inf.dir=${src.dir}/META-INF +mkdist.disabled=false +platform.active=default_platform +run.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +# Space-separated list of JVM arguments used when running the project +# (you may also define separate properties like run-sys-prop.name=value instead of -Dname=value +# or test-sys-prop.name=value to set system properties for unit tests): +run.jvmargs= +run.test.classpath=\ + ${javac.test.classpath}:\ + ${build.test.classes.dir} +source.encoding=UTF-8 +src.dir=src +test.src.dir=test diff --git a/Pro Java 7 NIO.2/Chapter06/watch/watch_03/nbproject/project.xml b/Pro Java 7 NIO.2/Chapter06/watch/watch_03/nbproject/project.xml new file mode 100644 index 0000000..f920a6c --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter06/watch/watch_03/nbproject/project.xml @@ -0,0 +1,15 @@ + + + org.netbeans.modules.java.j2seproject + + + watch_03 + + + + + + + + + diff --git a/Pro Java 7 NIO.2/Chapter06/watch/watch_03/src/watch_03/Main.java b/Pro Java 7 NIO.2/Chapter06/watch/watch_03/src/watch_03/Main.java new file mode 100644 index 0000000..ec21ffb --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter06/watch/watch_03/src/watch_03/Main.java @@ -0,0 +1,132 @@ +package watch_03; + +import java.io.IOException; +import java.nio.file.FileSystems; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.nio.file.StandardWatchEventKinds; +import java.nio.file.WatchEvent; +import java.nio.file.WatchEvent.Kind; +import java.nio.file.WatchKey; +import java.nio.file.WatchService; +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; +import java.util.Random; +import java.util.concurrent.TimeUnit; + +/** + * + * @author Apress + */ +class Print implements Runnable { + + private Path doc; + + Print(Path doc) { + this.doc = doc; + } + + @Override + public void run() { + try { + //sleep a random number of seconds for simulating dispaching and printing + Thread.sleep(20000 + new Random().nextInt(30000)); + System.out.println("Printing: " + doc); + } catch (InterruptedException ex) { + System.err.println(ex); + } + } +} + +class WatchPrinterTray { + + private final Map threads = new HashMap<>(); + + public void watchTray(Path path) throws IOException, InterruptedException { + try (WatchService watchService = FileSystems.getDefault().newWatchService()) { + path.register(watchService, StandardWatchEventKinds.ENTRY_CREATE, StandardWatchEventKinds.ENTRY_DELETE); + + //start an infinite loop + while (true) { + + //retrieve and remove the next watch key + final WatchKey key = watchService.poll(10, TimeUnit.SECONDS); + + //get list of events for the watch key + if (key != null) { + for (WatchEvent watchEvent : key.pollEvents()) { + + //get the filename for the event + final WatchEvent watchEventPath = (WatchEvent) watchEvent; + final Path filename = watchEventPath.context(); + + //get the kind of event (create, modify, delete) + final Kind kind = watchEvent.kind(); + + //handle OVERFLOW event + if (kind == StandardWatchEventKinds.OVERFLOW) { + continue; + } + + if (kind == StandardWatchEventKinds.ENTRY_CREATE) { + System.out.println("Sending the document to print -> " + filename); + + Runnable task = new Print(path.resolve(filename)); + Thread worker = new Thread(task); + + //we can set the name of the thread + worker.setName(path.resolve(filename).toString()); + + //store the thread and the path + threads.put(worker, path.resolve(filename)); + + //start the thread, never call method run() direct + worker.start(); + } + + if (kind == StandardWatchEventKinds.ENTRY_DELETE) { + System.out.println(filename + " was successfully printed!"); + } + } + + //reset the key + boolean valid = key.reset(); + + //exit loop if the key is not valid (if the directory was deleted, per example) + if (!valid) { + threads.clear(); + break; + } + } + + if (!threads.isEmpty()) { + for (Iterator> it = threads.entrySet().iterator(); it.hasNext();) { + Map.Entry entry = it.next(); + if (entry.getKey().getState() == Thread.State.TERMINATED) { + Files.deleteIfExists(entry.getValue()); + it.remove(); + } + } + } + } + } + } +} + +public class Main { + + public static void main(String[] args) { + + final Path path = Paths.get("C:/printertray"); + WatchPrinterTray watch = new WatchPrinterTray(); + + try { + watch.watchTray(path); + } catch (IOException | InterruptedException ex) { + System.err.println(ex); + } + + } +} diff --git a/Pro Java 7 NIO.2/Chapter06/watch/watch_04/build.xml b/Pro Java 7 NIO.2/Chapter06/watch/watch_04/build.xml new file mode 100644 index 0000000..adde750 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter06/watch/watch_04/build.xml @@ -0,0 +1,74 @@ + + + + + + + + + + + Builds, tests, and runs the project watch_04. + + + diff --git a/Pro Java 7 NIO.2/Chapter06/watch/watch_04/build/built-jar.properties b/Pro Java 7 NIO.2/Chapter06/watch/watch_04/build/built-jar.properties new file mode 100644 index 0000000..0818aa2 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter06/watch/watch_04/build/built-jar.properties @@ -0,0 +1,4 @@ +#Mon, 17 Oct 2011 11:18:15 +0200 + + +C\:\\NIO\\watch\\watch_04= diff --git a/Pro Java 7 NIO.2/Chapter06/watch/watch_04/build/classes/watch_04/Main.class b/Pro Java 7 NIO.2/Chapter06/watch/watch_04/build/classes/watch_04/Main.class new file mode 100644 index 0000000..9e0d67d Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter06/watch/watch_04/build/classes/watch_04/Main.class differ diff --git a/Pro Java 7 NIO.2/Chapter06/watch/watch_04/build/classes/watch_04/WatchRecursiveRafaelNadal$1.class b/Pro Java 7 NIO.2/Chapter06/watch/watch_04/build/classes/watch_04/WatchRecursiveRafaelNadal$1.class new file mode 100644 index 0000000..12934fc Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter06/watch/watch_04/build/classes/watch_04/WatchRecursiveRafaelNadal$1.class differ diff --git a/Pro Java 7 NIO.2/Chapter06/watch/watch_04/build/classes/watch_04/WatchRecursiveRafaelNadal.class b/Pro Java 7 NIO.2/Chapter06/watch/watch_04/build/classes/watch_04/WatchRecursiveRafaelNadal.class new file mode 100644 index 0000000..c06f6b7 Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter06/watch/watch_04/build/classes/watch_04/WatchRecursiveRafaelNadal.class differ diff --git a/Pro Java 7 NIO.2/Chapter06/watch/watch_04/dist/README.TXT b/Pro Java 7 NIO.2/Chapter06/watch/watch_04/dist/README.TXT new file mode 100644 index 0000000..f3b3dad --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter06/watch/watch_04/dist/README.TXT @@ -0,0 +1,32 @@ +======================== +BUILD OUTPUT DESCRIPTION +======================== + +When you build an Java application project that has a main class, the IDE +automatically copies all of the JAR +files on the projects classpath to your projects dist/lib folder. The IDE +also adds each of the JAR files to the Class-Path element in the application +JAR files manifest file (MANIFEST.MF). + +To run the project from the command line, go to the dist folder and +type the following: + +java -jar "watch_04.jar" + +To distribute this project, zip up the dist folder (including the lib folder) +and distribute the ZIP file. + +Notes: + +* If two JAR files on the project classpath have the same name, only the first +JAR file is copied to the lib folder. +* Only JAR files are copied to the lib folder. +If the classpath contains other types of files or folders, these files (folders) +are not copied. +* If a library on the projects classpath also has a Class-Path element +specified in the manifest,the content of the Class-Path element has to be on +the projects runtime path. +* To set a main class in a standard Java project, right-click the project node +in the Projects window and choose Properties. Then click Run and enter the +class name in the Main Class field. Alternatively, you can manually type the +class name in the manifest Main-Class element. diff --git a/Pro Java 7 NIO.2/Chapter06/watch/watch_04/dist/watch_04.jar b/Pro Java 7 NIO.2/Chapter06/watch/watch_04/dist/watch_04.jar new file mode 100644 index 0000000..4991177 Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter06/watch/watch_04/dist/watch_04.jar differ diff --git a/Pro Java 7 NIO.2/Chapter06/watch/watch_04/manifest.mf b/Pro Java 7 NIO.2/Chapter06/watch/watch_04/manifest.mf new file mode 100644 index 0000000..328e8e5 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter06/watch/watch_04/manifest.mf @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +X-COMMENT: Main-Class will be added automatically by build + diff --git a/Pro Java 7 NIO.2/Chapter06/watch/watch_04/nbproject/build-impl.xml b/Pro Java 7 NIO.2/Chapter06/watch/watch_04/nbproject/build-impl.xml new file mode 100644 index 0000000..a800580 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter06/watch/watch_04/nbproject/build-impl.xml @@ -0,0 +1,1041 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set src.dir + Must set test.src.dir + Must set build.dir + Must set dist.dir + Must set build.classes.dir + Must set dist.javadoc.dir + Must set build.test.classes.dir + Must set build.test.results.dir + Must set build.classes.excludes + Must set dist.jar + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set JVM to use for profiling in profiler.info.jvm + Must set profiler agent JVM arguments in profiler.info.jvmargs.agent + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + + + + + + java -cp "${run.classpath.with.dist.jar}" ${main.class} + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + java -jar "${dist.jar.resolved}" + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set run.class + + + + Must select one file in the IDE or set run.class + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set debug.class + + + + + Must select one file in the IDE or set debug.class + + + + + Must set fix.includes + + + + + + + + + + + + + + + + + Must select one file in the IDE or set profile.class + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + Some tests failed; see details above. + + + + + + + + + Must select some files in the IDE or set test.includes + + + + Some tests failed; see details above. + + + + + Must select one file in the IDE or set test.class + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Pro Java 7 NIO.2/Chapter06/watch/watch_04/nbproject/genfiles.properties b/Pro Java 7 NIO.2/Chapter06/watch/watch_04/nbproject/genfiles.properties new file mode 100644 index 0000000..cf01f62 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter06/watch/watch_04/nbproject/genfiles.properties @@ -0,0 +1,8 @@ +build.xml.data.CRC32=2d0930e0 +build.xml.script.CRC32=9afce044 +build.xml.stylesheet.CRC32=28e38971@1.43.1.45 +# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. +# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. +nbproject/build-impl.xml.data.CRC32=2d0930e0 +nbproject/build-impl.xml.script.CRC32=b6162a23 +nbproject/build-impl.xml.stylesheet.CRC32=0c01fd8e@1.43.1.45 diff --git a/Pro Java 7 NIO.2/Chapter06/watch/watch_04/nbproject/private/config.properties b/Pro Java 7 NIO.2/Chapter06/watch/watch_04/nbproject/private/config.properties new file mode 100644 index 0000000..e69de29 diff --git a/Pro Java 7 NIO.2/Chapter06/watch/watch_04/nbproject/private/private.properties b/Pro Java 7 NIO.2/Chapter06/watch/watch_04/nbproject/private/private.properties new file mode 100644 index 0000000..a5ab360 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter06/watch/watch_04/nbproject/private/private.properties @@ -0,0 +1,6 @@ +compile.on.save=true +do.depend=false +do.jar=true +javac.debug=true +javadoc.preview=true +user.properties.file=C:\\Users\\Leo\\.netbeans\\7.0\\build.properties diff --git a/Pro Java 7 NIO.2/Chapter06/watch/watch_04/nbproject/private/private.xml b/Pro Java 7 NIO.2/Chapter06/watch/watch_04/nbproject/private/private.xml new file mode 100644 index 0000000..c1f155a --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter06/watch/watch_04/nbproject/private/private.xml @@ -0,0 +1,4 @@ + + + + diff --git a/Pro Java 7 NIO.2/Chapter06/watch/watch_04/nbproject/project.properties b/Pro Java 7 NIO.2/Chapter06/watch/watch_04/nbproject/project.properties new file mode 100644 index 0000000..1875cad --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter06/watch/watch_04/nbproject/project.properties @@ -0,0 +1,72 @@ +annotation.processing.enabled=true +annotation.processing.enabled.in.editor=false +annotation.processing.run.all.processors=true +annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output +application.title=watch_04 +application.vendor=Leo +build.classes.dir=${build.dir}/classes +build.classes.excludes=**/*.java,**/*.form +# This directory is removed when the project is cleaned: +build.dir=build +build.generated.dir=${build.dir}/generated +build.generated.sources.dir=${build.dir}/generated-sources +# Only compile against the classpath explicitly listed here: +build.sysclasspath=ignore +build.test.classes.dir=${build.dir}/test/classes +build.test.results.dir=${build.dir}/test/results +# Uncomment to specify the preferred debugger connection transport: +#debug.transport=dt_socket +debug.classpath=\ + ${run.classpath} +debug.test.classpath=\ + ${run.test.classpath} +# This directory is removed when the project is cleaned: +dist.dir=dist +dist.jar=${dist.dir}/watch_04.jar +dist.javadoc.dir=${dist.dir}/javadoc +endorsed.classpath= +excludes= +includes=** +jar.compress=false +javac.classpath= +# Space-separated list of extra javac options +javac.compilerargs= +javac.deprecation=false +javac.processorpath=\ + ${javac.classpath} +javac.source=1.7 +javac.target=1.7 +javac.test.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +javac.test.processorpath=\ + ${javac.test.classpath} +javadoc.additionalparam= +javadoc.author=false +javadoc.encoding=${source.encoding} +javadoc.noindex=false +javadoc.nonavbar=false +javadoc.notree=false +javadoc.private=false +javadoc.splitindex=true +javadoc.use=true +javadoc.version=false +javadoc.windowtitle= +main.class=watch_04.Main +manifest.file=manifest.mf +meta.inf.dir=${src.dir}/META-INF +mkdist.disabled=false +platform.active=default_platform +run.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +# Space-separated list of JVM arguments used when running the project +# (you may also define separate properties like run-sys-prop.name=value instead of -Dname=value +# or test-sys-prop.name=value to set system properties for unit tests): +run.jvmargs= +run.test.classpath=\ + ${javac.test.classpath}:\ + ${build.test.classes.dir} +source.encoding=UTF-8 +src.dir=src +test.src.dir=test diff --git a/Pro Java 7 NIO.2/Chapter06/watch/watch_04/nbproject/project.xml b/Pro Java 7 NIO.2/Chapter06/watch/watch_04/nbproject/project.xml new file mode 100644 index 0000000..9dc331c --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter06/watch/watch_04/nbproject/project.xml @@ -0,0 +1,15 @@ + + + org.netbeans.modules.java.j2seproject + + + watch_04 + + + + + + + + + diff --git a/Pro Java 7 NIO.2/Chapter06/watch/watch_04/src/watch_04/Main.java b/Pro Java 7 NIO.2/Chapter06/watch/watch_04/src/watch_04/Main.java new file mode 100644 index 0000000..617f66b --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter06/watch/watch_04/src/watch_04/Main.java @@ -0,0 +1,124 @@ +package watch_04; + +import java.io.IOException; +import java.nio.file.FileSystems; +import java.nio.file.FileVisitResult; +import java.nio.file.Files; +import java.nio.file.LinkOption; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.nio.file.SimpleFileVisitor; +import java.nio.file.StandardWatchEventKinds; +import java.nio.file.WatchEvent; +import java.nio.file.WatchEvent.Kind; +import java.nio.file.WatchKey; +import java.nio.file.WatchService; +import java.nio.file.attribute.BasicFileAttributes; +import java.util.HashMap; +import java.util.Map; + +/** + * + * @author Apress + */ +class WatchRecursiveRafaelNadal { + + private WatchService watchService; + private final Map directories = new HashMap<>(); + + private void registerPath(Path path) throws IOException { + //register the received path + WatchKey key = path.register(watchService, StandardWatchEventKinds.ENTRY_CREATE, StandardWatchEventKinds.ENTRY_MODIFY, StandardWatchEventKinds.ENTRY_DELETE); + + //store the key and path + directories.put(key, path); + } + + private void registerTree(Path start) throws IOException { + + Files.walkFileTree(start, new SimpleFileVisitor() { + + @Override + public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) + throws IOException { + System.out.println("Registering:" + dir); + registerPath(dir); + return FileVisitResult.CONTINUE; + } + }); + + } + + public void watchRNDir(Path start) throws IOException, InterruptedException { + + watchService = FileSystems.getDefault().newWatchService(); + + registerTree(start); + + //start an infinite loop + while (true) { + + //retrieve and remove the next watch key + final WatchKey key = watchService.take(); + + //get list of events for the watch key + for (WatchEvent watchEvent : key.pollEvents()) { + + //get the kind of event (create, modify, delete) + final Kind kind = watchEvent.kind(); + + //get the filename for the event + final WatchEvent watchEventPath = (WatchEvent) watchEvent; + final Path filename = watchEventPath.context(); + + //handle OVERFLOW event + if (kind == StandardWatchEventKinds.OVERFLOW) { + continue; + } + + //handle CREATE event + if (kind == StandardWatchEventKinds.ENTRY_CREATE) { + final Path directory_path = directories.get(key); + final Path child = directory_path.resolve(filename); + + if (Files.isDirectory(child, LinkOption.NOFOLLOW_LINKS)) { + registerTree(child); + } + } + + //print it out + System.out.println(kind + " -> " + filename); + } + + //reset the key + boolean valid = key.reset(); + + //remove the key if it is not valid + if (!valid) { + directories.remove(key); + + //there are no more keys registered + if (directories.isEmpty()) { + break; + } + } + } + watchService.close(); + } +} + +public class Main { + + public static void main(String[] args) { + + final Path path = Paths.get("C:/rafaelnadal"); + WatchRecursiveRafaelNadal watch = new WatchRecursiveRafaelNadal(); + + try { + watch.watchRNDir(path); + } catch (IOException | InterruptedException ex) { + System.err.println(ex); + } + + } +} diff --git a/Pro Java 7 NIO.2/Chapter07/channels/chl_01/build.xml b/Pro Java 7 NIO.2/Chapter07/channels/chl_01/build.xml new file mode 100644 index 0000000..6c6cf9d --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter07/channels/chl_01/build.xml @@ -0,0 +1,74 @@ + + + + + + + + + + + Builds, tests, and runs the project chl_01. + + + diff --git a/Pro Java 7 NIO.2/Chapter07/channels/chl_01/build/built-jar.properties b/Pro Java 7 NIO.2/Chapter07/channels/chl_01/build/built-jar.properties new file mode 100644 index 0000000..f6fb864 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter07/channels/chl_01/build/built-jar.properties @@ -0,0 +1,4 @@ +#Wed, 26 Oct 2011 08:48:08 +0200 + + +C\:\\NIO\\channels\\chl_01= diff --git a/Pro Java 7 NIO.2/Chapter07/channels/chl_01/build/classes/chl_01/Main.class b/Pro Java 7 NIO.2/Chapter07/channels/chl_01/build/classes/chl_01/Main.class new file mode 100644 index 0000000..ee8c959 Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter07/channels/chl_01/build/classes/chl_01/Main.class differ diff --git a/Pro Java 7 NIO.2/Chapter07/channels/chl_01/dist/README.TXT b/Pro Java 7 NIO.2/Chapter07/channels/chl_01/dist/README.TXT new file mode 100644 index 0000000..f388a81 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter07/channels/chl_01/dist/README.TXT @@ -0,0 +1,32 @@ +======================== +BUILD OUTPUT DESCRIPTION +======================== + +When you build an Java application project that has a main class, the IDE +automatically copies all of the JAR +files on the projects classpath to your projects dist/lib folder. The IDE +also adds each of the JAR files to the Class-Path element in the application +JAR files manifest file (MANIFEST.MF). + +To run the project from the command line, go to the dist folder and +type the following: + +java -jar "chl_01.jar" + +To distribute this project, zip up the dist folder (including the lib folder) +and distribute the ZIP file. + +Notes: + +* If two JAR files on the project classpath have the same name, only the first +JAR file is copied to the lib folder. +* Only JAR files are copied to the lib folder. +If the classpath contains other types of files or folders, these files (folders) +are not copied. +* If a library on the projects classpath also has a Class-Path element +specified in the manifest,the content of the Class-Path element has to be on +the projects runtime path. +* To set a main class in a standard Java project, right-click the project node +in the Projects window and choose Properties. Then click Run and enter the +class name in the Main Class field. Alternatively, you can manually type the +class name in the manifest Main-Class element. diff --git a/Pro Java 7 NIO.2/Chapter07/channels/chl_01/dist/chl_01.jar b/Pro Java 7 NIO.2/Chapter07/channels/chl_01/dist/chl_01.jar new file mode 100644 index 0000000..c2344b0 Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter07/channels/chl_01/dist/chl_01.jar differ diff --git a/Pro Java 7 NIO.2/Chapter07/channels/chl_01/manifest.mf b/Pro Java 7 NIO.2/Chapter07/channels/chl_01/manifest.mf new file mode 100644 index 0000000..328e8e5 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter07/channels/chl_01/manifest.mf @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +X-COMMENT: Main-Class will be added automatically by build + diff --git a/Pro Java 7 NIO.2/Chapter07/channels/chl_01/nbproject/build-impl.xml b/Pro Java 7 NIO.2/Chapter07/channels/chl_01/nbproject/build-impl.xml new file mode 100644 index 0000000..9f3e44b --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter07/channels/chl_01/nbproject/build-impl.xml @@ -0,0 +1,1041 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set src.dir + Must set test.src.dir + Must set build.dir + Must set dist.dir + Must set build.classes.dir + Must set dist.javadoc.dir + Must set build.test.classes.dir + Must set build.test.results.dir + Must set build.classes.excludes + Must set dist.jar + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set JVM to use for profiling in profiler.info.jvm + Must set profiler agent JVM arguments in profiler.info.jvmargs.agent + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + + + + + + java -cp "${run.classpath.with.dist.jar}" ${main.class} + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + java -jar "${dist.jar.resolved}" + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set run.class + + + + Must select one file in the IDE or set run.class + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set debug.class + + + + + Must select one file in the IDE or set debug.class + + + + + Must set fix.includes + + + + + + + + + + + + + + + + + Must select one file in the IDE or set profile.class + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + Some tests failed; see details above. + + + + + + + + + Must select some files in the IDE or set test.includes + + + + Some tests failed; see details above. + + + + + Must select one file in the IDE or set test.class + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Pro Java 7 NIO.2/Chapter07/channels/chl_01/nbproject/genfiles.properties b/Pro Java 7 NIO.2/Chapter07/channels/chl_01/nbproject/genfiles.properties new file mode 100644 index 0000000..a6f4b24 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter07/channels/chl_01/nbproject/genfiles.properties @@ -0,0 +1,8 @@ +build.xml.data.CRC32=6768e06e +build.xml.script.CRC32=848ae160 +build.xml.stylesheet.CRC32=28e38971@1.43.1.45 +# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. +# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. +nbproject/build-impl.xml.data.CRC32=6768e06e +nbproject/build-impl.xml.script.CRC32=aa1b46c9 +nbproject/build-impl.xml.stylesheet.CRC32=0c01fd8e@1.43.1.45 diff --git a/Pro Java 7 NIO.2/Chapter07/channels/chl_01/nbproject/private/config.properties b/Pro Java 7 NIO.2/Chapter07/channels/chl_01/nbproject/private/config.properties new file mode 100644 index 0000000..e69de29 diff --git a/Pro Java 7 NIO.2/Chapter07/channels/chl_01/nbproject/private/private.properties b/Pro Java 7 NIO.2/Chapter07/channels/chl_01/nbproject/private/private.properties new file mode 100644 index 0000000..a5ab360 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter07/channels/chl_01/nbproject/private/private.properties @@ -0,0 +1,6 @@ +compile.on.save=true +do.depend=false +do.jar=true +javac.debug=true +javadoc.preview=true +user.properties.file=C:\\Users\\Leo\\.netbeans\\7.0\\build.properties diff --git a/Pro Java 7 NIO.2/Chapter07/channels/chl_01/nbproject/private/private.xml b/Pro Java 7 NIO.2/Chapter07/channels/chl_01/nbproject/private/private.xml new file mode 100644 index 0000000..c1f155a --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter07/channels/chl_01/nbproject/private/private.xml @@ -0,0 +1,4 @@ + + + + diff --git a/Pro Java 7 NIO.2/Chapter07/channels/chl_01/nbproject/project.properties b/Pro Java 7 NIO.2/Chapter07/channels/chl_01/nbproject/project.properties new file mode 100644 index 0000000..f0ed9fc --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter07/channels/chl_01/nbproject/project.properties @@ -0,0 +1,72 @@ +annotation.processing.enabled=true +annotation.processing.enabled.in.editor=false +annotation.processing.run.all.processors=true +annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output +application.title=chl_01 +application.vendor=Leo +build.classes.dir=${build.dir}/classes +build.classes.excludes=**/*.java,**/*.form +# This directory is removed when the project is cleaned: +build.dir=build +build.generated.dir=${build.dir}/generated +build.generated.sources.dir=${build.dir}/generated-sources +# Only compile against the classpath explicitly listed here: +build.sysclasspath=ignore +build.test.classes.dir=${build.dir}/test/classes +build.test.results.dir=${build.dir}/test/results +# Uncomment to specify the preferred debugger connection transport: +#debug.transport=dt_socket +debug.classpath=\ + ${run.classpath} +debug.test.classpath=\ + ${run.test.classpath} +# This directory is removed when the project is cleaned: +dist.dir=dist +dist.jar=${dist.dir}/chl_01.jar +dist.javadoc.dir=${dist.dir}/javadoc +endorsed.classpath= +excludes= +includes=** +jar.compress=false +javac.classpath= +# Space-separated list of extra javac options +javac.compilerargs= +javac.deprecation=false +javac.processorpath=\ + ${javac.classpath} +javac.source=1.7 +javac.target=1.7 +javac.test.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +javac.test.processorpath=\ + ${javac.test.classpath} +javadoc.additionalparam= +javadoc.author=false +javadoc.encoding=${source.encoding} +javadoc.noindex=false +javadoc.nonavbar=false +javadoc.notree=false +javadoc.private=false +javadoc.splitindex=true +javadoc.use=true +javadoc.version=false +javadoc.windowtitle= +main.class=chl_01.Main +manifest.file=manifest.mf +meta.inf.dir=${src.dir}/META-INF +mkdist.disabled=false +platform.active=default_platform +run.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +# Space-separated list of JVM arguments used when running the project +# (you may also define separate properties like run-sys-prop.name=value instead of -Dname=value +# or test-sys-prop.name=value to set system properties for unit tests): +run.jvmargs= +run.test.classpath=\ + ${javac.test.classpath}:\ + ${build.test.classes.dir} +source.encoding=UTF-8 +src.dir=src +test.src.dir=test diff --git a/Pro Java 7 NIO.2/Chapter07/channels/chl_01/nbproject/project.xml b/Pro Java 7 NIO.2/Chapter07/channels/chl_01/nbproject/project.xml new file mode 100644 index 0000000..27c2ba1 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter07/channels/chl_01/nbproject/project.xml @@ -0,0 +1,15 @@ + + + org.netbeans.modules.java.j2seproject + + + chl_01 + + + + + + + + + diff --git a/Pro Java 7 NIO.2/Chapter07/channels/chl_01/src/chl_01/Main.java b/Pro Java 7 NIO.2/Chapter07/channels/chl_01/src/chl_01/Main.java new file mode 100644 index 0000000..89cfd6a --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter07/channels/chl_01/src/chl_01/Main.java @@ -0,0 +1,61 @@ +package chl_01; + +import java.io.IOException; +import java.nio.ByteBuffer; +import java.nio.channels.ReadableByteChannel; +import java.nio.channels.SeekableByteChannel; +import java.nio.charset.Charset; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.nio.file.StandardOpenOption; +import java.util.EnumSet; + +/** + * + * @author Apress + */ +public class Main { + + public static void main(String[] args) { + + Path path = Paths.get("C:/rafaelnadal/grandslam/RolandGarros", "story.txt"); + + //read a file using ReadableByteChannel + try (ReadableByteChannel readableByteChannel = Files.newByteChannel(path)) { + + ByteBuffer buffer = ByteBuffer.allocate(12); + buffer.clear(); + + String encoding = System.getProperty("file.encoding"); + + while (readableByteChannel.read(buffer) > 0) { + buffer.flip(); + System.out.print(Charset.forName(encoding).decode(buffer)); + buffer.clear(); + } + + } catch (IOException ex) { + System.err.println(ex); + } + + System.out.println("\n"); + //read a file using SeekableByteChannel + try (SeekableByteChannel seekableByteChannel = Files.newByteChannel(path, EnumSet.of(StandardOpenOption.READ))) { + + ByteBuffer buffer = ByteBuffer.allocate(12); + String encoding = System.getProperty("file.encoding"); + buffer.clear(); + + while (seekableByteChannel.read(buffer) > 0) { + buffer.flip(); + System.out.print(Charset.forName(encoding).decode(buffer)); + buffer.clear(); + } + + } catch (IOException ex) { + System.err.println(ex); + } + + } +} diff --git a/Pro Java 7 NIO.2/Chapter07/channels/chl_02/build.xml b/Pro Java 7 NIO.2/Chapter07/channels/chl_02/build.xml new file mode 100644 index 0000000..627cac1 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter07/channels/chl_02/build.xml @@ -0,0 +1,74 @@ + + + + + + + + + + + Builds, tests, and runs the project chl_02. + + + diff --git a/Pro Java 7 NIO.2/Chapter07/channels/chl_02/build/built-jar.properties b/Pro Java 7 NIO.2/Chapter07/channels/chl_02/build/built-jar.properties new file mode 100644 index 0000000..ab79e6e --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter07/channels/chl_02/build/built-jar.properties @@ -0,0 +1,4 @@ +#Wed, 26 Oct 2011 08:51:50 +0200 + + +C\:\\NIO\\channels\\chl_02= diff --git a/Pro Java 7 NIO.2/Chapter07/channels/chl_02/build/classes/chl_02/Main.class b/Pro Java 7 NIO.2/Chapter07/channels/chl_02/build/classes/chl_02/Main.class new file mode 100644 index 0000000..b0ca6a0 Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter07/channels/chl_02/build/classes/chl_02/Main.class differ diff --git a/Pro Java 7 NIO.2/Chapter07/channels/chl_02/dist/README.TXT b/Pro Java 7 NIO.2/Chapter07/channels/chl_02/dist/README.TXT new file mode 100644 index 0000000..e435dfb --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter07/channels/chl_02/dist/README.TXT @@ -0,0 +1,32 @@ +======================== +BUILD OUTPUT DESCRIPTION +======================== + +When you build an Java application project that has a main class, the IDE +automatically copies all of the JAR +files on the projects classpath to your projects dist/lib folder. The IDE +also adds each of the JAR files to the Class-Path element in the application +JAR files manifest file (MANIFEST.MF). + +To run the project from the command line, go to the dist folder and +type the following: + +java -jar "chl_02.jar" + +To distribute this project, zip up the dist folder (including the lib folder) +and distribute the ZIP file. + +Notes: + +* If two JAR files on the project classpath have the same name, only the first +JAR file is copied to the lib folder. +* Only JAR files are copied to the lib folder. +If the classpath contains other types of files or folders, these files (folders) +are not copied. +* If a library on the projects classpath also has a Class-Path element +specified in the manifest,the content of the Class-Path element has to be on +the projects runtime path. +* To set a main class in a standard Java project, right-click the project node +in the Projects window and choose Properties. Then click Run and enter the +class name in the Main Class field. Alternatively, you can manually type the +class name in the manifest Main-Class element. diff --git a/Pro Java 7 NIO.2/Chapter07/channels/chl_02/dist/chl_02.jar b/Pro Java 7 NIO.2/Chapter07/channels/chl_02/dist/chl_02.jar new file mode 100644 index 0000000..4911d88 Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter07/channels/chl_02/dist/chl_02.jar differ diff --git a/Pro Java 7 NIO.2/Chapter07/channels/chl_02/manifest.mf b/Pro Java 7 NIO.2/Chapter07/channels/chl_02/manifest.mf new file mode 100644 index 0000000..328e8e5 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter07/channels/chl_02/manifest.mf @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +X-COMMENT: Main-Class will be added automatically by build + diff --git a/Pro Java 7 NIO.2/Chapter07/channels/chl_02/nbproject/build-impl.xml b/Pro Java 7 NIO.2/Chapter07/channels/chl_02/nbproject/build-impl.xml new file mode 100644 index 0000000..779262b --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter07/channels/chl_02/nbproject/build-impl.xml @@ -0,0 +1,1041 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set src.dir + Must set test.src.dir + Must set build.dir + Must set dist.dir + Must set build.classes.dir + Must set dist.javadoc.dir + Must set build.test.classes.dir + Must set build.test.results.dir + Must set build.classes.excludes + Must set dist.jar + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set JVM to use for profiling in profiler.info.jvm + Must set profiler agent JVM arguments in profiler.info.jvmargs.agent + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + + + + + + java -cp "${run.classpath.with.dist.jar}" ${main.class} + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + java -jar "${dist.jar.resolved}" + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set run.class + + + + Must select one file in the IDE or set run.class + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set debug.class + + + + + Must select one file in the IDE or set debug.class + + + + + Must set fix.includes + + + + + + + + + + + + + + + + + Must select one file in the IDE or set profile.class + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + Some tests failed; see details above. + + + + + + + + + Must select some files in the IDE or set test.includes + + + + Some tests failed; see details above. + + + + + Must select one file in the IDE or set test.class + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Pro Java 7 NIO.2/Chapter07/channels/chl_02/nbproject/genfiles.properties b/Pro Java 7 NIO.2/Chapter07/channels/chl_02/nbproject/genfiles.properties new file mode 100644 index 0000000..c74d0d8 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter07/channels/chl_02/nbproject/genfiles.properties @@ -0,0 +1,8 @@ +build.xml.data.CRC32=7f5c7404 +build.xml.script.CRC32=1e022847 +build.xml.stylesheet.CRC32=28e38971@1.43.1.45 +# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. +# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. +nbproject/build-impl.xml.data.CRC32=7f5c7404 +nbproject/build-impl.xml.script.CRC32=f7ce2cb1 +nbproject/build-impl.xml.stylesheet.CRC32=0c01fd8e@1.43.1.45 diff --git a/Pro Java 7 NIO.2/Chapter07/channels/chl_02/nbproject/private/config.properties b/Pro Java 7 NIO.2/Chapter07/channels/chl_02/nbproject/private/config.properties new file mode 100644 index 0000000..e69de29 diff --git a/Pro Java 7 NIO.2/Chapter07/channels/chl_02/nbproject/private/private.properties b/Pro Java 7 NIO.2/Chapter07/channels/chl_02/nbproject/private/private.properties new file mode 100644 index 0000000..a5ab360 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter07/channels/chl_02/nbproject/private/private.properties @@ -0,0 +1,6 @@ +compile.on.save=true +do.depend=false +do.jar=true +javac.debug=true +javadoc.preview=true +user.properties.file=C:\\Users\\Leo\\.netbeans\\7.0\\build.properties diff --git a/Pro Java 7 NIO.2/Chapter07/channels/chl_02/nbproject/private/private.xml b/Pro Java 7 NIO.2/Chapter07/channels/chl_02/nbproject/private/private.xml new file mode 100644 index 0000000..c1f155a --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter07/channels/chl_02/nbproject/private/private.xml @@ -0,0 +1,4 @@ + + + + diff --git a/Pro Java 7 NIO.2/Chapter07/channels/chl_02/nbproject/project.properties b/Pro Java 7 NIO.2/Chapter07/channels/chl_02/nbproject/project.properties new file mode 100644 index 0000000..9cfa81c --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter07/channels/chl_02/nbproject/project.properties @@ -0,0 +1,72 @@ +annotation.processing.enabled=true +annotation.processing.enabled.in.editor=false +annotation.processing.run.all.processors=true +annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output +application.title=chl_02 +application.vendor=Leo +build.classes.dir=${build.dir}/classes +build.classes.excludes=**/*.java,**/*.form +# This directory is removed when the project is cleaned: +build.dir=build +build.generated.dir=${build.dir}/generated +build.generated.sources.dir=${build.dir}/generated-sources +# Only compile against the classpath explicitly listed here: +build.sysclasspath=ignore +build.test.classes.dir=${build.dir}/test/classes +build.test.results.dir=${build.dir}/test/results +# Uncomment to specify the preferred debugger connection transport: +#debug.transport=dt_socket +debug.classpath=\ + ${run.classpath} +debug.test.classpath=\ + ${run.test.classpath} +# This directory is removed when the project is cleaned: +dist.dir=dist +dist.jar=${dist.dir}/chl_02.jar +dist.javadoc.dir=${dist.dir}/javadoc +endorsed.classpath= +excludes= +includes=** +jar.compress=false +javac.classpath= +# Space-separated list of extra javac options +javac.compilerargs= +javac.deprecation=false +javac.processorpath=\ + ${javac.classpath} +javac.source=1.7 +javac.target=1.7 +javac.test.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +javac.test.processorpath=\ + ${javac.test.classpath} +javadoc.additionalparam= +javadoc.author=false +javadoc.encoding=${source.encoding} +javadoc.noindex=false +javadoc.nonavbar=false +javadoc.notree=false +javadoc.private=false +javadoc.splitindex=true +javadoc.use=true +javadoc.version=false +javadoc.windowtitle= +main.class=chl_02.Main +manifest.file=manifest.mf +meta.inf.dir=${src.dir}/META-INF +mkdist.disabled=false +platform.active=default_platform +run.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +# Space-separated list of JVM arguments used when running the project +# (you may also define separate properties like run-sys-prop.name=value instead of -Dname=value +# or test-sys-prop.name=value to set system properties for unit tests): +run.jvmargs= +run.test.classpath=\ + ${javac.test.classpath}:\ + ${build.test.classes.dir} +source.encoding=UTF-8 +src.dir=src +test.src.dir=test diff --git a/Pro Java 7 NIO.2/Chapter07/channels/chl_02/nbproject/project.xml b/Pro Java 7 NIO.2/Chapter07/channels/chl_02/nbproject/project.xml new file mode 100644 index 0000000..777c2c3 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter07/channels/chl_02/nbproject/project.xml @@ -0,0 +1,15 @@ + + + org.netbeans.modules.java.j2seproject + + + chl_02 + + + + + + + + + diff --git a/Pro Java 7 NIO.2/Chapter07/channels/chl_02/src/chl_02/Main.java b/Pro Java 7 NIO.2/Chapter07/channels/chl_02/src/chl_02/Main.java new file mode 100644 index 0000000..0117ebf --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter07/channels/chl_02/src/chl_02/Main.java @@ -0,0 +1,52 @@ +package chl_02; + +import java.io.IOException; +import java.nio.ByteBuffer; +import java.nio.channels.SeekableByteChannel; +import java.nio.channels.WritableByteChannel; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.nio.file.StandardOpenOption; +import java.util.EnumSet; + +/** + * + * @author Apress + */ +public class Main { + + public static void main(String[] args) { + + Path path = Paths.get("C:/rafaelnadal/grandslam/RolandGarros", "story.txt"); + + //write a file using SeekableByteChannel + try (SeekableByteChannel seekableByteChannel = Files.newByteChannel(path, EnumSet.of(StandardOpenOption.WRITE, StandardOpenOption.TRUNCATE_EXISTING))) { + + ByteBuffer buffer = ByteBuffer.wrap("Rafa Nadal produced another masterclass of clay-court tennis to win his fifth French Open title ...".getBytes()); + + int write = seekableByteChannel.write(buffer); + System.out.println("Number of written bytes: " + write); + + buffer.clear(); + + } catch (IOException ex) { + System.err.println(ex); + } + + System.out.println("\n"); + //write a file using WritableByteChannel + try (WritableByteChannel writableByteChannel = Files.newByteChannel(path, EnumSet.of(StandardOpenOption.WRITE, StandardOpenOption.APPEND))) { + + ByteBuffer buffer = ByteBuffer.wrap("Vamos Rafa!".getBytes()); + + int write = writableByteChannel.write(buffer); + System.out.println("Number of written bytes: " + write); + + buffer.clear(); + + } catch (IOException ex) { + System.err.println(ex); + } + } +} diff --git a/Pro Java 7 NIO.2/Chapter07/channels/chl_03/build.xml b/Pro Java 7 NIO.2/Chapter07/channels/chl_03/build.xml new file mode 100644 index 0000000..e73aabc --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter07/channels/chl_03/build.xml @@ -0,0 +1,74 @@ + + + + + + + + + + + Builds, tests, and runs the project chl_03. + + + diff --git a/Pro Java 7 NIO.2/Chapter07/channels/chl_03/build/built-jar.properties b/Pro Java 7 NIO.2/Chapter07/channels/chl_03/build/built-jar.properties new file mode 100644 index 0000000..f15b4ec --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter07/channels/chl_03/build/built-jar.properties @@ -0,0 +1,4 @@ +#Wed, 26 Oct 2011 08:53:50 +0200 + + +C\:\\NIO\\channels\\chl_03= diff --git a/Pro Java 7 NIO.2/Chapter07/channels/chl_03/build/classes/chl_03/Main.class b/Pro Java 7 NIO.2/Chapter07/channels/chl_03/build/classes/chl_03/Main.class new file mode 100644 index 0000000..6ca3f79 Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter07/channels/chl_03/build/classes/chl_03/Main.class differ diff --git a/Pro Java 7 NIO.2/Chapter07/channels/chl_03/dist/README.TXT b/Pro Java 7 NIO.2/Chapter07/channels/chl_03/dist/README.TXT new file mode 100644 index 0000000..a3a78c7 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter07/channels/chl_03/dist/README.TXT @@ -0,0 +1,32 @@ +======================== +BUILD OUTPUT DESCRIPTION +======================== + +When you build an Java application project that has a main class, the IDE +automatically copies all of the JAR +files on the projects classpath to your projects dist/lib folder. The IDE +also adds each of the JAR files to the Class-Path element in the application +JAR files manifest file (MANIFEST.MF). + +To run the project from the command line, go to the dist folder and +type the following: + +java -jar "chl_03.jar" + +To distribute this project, zip up the dist folder (including the lib folder) +and distribute the ZIP file. + +Notes: + +* If two JAR files on the project classpath have the same name, only the first +JAR file is copied to the lib folder. +* Only JAR files are copied to the lib folder. +If the classpath contains other types of files or folders, these files (folders) +are not copied. +* If a library on the projects classpath also has a Class-Path element +specified in the manifest,the content of the Class-Path element has to be on +the projects runtime path. +* To set a main class in a standard Java project, right-click the project node +in the Projects window and choose Properties. Then click Run and enter the +class name in the Main Class field. Alternatively, you can manually type the +class name in the manifest Main-Class element. diff --git a/Pro Java 7 NIO.2/Chapter07/channels/chl_03/dist/chl_03.jar b/Pro Java 7 NIO.2/Chapter07/channels/chl_03/dist/chl_03.jar new file mode 100644 index 0000000..f05b2b3 Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter07/channels/chl_03/dist/chl_03.jar differ diff --git a/Pro Java 7 NIO.2/Chapter07/channels/chl_03/manifest.mf b/Pro Java 7 NIO.2/Chapter07/channels/chl_03/manifest.mf new file mode 100644 index 0000000..328e8e5 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter07/channels/chl_03/manifest.mf @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +X-COMMENT: Main-Class will be added automatically by build + diff --git a/Pro Java 7 NIO.2/Chapter07/channels/chl_03/nbproject/build-impl.xml b/Pro Java 7 NIO.2/Chapter07/channels/chl_03/nbproject/build-impl.xml new file mode 100644 index 0000000..d9a0b1b --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter07/channels/chl_03/nbproject/build-impl.xml @@ -0,0 +1,1041 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set src.dir + Must set test.src.dir + Must set build.dir + Must set dist.dir + Must set build.classes.dir + Must set dist.javadoc.dir + Must set build.test.classes.dir + Must set build.test.results.dir + Must set build.classes.excludes + Must set dist.jar + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set JVM to use for profiling in profiler.info.jvm + Must set profiler agent JVM arguments in profiler.info.jvmargs.agent + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + + + + + + java -cp "${run.classpath.with.dist.jar}" ${main.class} + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + java -jar "${dist.jar.resolved}" + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set run.class + + + + Must select one file in the IDE or set run.class + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set debug.class + + + + + Must select one file in the IDE or set debug.class + + + + + Must set fix.includes + + + + + + + + + + + + + + + + + Must select one file in the IDE or set profile.class + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + Some tests failed; see details above. + + + + + + + + + Must select some files in the IDE or set test.includes + + + + Some tests failed; see details above. + + + + + Must select one file in the IDE or set test.class + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Pro Java 7 NIO.2/Chapter07/channels/chl_03/nbproject/genfiles.properties b/Pro Java 7 NIO.2/Chapter07/channels/chl_03/nbproject/genfiles.properties new file mode 100644 index 0000000..0c82f93 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter07/channels/chl_03/nbproject/genfiles.properties @@ -0,0 +1,8 @@ +build.xml.data.CRC32=774ff822 +build.xml.script.CRC32=687a6f5a +build.xml.stylesheet.CRC32=28e38971@1.43.1.45 +# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. +# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. +nbproject/build-impl.xml.data.CRC32=774ff822 +nbproject/build-impl.xml.script.CRC32=c37d0a99 +nbproject/build-impl.xml.stylesheet.CRC32=0c01fd8e@1.43.1.45 diff --git a/Pro Java 7 NIO.2/Chapter07/channels/chl_03/nbproject/private/config.properties b/Pro Java 7 NIO.2/Chapter07/channels/chl_03/nbproject/private/config.properties new file mode 100644 index 0000000..e69de29 diff --git a/Pro Java 7 NIO.2/Chapter07/channels/chl_03/nbproject/private/private.properties b/Pro Java 7 NIO.2/Chapter07/channels/chl_03/nbproject/private/private.properties new file mode 100644 index 0000000..a5ab360 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter07/channels/chl_03/nbproject/private/private.properties @@ -0,0 +1,6 @@ +compile.on.save=true +do.depend=false +do.jar=true +javac.debug=true +javadoc.preview=true +user.properties.file=C:\\Users\\Leo\\.netbeans\\7.0\\build.properties diff --git a/Pro Java 7 NIO.2/Chapter07/channels/chl_03/nbproject/private/private.xml b/Pro Java 7 NIO.2/Chapter07/channels/chl_03/nbproject/private/private.xml new file mode 100644 index 0000000..c1f155a --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter07/channels/chl_03/nbproject/private/private.xml @@ -0,0 +1,4 @@ + + + + diff --git a/Pro Java 7 NIO.2/Chapter07/channels/chl_03/nbproject/project.properties b/Pro Java 7 NIO.2/Chapter07/channels/chl_03/nbproject/project.properties new file mode 100644 index 0000000..a9eafe9 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter07/channels/chl_03/nbproject/project.properties @@ -0,0 +1,72 @@ +annotation.processing.enabled=true +annotation.processing.enabled.in.editor=false +annotation.processing.run.all.processors=true +annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output +application.title=chl_03 +application.vendor=Leo +build.classes.dir=${build.dir}/classes +build.classes.excludes=**/*.java,**/*.form +# This directory is removed when the project is cleaned: +build.dir=build +build.generated.dir=${build.dir}/generated +build.generated.sources.dir=${build.dir}/generated-sources +# Only compile against the classpath explicitly listed here: +build.sysclasspath=ignore +build.test.classes.dir=${build.dir}/test/classes +build.test.results.dir=${build.dir}/test/results +# Uncomment to specify the preferred debugger connection transport: +#debug.transport=dt_socket +debug.classpath=\ + ${run.classpath} +debug.test.classpath=\ + ${run.test.classpath} +# This directory is removed when the project is cleaned: +dist.dir=dist +dist.jar=${dist.dir}/chl_03.jar +dist.javadoc.dir=${dist.dir}/javadoc +endorsed.classpath= +excludes= +includes=** +jar.compress=false +javac.classpath= +# Space-separated list of extra javac options +javac.compilerargs= +javac.deprecation=false +javac.processorpath=\ + ${javac.classpath} +javac.source=1.7 +javac.target=1.7 +javac.test.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +javac.test.processorpath=\ + ${javac.test.classpath} +javadoc.additionalparam= +javadoc.author=false +javadoc.encoding=${source.encoding} +javadoc.noindex=false +javadoc.nonavbar=false +javadoc.notree=false +javadoc.private=false +javadoc.splitindex=true +javadoc.use=true +javadoc.version=false +javadoc.windowtitle= +main.class=chl_03.Main +manifest.file=manifest.mf +meta.inf.dir=${src.dir}/META-INF +mkdist.disabled=false +platform.active=default_platform +run.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +# Space-separated list of JVM arguments used when running the project +# (you may also define separate properties like run-sys-prop.name=value instead of -Dname=value +# or test-sys-prop.name=value to set system properties for unit tests): +run.jvmargs= +run.test.classpath=\ + ${javac.test.classpath}:\ + ${build.test.classes.dir} +source.encoding=UTF-8 +src.dir=src +test.src.dir=test diff --git a/Pro Java 7 NIO.2/Chapter07/channels/chl_03/nbproject/project.xml b/Pro Java 7 NIO.2/Chapter07/channels/chl_03/nbproject/project.xml new file mode 100644 index 0000000..2185a51 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter07/channels/chl_03/nbproject/project.xml @@ -0,0 +1,15 @@ + + + org.netbeans.modules.java.j2seproject + + + chl_03 + + + + + + + + + diff --git a/Pro Java 7 NIO.2/Chapter07/channels/chl_03/src/chl_03/Main.java b/Pro Java 7 NIO.2/Chapter07/channels/chl_03/src/chl_03/Main.java new file mode 100644 index 0000000..d9bac3e --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter07/channels/chl_03/src/chl_03/Main.java @@ -0,0 +1,43 @@ +package chl_03; + +import java.io.IOException; +import java.nio.ByteBuffer; +import java.nio.channels.SeekableByteChannel; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.nio.file.StandardOpenOption; +import java.nio.file.attribute.FileAttribute; +import java.nio.file.attribute.PosixFilePermission; +import java.nio.file.attribute.PosixFilePermissions; +import java.util.EnumSet; +import java.util.Set; + +/** + * + * @author Apress + */ +public class Main { + + public static void main(String[] args) { + + Path path = Paths.get("home/rafaelnadal/email", "email.txt"); + ByteBuffer buffer = ByteBuffer.wrap("Hi Rafa, I want to congratulate you for the amazing match that you played ... ".getBytes()); + + //create the custom permissions attribute for the email.txt file + Set perms = PosixFilePermissions.fromString("rw-r------"); + FileAttribute> attr = PosixFilePermissions.asFileAttribute(perms); + + //write a file using SeekableByteChannel + try (SeekableByteChannel seekableByteChannel = Files.newByteChannel(path, EnumSet.of(StandardOpenOption.CREATE, StandardOpenOption.APPEND), attr)) { + + int write = seekableByteChannel.write(buffer); + System.out.println("Number of written bytes: " + write); + + } catch (IOException ex) { + System.err.println(ex); + } + + buffer.clear(); + } +} diff --git a/Pro Java 7 NIO.2/Chapter07/channels/chl_04/build.xml b/Pro Java 7 NIO.2/Chapter07/channels/chl_04/build.xml new file mode 100644 index 0000000..3e1bec2 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter07/channels/chl_04/build.xml @@ -0,0 +1,74 @@ + + + + + + + + + + + Builds, tests, and runs the project chl_04. + + + diff --git a/Pro Java 7 NIO.2/Chapter07/channels/chl_04/build/built-jar.properties b/Pro Java 7 NIO.2/Chapter07/channels/chl_04/build/built-jar.properties new file mode 100644 index 0000000..e3a6bfa --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter07/channels/chl_04/build/built-jar.properties @@ -0,0 +1,4 @@ +#Wed, 26 Oct 2011 09:01:56 +0200 + + +C\:\\NIO\\channels\\chl_04= diff --git a/Pro Java 7 NIO.2/Chapter07/channels/chl_04/build/classes/chl_04/Main.class b/Pro Java 7 NIO.2/Chapter07/channels/chl_04/build/classes/chl_04/Main.class new file mode 100644 index 0000000..1ee0221 Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter07/channels/chl_04/build/classes/chl_04/Main.class differ diff --git a/Pro Java 7 NIO.2/Chapter07/channels/chl_04/dist/README.TXT b/Pro Java 7 NIO.2/Chapter07/channels/chl_04/dist/README.TXT new file mode 100644 index 0000000..58a804b --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter07/channels/chl_04/dist/README.TXT @@ -0,0 +1,32 @@ +======================== +BUILD OUTPUT DESCRIPTION +======================== + +When you build an Java application project that has a main class, the IDE +automatically copies all of the JAR +files on the projects classpath to your projects dist/lib folder. The IDE +also adds each of the JAR files to the Class-Path element in the application +JAR files manifest file (MANIFEST.MF). + +To run the project from the command line, go to the dist folder and +type the following: + +java -jar "chl_04.jar" + +To distribute this project, zip up the dist folder (including the lib folder) +and distribute the ZIP file. + +Notes: + +* If two JAR files on the project classpath have the same name, only the first +JAR file is copied to the lib folder. +* Only JAR files are copied to the lib folder. +If the classpath contains other types of files or folders, these files (folders) +are not copied. +* If a library on the projects classpath also has a Class-Path element +specified in the manifest,the content of the Class-Path element has to be on +the projects runtime path. +* To set a main class in a standard Java project, right-click the project node +in the Projects window and choose Properties. Then click Run and enter the +class name in the Main Class field. Alternatively, you can manually type the +class name in the manifest Main-Class element. diff --git a/Pro Java 7 NIO.2/Chapter07/channels/chl_04/dist/chl_04.jar b/Pro Java 7 NIO.2/Chapter07/channels/chl_04/dist/chl_04.jar new file mode 100644 index 0000000..4798cf0 Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter07/channels/chl_04/dist/chl_04.jar differ diff --git a/Pro Java 7 NIO.2/Chapter07/channels/chl_04/manifest.mf b/Pro Java 7 NIO.2/Chapter07/channels/chl_04/manifest.mf new file mode 100644 index 0000000..328e8e5 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter07/channels/chl_04/manifest.mf @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +X-COMMENT: Main-Class will be added automatically by build + diff --git a/Pro Java 7 NIO.2/Chapter07/channels/chl_04/nbproject/build-impl.xml b/Pro Java 7 NIO.2/Chapter07/channels/chl_04/nbproject/build-impl.xml new file mode 100644 index 0000000..3306732 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter07/channels/chl_04/nbproject/build-impl.xml @@ -0,0 +1,1041 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set src.dir + Must set test.src.dir + Must set build.dir + Must set dist.dir + Must set build.classes.dir + Must set dist.javadoc.dir + Must set build.test.classes.dir + Must set build.test.results.dir + Must set build.classes.excludes + Must set dist.jar + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set JVM to use for profiling in profiler.info.jvm + Must set profiler agent JVM arguments in profiler.info.jvmargs.agent + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + + + + + + java -cp "${run.classpath.with.dist.jar}" ${main.class} + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + java -jar "${dist.jar.resolved}" + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set run.class + + + + Must select one file in the IDE or set run.class + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set debug.class + + + + + Must select one file in the IDE or set debug.class + + + + + Must set fix.includes + + + + + + + + + + + + + + + + + Must select one file in the IDE or set profile.class + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + Some tests failed; see details above. + + + + + + + + + Must select some files in the IDE or set test.includes + + + + Some tests failed; see details above. + + + + + Must select one file in the IDE or set test.class + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Pro Java 7 NIO.2/Chapter07/channels/chl_04/nbproject/genfiles.properties b/Pro Java 7 NIO.2/Chapter07/channels/chl_04/nbproject/genfiles.properties new file mode 100644 index 0000000..e248a65 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter07/channels/chl_04/nbproject/genfiles.properties @@ -0,0 +1,8 @@ +build.xml.data.CRC32=4f355cd0 +build.xml.script.CRC32=f062bc48 +build.xml.stylesheet.CRC32=28e38971@1.43.1.45 +# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. +# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. +nbproject/build-impl.xml.data.CRC32=4f355cd0 +nbproject/build-impl.xml.script.CRC32=4c64f841 +nbproject/build-impl.xml.stylesheet.CRC32=0c01fd8e@1.43.1.45 diff --git a/Pro Java 7 NIO.2/Chapter07/channels/chl_04/nbproject/private/config.properties b/Pro Java 7 NIO.2/Chapter07/channels/chl_04/nbproject/private/config.properties new file mode 100644 index 0000000..e69de29 diff --git a/Pro Java 7 NIO.2/Chapter07/channels/chl_04/nbproject/private/private.properties b/Pro Java 7 NIO.2/Chapter07/channels/chl_04/nbproject/private/private.properties new file mode 100644 index 0000000..a5ab360 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter07/channels/chl_04/nbproject/private/private.properties @@ -0,0 +1,6 @@ +compile.on.save=true +do.depend=false +do.jar=true +javac.debug=true +javadoc.preview=true +user.properties.file=C:\\Users\\Leo\\.netbeans\\7.0\\build.properties diff --git a/Pro Java 7 NIO.2/Chapter07/channels/chl_04/nbproject/private/private.xml b/Pro Java 7 NIO.2/Chapter07/channels/chl_04/nbproject/private/private.xml new file mode 100644 index 0000000..c1f155a --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter07/channels/chl_04/nbproject/private/private.xml @@ -0,0 +1,4 @@ + + + + diff --git a/Pro Java 7 NIO.2/Chapter07/channels/chl_04/nbproject/project.properties b/Pro Java 7 NIO.2/Chapter07/channels/chl_04/nbproject/project.properties new file mode 100644 index 0000000..dfa1298 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter07/channels/chl_04/nbproject/project.properties @@ -0,0 +1,72 @@ +annotation.processing.enabled=true +annotation.processing.enabled.in.editor=false +annotation.processing.run.all.processors=true +annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output +application.title=chl_04 +application.vendor=Leo +build.classes.dir=${build.dir}/classes +build.classes.excludes=**/*.java,**/*.form +# This directory is removed when the project is cleaned: +build.dir=build +build.generated.dir=${build.dir}/generated +build.generated.sources.dir=${build.dir}/generated-sources +# Only compile against the classpath explicitly listed here: +build.sysclasspath=ignore +build.test.classes.dir=${build.dir}/test/classes +build.test.results.dir=${build.dir}/test/results +# Uncomment to specify the preferred debugger connection transport: +#debug.transport=dt_socket +debug.classpath=\ + ${run.classpath} +debug.test.classpath=\ + ${run.test.classpath} +# This directory is removed when the project is cleaned: +dist.dir=dist +dist.jar=${dist.dir}/chl_04.jar +dist.javadoc.dir=${dist.dir}/javadoc +endorsed.classpath= +excludes= +includes=** +jar.compress=false +javac.classpath= +# Space-separated list of extra javac options +javac.compilerargs= +javac.deprecation=false +javac.processorpath=\ + ${javac.classpath} +javac.source=1.7 +javac.target=1.7 +javac.test.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +javac.test.processorpath=\ + ${javac.test.classpath} +javadoc.additionalparam= +javadoc.author=false +javadoc.encoding=${source.encoding} +javadoc.noindex=false +javadoc.nonavbar=false +javadoc.notree=false +javadoc.private=false +javadoc.splitindex=true +javadoc.use=true +javadoc.version=false +javadoc.windowtitle= +main.class=chl_04.Main +manifest.file=manifest.mf +meta.inf.dir=${src.dir}/META-INF +mkdist.disabled=false +platform.active=default_platform +run.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +# Space-separated list of JVM arguments used when running the project +# (you may also define separate properties like run-sys-prop.name=value instead of -Dname=value +# or test-sys-prop.name=value to set system properties for unit tests): +run.jvmargs= +run.test.classpath=\ + ${javac.test.classpath}:\ + ${build.test.classes.dir} +source.encoding=UTF-8 +src.dir=src +test.src.dir=test diff --git a/Pro Java 7 NIO.2/Chapter07/channels/chl_04/nbproject/project.xml b/Pro Java 7 NIO.2/Chapter07/channels/chl_04/nbproject/project.xml new file mode 100644 index 0000000..6310547 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter07/channels/chl_04/nbproject/project.xml @@ -0,0 +1,15 @@ + + + org.netbeans.modules.java.j2seproject + + + chl_04 + + + + + + + + + diff --git a/Pro Java 7 NIO.2/Chapter07/channels/chl_04/src/chl_04/Main.java b/Pro Java 7 NIO.2/Chapter07/channels/chl_04/src/chl_04/Main.java new file mode 100644 index 0000000..d4732c4 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter07/channels/chl_04/src/chl_04/Main.java @@ -0,0 +1,45 @@ +package chl_04; + +import java.io.IOException; +import java.nio.ByteBuffer; +import java.nio.channels.SeekableByteChannel; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.nio.file.StandardOpenOption; +import java.util.EnumSet; + +/** + * + * @author Apress + */ +public class Main { + + public static void main(String[] args) { + + Path path = Paths.get("C:/rafaelnadal/tournaments/2009", "MovistarOpen.txt"); + ByteBuffer buffer_1 = ByteBuffer.wrap("Great players participate in our tournament, like: Tommy Robredo, Fernando Gonzalez, Jose Acasuso or Thomaz Bellucci.".getBytes()); + ByteBuffer buffer_2 = ByteBuffer.wrap("Gonzalez".getBytes()); + + try (SeekableByteChannel seekableByteChannel = (Files.newByteChannel(path, EnumSet.of(StandardOpenOption.WRITE)))) { + + seekableByteChannel.position(seekableByteChannel.size()); + + while (buffer_1.hasRemaining()) { + seekableByteChannel.write(buffer_1); + } + + seekableByteChannel.position(301); + + while (buffer_2.hasRemaining()) { + seekableByteChannel.write(buffer_2); + } + + buffer_1.clear(); + buffer_2.clear(); + + } catch (IOException ex) { + System.err.println(ex); + } + } +} diff --git a/Pro Java 7 NIO.2/Chapter07/channels/chl_05/build.xml b/Pro Java 7 NIO.2/Chapter07/channels/chl_05/build.xml new file mode 100644 index 0000000..83a8072 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter07/channels/chl_05/build.xml @@ -0,0 +1,74 @@ + + + + + + + + + + + Builds, tests, and runs the project chl_05. + + + diff --git a/Pro Java 7 NIO.2/Chapter07/channels/chl_05/build/built-jar.properties b/Pro Java 7 NIO.2/Chapter07/channels/chl_05/build/built-jar.properties new file mode 100644 index 0000000..005b7ab --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter07/channels/chl_05/build/built-jar.properties @@ -0,0 +1,4 @@ +#Wed, 26 Oct 2011 09:04:53 +0200 + + +C\:\\NIO\\channels\\chl_05= diff --git a/Pro Java 7 NIO.2/Chapter07/channels/chl_05/build/classes/chl_05/Main.class b/Pro Java 7 NIO.2/Chapter07/channels/chl_05/build/classes/chl_05/Main.class new file mode 100644 index 0000000..096ad39 Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter07/channels/chl_05/build/classes/chl_05/Main.class differ diff --git a/Pro Java 7 NIO.2/Chapter07/channels/chl_05/dist/README.TXT b/Pro Java 7 NIO.2/Chapter07/channels/chl_05/dist/README.TXT new file mode 100644 index 0000000..b5c4c6b --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter07/channels/chl_05/dist/README.TXT @@ -0,0 +1,32 @@ +======================== +BUILD OUTPUT DESCRIPTION +======================== + +When you build an Java application project that has a main class, the IDE +automatically copies all of the JAR +files on the projects classpath to your projects dist/lib folder. The IDE +also adds each of the JAR files to the Class-Path element in the application +JAR files manifest file (MANIFEST.MF). + +To run the project from the command line, go to the dist folder and +type the following: + +java -jar "chl_05.jar" + +To distribute this project, zip up the dist folder (including the lib folder) +and distribute the ZIP file. + +Notes: + +* If two JAR files on the project classpath have the same name, only the first +JAR file is copied to the lib folder. +* Only JAR files are copied to the lib folder. +If the classpath contains other types of files or folders, these files (folders) +are not copied. +* If a library on the projects classpath also has a Class-Path element +specified in the manifest,the content of the Class-Path element has to be on +the projects runtime path. +* To set a main class in a standard Java project, right-click the project node +in the Projects window and choose Properties. Then click Run and enter the +class name in the Main Class field. Alternatively, you can manually type the +class name in the manifest Main-Class element. diff --git a/Pro Java 7 NIO.2/Chapter07/channels/chl_05/dist/chl_05.jar b/Pro Java 7 NIO.2/Chapter07/channels/chl_05/dist/chl_05.jar new file mode 100644 index 0000000..11dc11e Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter07/channels/chl_05/dist/chl_05.jar differ diff --git a/Pro Java 7 NIO.2/Chapter07/channels/chl_05/manifest.mf b/Pro Java 7 NIO.2/Chapter07/channels/chl_05/manifest.mf new file mode 100644 index 0000000..328e8e5 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter07/channels/chl_05/manifest.mf @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +X-COMMENT: Main-Class will be added automatically by build + diff --git a/Pro Java 7 NIO.2/Chapter07/channels/chl_05/nbproject/build-impl.xml b/Pro Java 7 NIO.2/Chapter07/channels/chl_05/nbproject/build-impl.xml new file mode 100644 index 0000000..e4c98a8 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter07/channels/chl_05/nbproject/build-impl.xml @@ -0,0 +1,1041 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set src.dir + Must set test.src.dir + Must set build.dir + Must set dist.dir + Must set build.classes.dir + Must set dist.javadoc.dir + Must set build.test.classes.dir + Must set build.test.results.dir + Must set build.classes.excludes + Must set dist.jar + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set JVM to use for profiling in profiler.info.jvm + Must set profiler agent JVM arguments in profiler.info.jvmargs.agent + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + + + + + + java -cp "${run.classpath.with.dist.jar}" ${main.class} + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + java -jar "${dist.jar.resolved}" + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set run.class + + + + Must select one file in the IDE or set run.class + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set debug.class + + + + + Must select one file in the IDE or set debug.class + + + + + Must set fix.includes + + + + + + + + + + + + + + + + + Must select one file in the IDE or set profile.class + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + Some tests failed; see details above. + + + + + + + + + Must select some files in the IDE or set test.includes + + + + Some tests failed; see details above. + + + + + Must select one file in the IDE or set test.class + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Pro Java 7 NIO.2/Chapter07/channels/chl_05/nbproject/genfiles.properties b/Pro Java 7 NIO.2/Chapter07/channels/chl_05/nbproject/genfiles.properties new file mode 100644 index 0000000..583077a --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter07/channels/chl_05/nbproject/genfiles.properties @@ -0,0 +1,8 @@ +build.xml.data.CRC32=4726d0f6 +build.xml.script.CRC32=861afb55 +build.xml.stylesheet.CRC32=28e38971@1.43.1.45 +# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. +# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. +nbproject/build-impl.xml.data.CRC32=4726d0f6 +nbproject/build-impl.xml.script.CRC32=78d7de69 +nbproject/build-impl.xml.stylesheet.CRC32=0c01fd8e@1.43.1.45 diff --git a/Pro Java 7 NIO.2/Chapter07/channels/chl_05/nbproject/private/config.properties b/Pro Java 7 NIO.2/Chapter07/channels/chl_05/nbproject/private/config.properties new file mode 100644 index 0000000..e69de29 diff --git a/Pro Java 7 NIO.2/Chapter07/channels/chl_05/nbproject/private/private.properties b/Pro Java 7 NIO.2/Chapter07/channels/chl_05/nbproject/private/private.properties new file mode 100644 index 0000000..a5ab360 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter07/channels/chl_05/nbproject/private/private.properties @@ -0,0 +1,6 @@ +compile.on.save=true +do.depend=false +do.jar=true +javac.debug=true +javadoc.preview=true +user.properties.file=C:\\Users\\Leo\\.netbeans\\7.0\\build.properties diff --git a/Pro Java 7 NIO.2/Chapter07/channels/chl_05/nbproject/private/private.xml b/Pro Java 7 NIO.2/Chapter07/channels/chl_05/nbproject/private/private.xml new file mode 100644 index 0000000..c1f155a --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter07/channels/chl_05/nbproject/private/private.xml @@ -0,0 +1,4 @@ + + + + diff --git a/Pro Java 7 NIO.2/Chapter07/channels/chl_05/nbproject/project.properties b/Pro Java 7 NIO.2/Chapter07/channels/chl_05/nbproject/project.properties new file mode 100644 index 0000000..1a2a6a3 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter07/channels/chl_05/nbproject/project.properties @@ -0,0 +1,72 @@ +annotation.processing.enabled=true +annotation.processing.enabled.in.editor=false +annotation.processing.run.all.processors=true +annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output +application.title=chl_05 +application.vendor=Leo +build.classes.dir=${build.dir}/classes +build.classes.excludes=**/*.java,**/*.form +# This directory is removed when the project is cleaned: +build.dir=build +build.generated.dir=${build.dir}/generated +build.generated.sources.dir=${build.dir}/generated-sources +# Only compile against the classpath explicitly listed here: +build.sysclasspath=ignore +build.test.classes.dir=${build.dir}/test/classes +build.test.results.dir=${build.dir}/test/results +# Uncomment to specify the preferred debugger connection transport: +#debug.transport=dt_socket +debug.classpath=\ + ${run.classpath} +debug.test.classpath=\ + ${run.test.classpath} +# This directory is removed when the project is cleaned: +dist.dir=dist +dist.jar=${dist.dir}/chl_05.jar +dist.javadoc.dir=${dist.dir}/javadoc +endorsed.classpath= +excludes= +includes=** +jar.compress=false +javac.classpath= +# Space-separated list of extra javac options +javac.compilerargs= +javac.deprecation=false +javac.processorpath=\ + ${javac.classpath} +javac.source=1.7 +javac.target=1.7 +javac.test.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +javac.test.processorpath=\ + ${javac.test.classpath} +javadoc.additionalparam= +javadoc.author=false +javadoc.encoding=${source.encoding} +javadoc.noindex=false +javadoc.nonavbar=false +javadoc.notree=false +javadoc.private=false +javadoc.splitindex=true +javadoc.use=true +javadoc.version=false +javadoc.windowtitle= +main.class=chl_05.Main +manifest.file=manifest.mf +meta.inf.dir=${src.dir}/META-INF +mkdist.disabled=false +platform.active=default_platform +run.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +# Space-separated list of JVM arguments used when running the project +# (you may also define separate properties like run-sys-prop.name=value instead of -Dname=value +# or test-sys-prop.name=value to set system properties for unit tests): +run.jvmargs= +run.test.classpath=\ + ${javac.test.classpath}:\ + ${build.test.classes.dir} +source.encoding=UTF-8 +src.dir=src +test.src.dir=test diff --git a/Pro Java 7 NIO.2/Chapter07/channels/chl_05/nbproject/project.xml b/Pro Java 7 NIO.2/Chapter07/channels/chl_05/nbproject/project.xml new file mode 100644 index 0000000..95ce937 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter07/channels/chl_05/nbproject/project.xml @@ -0,0 +1,15 @@ + + + org.netbeans.modules.java.j2seproject + + + chl_05 + + + + + + + + + diff --git a/Pro Java 7 NIO.2/Chapter07/channels/chl_05/src/chl_05/Main.java b/Pro Java 7 NIO.2/Chapter07/channels/chl_05/src/chl_05/Main.java new file mode 100644 index 0000000..d202b4d --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter07/channels/chl_05/src/chl_05/Main.java @@ -0,0 +1,45 @@ +package chl_05; + +import java.io.IOException; +import java.nio.ByteBuffer; +import java.nio.channels.SeekableByteChannel; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.nio.file.StandardOpenOption; +import java.util.EnumSet; + +/** + * + * @author Apress + */ +public class Main { + + public static void main(String[] args) { + + Path path = Paths.get("C:/rafaelnadal/tournaments/2009", "HeinekenOpen.txt"); + + ByteBuffer copy = ByteBuffer.allocate(25); + copy.put("\n".getBytes()); + + try (SeekableByteChannel seekableByteChannel = (Files.newByteChannel(path, EnumSet.of(StandardOpenOption.READ, StandardOpenOption.WRITE)))) { + + int nbytes; + do { + nbytes = seekableByteChannel.read(copy); + } while (nbytes != -1 && copy.hasRemaining()); + + copy.flip(); + + seekableByteChannel.position(seekableByteChannel.size()); + while (copy.hasRemaining()) { + seekableByteChannel.write(copy); + } + + copy.clear(); + + } catch (IOException ex) { + System.err.println(ex); + } + } +} diff --git a/Pro Java 7 NIO.2/Chapter07/channels/chl_06/build.xml b/Pro Java 7 NIO.2/Chapter07/channels/chl_06/build.xml new file mode 100644 index 0000000..56349fd --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter07/channels/chl_06/build.xml @@ -0,0 +1,74 @@ + + + + + + + + + + + Builds, tests, and runs the project chl_06. + + + diff --git a/Pro Java 7 NIO.2/Chapter07/channels/chl_06/build/built-jar.properties b/Pro Java 7 NIO.2/Chapter07/channels/chl_06/build/built-jar.properties new file mode 100644 index 0000000..a20697d --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter07/channels/chl_06/build/built-jar.properties @@ -0,0 +1,4 @@ +#Wed, 26 Oct 2011 09:08:02 +0200 + + +C\:\\NIO\\channels\\chl_06= diff --git a/Pro Java 7 NIO.2/Chapter07/channels/chl_06/build/classes/chl_06/Main.class b/Pro Java 7 NIO.2/Chapter07/channels/chl_06/build/classes/chl_06/Main.class new file mode 100644 index 0000000..eba4c47 Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter07/channels/chl_06/build/classes/chl_06/Main.class differ diff --git a/Pro Java 7 NIO.2/Chapter07/channels/chl_06/dist/README.TXT b/Pro Java 7 NIO.2/Chapter07/channels/chl_06/dist/README.TXT new file mode 100644 index 0000000..745720a --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter07/channels/chl_06/dist/README.TXT @@ -0,0 +1,32 @@ +======================== +BUILD OUTPUT DESCRIPTION +======================== + +When you build an Java application project that has a main class, the IDE +automatically copies all of the JAR +files on the projects classpath to your projects dist/lib folder. The IDE +also adds each of the JAR files to the Class-Path element in the application +JAR files manifest file (MANIFEST.MF). + +To run the project from the command line, go to the dist folder and +type the following: + +java -jar "chl_06.jar" + +To distribute this project, zip up the dist folder (including the lib folder) +and distribute the ZIP file. + +Notes: + +* If two JAR files on the project classpath have the same name, only the first +JAR file is copied to the lib folder. +* Only JAR files are copied to the lib folder. +If the classpath contains other types of files or folders, these files (folders) +are not copied. +* If a library on the projects classpath also has a Class-Path element +specified in the manifest,the content of the Class-Path element has to be on +the projects runtime path. +* To set a main class in a standard Java project, right-click the project node +in the Projects window and choose Properties. Then click Run and enter the +class name in the Main Class field. Alternatively, you can manually type the +class name in the manifest Main-Class element. diff --git a/Pro Java 7 NIO.2/Chapter07/channels/chl_06/dist/chl_06.jar b/Pro Java 7 NIO.2/Chapter07/channels/chl_06/dist/chl_06.jar new file mode 100644 index 0000000..89773ae Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter07/channels/chl_06/dist/chl_06.jar differ diff --git a/Pro Java 7 NIO.2/Chapter07/channels/chl_06/manifest.mf b/Pro Java 7 NIO.2/Chapter07/channels/chl_06/manifest.mf new file mode 100644 index 0000000..328e8e5 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter07/channels/chl_06/manifest.mf @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +X-COMMENT: Main-Class will be added automatically by build + diff --git a/Pro Java 7 NIO.2/Chapter07/channels/chl_06/nbproject/build-impl.xml b/Pro Java 7 NIO.2/Chapter07/channels/chl_06/nbproject/build-impl.xml new file mode 100644 index 0000000..3e29b4a --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter07/channels/chl_06/nbproject/build-impl.xml @@ -0,0 +1,1041 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set src.dir + Must set test.src.dir + Must set build.dir + Must set dist.dir + Must set build.classes.dir + Must set dist.javadoc.dir + Must set build.test.classes.dir + Must set build.test.results.dir + Must set build.classes.excludes + Must set dist.jar + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set JVM to use for profiling in profiler.info.jvm + Must set profiler agent JVM arguments in profiler.info.jvmargs.agent + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + + + + + + java -cp "${run.classpath.with.dist.jar}" ${main.class} + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + java -jar "${dist.jar.resolved}" + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set run.class + + + + Must select one file in the IDE or set run.class + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set debug.class + + + + + Must select one file in the IDE or set debug.class + + + + + Must set fix.includes + + + + + + + + + + + + + + + + + Must select one file in the IDE or set profile.class + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + Some tests failed; see details above. + + + + + + + + + Must select some files in the IDE or set test.includes + + + + Some tests failed; see details above. + + + + + Must select one file in the IDE or set test.class + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Pro Java 7 NIO.2/Chapter07/channels/chl_06/nbproject/genfiles.properties b/Pro Java 7 NIO.2/Chapter07/channels/chl_06/nbproject/genfiles.properties new file mode 100644 index 0000000..7213d4b --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter07/channels/chl_06/nbproject/genfiles.properties @@ -0,0 +1,8 @@ +build.xml.data.CRC32=5f12449c +build.xml.script.CRC32=1c923272 +build.xml.stylesheet.CRC32=28e38971@1.43.1.45 +# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. +# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. +nbproject/build-impl.xml.data.CRC32=5f12449c +nbproject/build-impl.xml.script.CRC32=2502b411 +nbproject/build-impl.xml.stylesheet.CRC32=0c01fd8e@1.43.1.45 diff --git a/Pro Java 7 NIO.2/Chapter07/channels/chl_06/nbproject/private/config.properties b/Pro Java 7 NIO.2/Chapter07/channels/chl_06/nbproject/private/config.properties new file mode 100644 index 0000000..e69de29 diff --git a/Pro Java 7 NIO.2/Chapter07/channels/chl_06/nbproject/private/private.properties b/Pro Java 7 NIO.2/Chapter07/channels/chl_06/nbproject/private/private.properties new file mode 100644 index 0000000..a5ab360 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter07/channels/chl_06/nbproject/private/private.properties @@ -0,0 +1,6 @@ +compile.on.save=true +do.depend=false +do.jar=true +javac.debug=true +javadoc.preview=true +user.properties.file=C:\\Users\\Leo\\.netbeans\\7.0\\build.properties diff --git a/Pro Java 7 NIO.2/Chapter07/channels/chl_06/nbproject/private/private.xml b/Pro Java 7 NIO.2/Chapter07/channels/chl_06/nbproject/private/private.xml new file mode 100644 index 0000000..c1f155a --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter07/channels/chl_06/nbproject/private/private.xml @@ -0,0 +1,4 @@ + + + + diff --git a/Pro Java 7 NIO.2/Chapter07/channels/chl_06/nbproject/project.properties b/Pro Java 7 NIO.2/Chapter07/channels/chl_06/nbproject/project.properties new file mode 100644 index 0000000..0b8813e --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter07/channels/chl_06/nbproject/project.properties @@ -0,0 +1,72 @@ +annotation.processing.enabled=true +annotation.processing.enabled.in.editor=false +annotation.processing.run.all.processors=true +annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output +application.title=chl_06 +application.vendor=Leo +build.classes.dir=${build.dir}/classes +build.classes.excludes=**/*.java,**/*.form +# This directory is removed when the project is cleaned: +build.dir=build +build.generated.dir=${build.dir}/generated +build.generated.sources.dir=${build.dir}/generated-sources +# Only compile against the classpath explicitly listed here: +build.sysclasspath=ignore +build.test.classes.dir=${build.dir}/test/classes +build.test.results.dir=${build.dir}/test/results +# Uncomment to specify the preferred debugger connection transport: +#debug.transport=dt_socket +debug.classpath=\ + ${run.classpath} +debug.test.classpath=\ + ${run.test.classpath} +# This directory is removed when the project is cleaned: +dist.dir=dist +dist.jar=${dist.dir}/chl_06.jar +dist.javadoc.dir=${dist.dir}/javadoc +endorsed.classpath= +excludes= +includes=** +jar.compress=false +javac.classpath= +# Space-separated list of extra javac options +javac.compilerargs= +javac.deprecation=false +javac.processorpath=\ + ${javac.classpath} +javac.source=1.7 +javac.target=1.7 +javac.test.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +javac.test.processorpath=\ + ${javac.test.classpath} +javadoc.additionalparam= +javadoc.author=false +javadoc.encoding=${source.encoding} +javadoc.noindex=false +javadoc.nonavbar=false +javadoc.notree=false +javadoc.private=false +javadoc.splitindex=true +javadoc.use=true +javadoc.version=false +javadoc.windowtitle= +main.class=chl_06.Main +manifest.file=manifest.mf +meta.inf.dir=${src.dir}/META-INF +mkdist.disabled=false +platform.active=default_platform +run.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +# Space-separated list of JVM arguments used when running the project +# (you may also define separate properties like run-sys-prop.name=value instead of -Dname=value +# or test-sys-prop.name=value to set system properties for unit tests): +run.jvmargs= +run.test.classpath=\ + ${javac.test.classpath}:\ + ${build.test.classes.dir} +source.encoding=UTF-8 +src.dir=src +test.src.dir=test diff --git a/Pro Java 7 NIO.2/Chapter07/channels/chl_06/nbproject/project.xml b/Pro Java 7 NIO.2/Chapter07/channels/chl_06/nbproject/project.xml new file mode 100644 index 0000000..b1e139d --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter07/channels/chl_06/nbproject/project.xml @@ -0,0 +1,15 @@ + + + org.netbeans.modules.java.j2seproject + + + chl_06 + + + + + + + + + diff --git a/Pro Java 7 NIO.2/Chapter07/channels/chl_06/src/chl_06/Main.java b/Pro Java 7 NIO.2/Chapter07/channels/chl_06/src/chl_06/Main.java new file mode 100644 index 0000000..0be0171 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter07/channels/chl_06/src/chl_06/Main.java @@ -0,0 +1,40 @@ +package chl_06; + +import java.io.IOException; +import java.nio.ByteBuffer; +import java.nio.channels.SeekableByteChannel; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.nio.file.StandardOpenOption; +import java.util.EnumSet; + +/** + * + * @author Apress + */ +public class Main { + + public static void main(String[] args) { + + Path path = Paths.get("C:/rafaelnadal/tournaments/2009", "BrasilOpen.txt"); + + ByteBuffer buffer = ByteBuffer.wrap("The tournament has taken a lead in environmental conservation efforts, with highlights including the planting of 500 trees to neutralise carbon emissions and providing recyclable materials to local children for use in craft work.".getBytes()); + + try (SeekableByteChannel seekableByteChannel = (Files.newByteChannel(path, EnumSet.of(StandardOpenOption.READ, StandardOpenOption.WRITE)))) { + + seekableByteChannel.truncate(200); + + seekableByteChannel.position(seekableByteChannel.size()-1); + while (buffer.hasRemaining()) { + seekableByteChannel.write(buffer); + } + + buffer.clear(); + + } catch (IOException ex) { + System.err.println(ex); + } + + } +} diff --git a/Pro Java 7 NIO.2/Chapter07/channels/chl_07/build.xml b/Pro Java 7 NIO.2/Chapter07/channels/chl_07/build.xml new file mode 100644 index 0000000..8186b90 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter07/channels/chl_07/build.xml @@ -0,0 +1,74 @@ + + + + + + + + + + + Builds, tests, and runs the project chl_07. + + + diff --git a/Pro Java 7 NIO.2/Chapter07/channels/chl_07/build/built-jar.properties b/Pro Java 7 NIO.2/Chapter07/channels/chl_07/build/built-jar.properties new file mode 100644 index 0000000..1a214ed --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter07/channels/chl_07/build/built-jar.properties @@ -0,0 +1,4 @@ +#Wed, 26 Oct 2011 09:54:43 +0200 + + +C\:\\NIO\\channels\\chl_07= diff --git a/Pro Java 7 NIO.2/Chapter07/channels/chl_07/build/classes/chl_07/Main.class b/Pro Java 7 NIO.2/Chapter07/channels/chl_07/build/classes/chl_07/Main.class new file mode 100644 index 0000000..81a5b9f Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter07/channels/chl_07/build/classes/chl_07/Main.class differ diff --git a/Pro Java 7 NIO.2/Chapter07/channels/chl_07/dist/README.TXT b/Pro Java 7 NIO.2/Chapter07/channels/chl_07/dist/README.TXT new file mode 100644 index 0000000..fb18fdf --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter07/channels/chl_07/dist/README.TXT @@ -0,0 +1,32 @@ +======================== +BUILD OUTPUT DESCRIPTION +======================== + +When you build an Java application project that has a main class, the IDE +automatically copies all of the JAR +files on the projects classpath to your projects dist/lib folder. The IDE +also adds each of the JAR files to the Class-Path element in the application +JAR files manifest file (MANIFEST.MF). + +To run the project from the command line, go to the dist folder and +type the following: + +java -jar "chl_07.jar" + +To distribute this project, zip up the dist folder (including the lib folder) +and distribute the ZIP file. + +Notes: + +* If two JAR files on the project classpath have the same name, only the first +JAR file is copied to the lib folder. +* Only JAR files are copied to the lib folder. +If the classpath contains other types of files or folders, these files (folders) +are not copied. +* If a library on the projects classpath also has a Class-Path element +specified in the manifest,the content of the Class-Path element has to be on +the projects runtime path. +* To set a main class in a standard Java project, right-click the project node +in the Projects window and choose Properties. Then click Run and enter the +class name in the Main Class field. Alternatively, you can manually type the +class name in the manifest Main-Class element. diff --git a/Pro Java 7 NIO.2/Chapter07/channels/chl_07/dist/chl_07.jar b/Pro Java 7 NIO.2/Chapter07/channels/chl_07/dist/chl_07.jar new file mode 100644 index 0000000..cda3100 Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter07/channels/chl_07/dist/chl_07.jar differ diff --git a/Pro Java 7 NIO.2/Chapter07/channels/chl_07/manifest.mf b/Pro Java 7 NIO.2/Chapter07/channels/chl_07/manifest.mf new file mode 100644 index 0000000..328e8e5 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter07/channels/chl_07/manifest.mf @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +X-COMMENT: Main-Class will be added automatically by build + diff --git a/Pro Java 7 NIO.2/Chapter07/channels/chl_07/nbproject/build-impl.xml b/Pro Java 7 NIO.2/Chapter07/channels/chl_07/nbproject/build-impl.xml new file mode 100644 index 0000000..fd0a1c4 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter07/channels/chl_07/nbproject/build-impl.xml @@ -0,0 +1,1041 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set src.dir + Must set test.src.dir + Must set build.dir + Must set dist.dir + Must set build.classes.dir + Must set dist.javadoc.dir + Must set build.test.classes.dir + Must set build.test.results.dir + Must set build.classes.excludes + Must set dist.jar + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set JVM to use for profiling in profiler.info.jvm + Must set profiler agent JVM arguments in profiler.info.jvmargs.agent + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + + + + + + java -cp "${run.classpath.with.dist.jar}" ${main.class} + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + java -jar "${dist.jar.resolved}" + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set run.class + + + + Must select one file in the IDE or set run.class + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set debug.class + + + + + Must select one file in the IDE or set debug.class + + + + + Must set fix.includes + + + + + + + + + + + + + + + + + Must select one file in the IDE or set profile.class + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + Some tests failed; see details above. + + + + + + + + + Must select some files in the IDE or set test.includes + + + + Some tests failed; see details above. + + + + + Must select one file in the IDE or set test.class + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Pro Java 7 NIO.2/Chapter07/channels/chl_07/nbproject/genfiles.properties b/Pro Java 7 NIO.2/Chapter07/channels/chl_07/nbproject/genfiles.properties new file mode 100644 index 0000000..ea89b1e --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter07/channels/chl_07/nbproject/genfiles.properties @@ -0,0 +1,8 @@ +build.xml.data.CRC32=5701c8ba +build.xml.script.CRC32=6aea756f +build.xml.stylesheet.CRC32=28e38971@1.43.1.45 +# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. +# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. +nbproject/build-impl.xml.data.CRC32=5701c8ba +nbproject/build-impl.xml.script.CRC32=11b19239 +nbproject/build-impl.xml.stylesheet.CRC32=0c01fd8e@1.43.1.45 diff --git a/Pro Java 7 NIO.2/Chapter07/channels/chl_07/nbproject/private/config.properties b/Pro Java 7 NIO.2/Chapter07/channels/chl_07/nbproject/private/config.properties new file mode 100644 index 0000000..e69de29 diff --git a/Pro Java 7 NIO.2/Chapter07/channels/chl_07/nbproject/private/private.properties b/Pro Java 7 NIO.2/Chapter07/channels/chl_07/nbproject/private/private.properties new file mode 100644 index 0000000..a5ab360 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter07/channels/chl_07/nbproject/private/private.properties @@ -0,0 +1,6 @@ +compile.on.save=true +do.depend=false +do.jar=true +javac.debug=true +javadoc.preview=true +user.properties.file=C:\\Users\\Leo\\.netbeans\\7.0\\build.properties diff --git a/Pro Java 7 NIO.2/Chapter07/channels/chl_07/nbproject/private/private.xml b/Pro Java 7 NIO.2/Chapter07/channels/chl_07/nbproject/private/private.xml new file mode 100644 index 0000000..c1f155a --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter07/channels/chl_07/nbproject/private/private.xml @@ -0,0 +1,4 @@ + + + + diff --git a/Pro Java 7 NIO.2/Chapter07/channels/chl_07/nbproject/project.properties b/Pro Java 7 NIO.2/Chapter07/channels/chl_07/nbproject/project.properties new file mode 100644 index 0000000..151c194 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter07/channels/chl_07/nbproject/project.properties @@ -0,0 +1,72 @@ +annotation.processing.enabled=true +annotation.processing.enabled.in.editor=false +annotation.processing.run.all.processors=true +annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output +application.title=chl_07 +application.vendor=Leo +build.classes.dir=${build.dir}/classes +build.classes.excludes=**/*.java,**/*.form +# This directory is removed when the project is cleaned: +build.dir=build +build.generated.dir=${build.dir}/generated +build.generated.sources.dir=${build.dir}/generated-sources +# Only compile against the classpath explicitly listed here: +build.sysclasspath=ignore +build.test.classes.dir=${build.dir}/test/classes +build.test.results.dir=${build.dir}/test/results +# Uncomment to specify the preferred debugger connection transport: +#debug.transport=dt_socket +debug.classpath=\ + ${run.classpath} +debug.test.classpath=\ + ${run.test.classpath} +# This directory is removed when the project is cleaned: +dist.dir=dist +dist.jar=${dist.dir}/chl_07.jar +dist.javadoc.dir=${dist.dir}/javadoc +endorsed.classpath= +excludes= +includes=** +jar.compress=false +javac.classpath= +# Space-separated list of extra javac options +javac.compilerargs= +javac.deprecation=false +javac.processorpath=\ + ${javac.classpath} +javac.source=1.7 +javac.target=1.7 +javac.test.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +javac.test.processorpath=\ + ${javac.test.classpath} +javadoc.additionalparam= +javadoc.author=false +javadoc.encoding=${source.encoding} +javadoc.noindex=false +javadoc.nonavbar=false +javadoc.notree=false +javadoc.private=false +javadoc.splitindex=true +javadoc.use=true +javadoc.version=false +javadoc.windowtitle= +main.class=chl_07.Main +manifest.file=manifest.mf +meta.inf.dir=${src.dir}/META-INF +mkdist.disabled=false +platform.active=default_platform +run.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +# Space-separated list of JVM arguments used when running the project +# (you may also define separate properties like run-sys-prop.name=value instead of -Dname=value +# or test-sys-prop.name=value to set system properties for unit tests): +run.jvmargs= +run.test.classpath=\ + ${javac.test.classpath}:\ + ${build.test.classes.dir} +source.encoding=UTF-8 +src.dir=src +test.src.dir=test diff --git a/Pro Java 7 NIO.2/Chapter07/channels/chl_07/nbproject/project.xml b/Pro Java 7 NIO.2/Chapter07/channels/chl_07/nbproject/project.xml new file mode 100644 index 0000000..b143ad7 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter07/channels/chl_07/nbproject/project.xml @@ -0,0 +1,15 @@ + + + org.netbeans.modules.java.j2seproject + + + chl_07 + + + + + + + + + diff --git a/Pro Java 7 NIO.2/Chapter07/channels/chl_07/src/chl_07/Main.java b/Pro Java 7 NIO.2/Chapter07/channels/chl_07/src/chl_07/Main.java new file mode 100644 index 0000000..c7765fa --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter07/channels/chl_07/src/chl_07/Main.java @@ -0,0 +1,242 @@ +package chl_07; + +import java.nio.MappedByteBuffer; +import java.io.OutputStream; +import java.io.InputStream; +import java.io.BufferedInputStream; +import java.io.BufferedOutputStream; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.nio.ByteBuffer; +import java.nio.channels.FileChannel; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.nio.file.StandardOpenOption; +import java.util.EnumSet; +import static java.nio.file.LinkOption.NOFOLLOW_LINKS; + +/** + * + * @author Apress + */ +public class Main { + + public static void deleteCopied(Path path){ + + try { + Files.deleteIfExists(path); + } catch (IOException ex) { + System.err.println(ex); + } + + } + + public static void main(String[] args) { + + final Path copy_from = Paths.get("C:/rafaelnadal/tournaments/2009/videos/Rafa Best Shots.mp4"); + final Path copy_to = Paths.get("C:/Rafa Best Shots.mp4"); + long startTime, elapsedTime; + int bufferSizeKB = 4; + int bufferSize = bufferSizeKB * 1024; + + deleteCopied(copy_to); + + //FileChannel and indirect buffer + System.out.println("Using FileChannel and non-direct buffer ..."); + try (FileChannel fileChannel_from = (FileChannel.open(copy_from, EnumSet.of(StandardOpenOption.READ))); + FileChannel fileChannel_to = (FileChannel.open(copy_to, EnumSet.of(StandardOpenOption.CREATE_NEW, StandardOpenOption.WRITE)))) { + + startTime = System.nanoTime(); + + // Allocate an non-direct ByteBuffer + ByteBuffer bytebuffer = ByteBuffer.allocate(bufferSize); + + // Read data from file into ByteBuffer + int bytesCount; + while ((bytesCount = fileChannel_from.read(bytebuffer)) > 0) { + //flip the buffer which set the limit to current position, and position to 0 + bytebuffer.flip(); + //write data from ByteBuffer to file + fileChannel_to.write(bytebuffer); + //for the next read + bytebuffer.clear(); + } + elapsedTime = System.nanoTime() - startTime; + System.out.println("Elapsed Time is " + (elapsedTime / 1000000000.0) + " seconds"); + } catch (IOException ex) { + System.err.println(ex); + } + + deleteCopied(copy_to); + + //FileChannel and direct buffer + System.out.println("Using FileChannel and direct buffer ..."); + try (FileChannel fileChannel_from = (FileChannel.open(copy_from, EnumSet.of(StandardOpenOption.READ))); + FileChannel fileChannel_to = (FileChannel.open(copy_to, EnumSet.of(StandardOpenOption.CREATE_NEW, StandardOpenOption.WRITE)))) { + + startTime = System.nanoTime(); + + // Allocate an direct ByteBuffer + ByteBuffer bytebuffer = ByteBuffer.allocateDirect(bufferSize); + + // Read data from file into ByteBuffer + int bytesCount; + while ((bytesCount = fileChannel_from.read(bytebuffer)) > 0) { + //flip the buffer which set the limit to current position, and position to 0 + bytebuffer.flip(); + //write data from ByteBuffer to file + fileChannel_to.write(bytebuffer); + //for the next read + bytebuffer.clear(); + } + elapsedTime = System.nanoTime() - startTime; + System.out.println("Elapsed Time is " + (elapsedTime / 1000000000.0) + " seconds"); + } catch (IOException ex) { + System.err.println(ex); + } + + deleteCopied(copy_to); + + //FileChannel and transferTo + System.out.println("Using FileChannel.transferTo method ..."); + try (FileChannel fileChannel_from = (FileChannel.open(copy_from, EnumSet.of(StandardOpenOption.READ))); + FileChannel fileChannel_to = (FileChannel.open(copy_to, EnumSet.of(StandardOpenOption.CREATE_NEW, StandardOpenOption.WRITE)))) { + + startTime = System.nanoTime(); + + fileChannel_from.transferTo(0L, fileChannel_from.size(), fileChannel_to); + + elapsedTime = System.nanoTime() - startTime; + System.out.println("Elapsed Time is " + (elapsedTime / 1000000000.0) + " seconds"); + } catch (IOException ex) { + System.err.println(ex); + } + + deleteCopied(copy_to); + + //FileChannel and transfer from + System.out.println("Using FileChannel.transferFrom method ..."); + try (FileChannel fileChannel_from = (FileChannel.open(copy_from, EnumSet.of(StandardOpenOption.READ))); + FileChannel fileChannel_to = (FileChannel.open(copy_to, EnumSet.of(StandardOpenOption.CREATE_NEW, StandardOpenOption.WRITE)))) { + + startTime = System.nanoTime(); + + fileChannel_to.transferFrom(fileChannel_from, 0L, (int) fileChannel_from.size()); + + elapsedTime = System.nanoTime() - startTime; + System.out.println("Elapsed Time is " + (elapsedTime / 1000000000.0) + " seconds"); + } catch (IOException ex) { + System.err.println(ex); + } + + deleteCopied(copy_to); + + //FileChannel.map + System.out.println("Using FileChannel.map method ..."); + try (FileChannel fileChannel_from = (FileChannel.open(copy_from, EnumSet.of(StandardOpenOption.READ))); + FileChannel fileChannel_to = (FileChannel.open(copy_to, EnumSet.of(StandardOpenOption.CREATE_NEW, StandardOpenOption.WRITE)))) { + + startTime = System.nanoTime(); + + MappedByteBuffer buffer = fileChannel_from.map(FileChannel.MapMode.READ_ONLY, 0, fileChannel_from.size()); + + fileChannel_to.write(buffer); + buffer.clear(); + + elapsedTime = System.nanoTime() - startTime; + System.out.println("Elapsed Time is " + (elapsedTime / 1000000000.0) + " seconds"); + } catch (IOException ex) { + System.err.println(ex); + } + + deleteCopied(copy_to); + + //Buffered Stream I/O + System.out.println("Using buffered streams and byte array ..."); + File inFileStr = copy_from.toFile(); + File outFileStr = copy_to.toFile(); + try (BufferedInputStream in = new BufferedInputStream(new FileInputStream(inFileStr)); + BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(outFileStr))) { + + startTime = System.nanoTime(); + + byte[] byteArray = new byte[bufferSize]; + int bytesCount; + while ((bytesCount = in.read(byteArray)) != -1) { + out.write(byteArray, 0, bytesCount); + } + + elapsedTime = System.nanoTime() - startTime; + System.out.println("Elapsed Time is " + (elapsedTime / 1000000000.0) + " seconds"); + } catch (IOException ex) { + System.err.println(ex); + } + + deleteCopied(copy_to); + + System.out.println("Using un-buffered streams and byte array ..."); + try (FileInputStream in = new FileInputStream(inFileStr); + FileOutputStream out = new FileOutputStream(outFileStr)) { + + startTime = System.nanoTime(); + + byte[] byteArray = new byte[bufferSize]; + int bytesCount; + while ((bytesCount = in.read(byteArray)) != -1) { + out.write(byteArray, 0, bytesCount); + } + + elapsedTime = System.nanoTime() - startTime; + System.out.println("Elapsed Time is " + (elapsedTime / 1000000000.0) + " seconds"); + } catch (IOException ex) { + System.err.println(ex); + } + + deleteCopied(copy_to); + + System.out.println("Using Files.copy (Path to Path) method ..."); + try { + startTime = System.nanoTime(); + + Files.copy(copy_from, copy_to, NOFOLLOW_LINKS); + + elapsedTime = System.nanoTime() - startTime; + System.out.println("Elapsed Time is " + (elapsedTime / 1000000000.0) + " seconds"); + } catch (IOException e) { + System.err.println(e); + } + + deleteCopied(copy_to); + + System.out.println("Using Files.copy (InputStream to Path) ..."); + try (InputStream is = new FileInputStream(copy_from.toFile())) { + + startTime = System.nanoTime(); + + Files.copy(is, copy_to); + + elapsedTime = System.nanoTime() - startTime; + System.out.println("Elapsed Time is " + (elapsedTime / 1000000000.0) + " seconds"); + } catch (IOException e) { + System.err.println(e); + } + + deleteCopied(copy_to); + + System.out.println("Using Files.copy (Path to OutputStream) ..."); + try (OutputStream os = new FileOutputStream(copy_to.toFile())) { + + startTime = System.nanoTime(); + + Files.copy(copy_from, os); + + elapsedTime = System.nanoTime() - startTime; + System.out.println("Elapsed Time is " + (elapsedTime / 1000000000.0) + " seconds"); + } catch (IOException e) { + System.err.println(e); + } + } +} diff --git a/Pro Java 7 NIO.2/Chapter07/channels/chl_08/build.xml b/Pro Java 7 NIO.2/Chapter07/channels/chl_08/build.xml new file mode 100644 index 0000000..cd3192f --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter07/channels/chl_08/build.xml @@ -0,0 +1,74 @@ + + + + + + + + + + + Builds, tests, and runs the project chl_08. + + + diff --git a/Pro Java 7 NIO.2/Chapter07/channels/chl_08/build/built-jar.properties b/Pro Java 7 NIO.2/Chapter07/channels/chl_08/build/built-jar.properties new file mode 100644 index 0000000..229e9c6 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter07/channels/chl_08/build/built-jar.properties @@ -0,0 +1,4 @@ +#Wed, 26 Oct 2011 09:28:57 +0200 + + +C\:\\NIO\\channels\\chl_08= diff --git a/Pro Java 7 NIO.2/Chapter07/channels/chl_08/build/classes/.netbeans_automatic_build b/Pro Java 7 NIO.2/Chapter07/channels/chl_08/build/classes/.netbeans_automatic_build new file mode 100644 index 0000000..e69de29 diff --git a/Pro Java 7 NIO.2/Chapter07/channels/chl_08/build/classes/chl_08/Main.class b/Pro Java 7 NIO.2/Chapter07/channels/chl_08/build/classes/chl_08/Main.class new file mode 100644 index 0000000..1ffc60e Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter07/channels/chl_08/build/classes/chl_08/Main.class differ diff --git a/Pro Java 7 NIO.2/Chapter07/channels/chl_08/dist/README.TXT b/Pro Java 7 NIO.2/Chapter07/channels/chl_08/dist/README.TXT new file mode 100644 index 0000000..28fbd3e --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter07/channels/chl_08/dist/README.TXT @@ -0,0 +1,32 @@ +======================== +BUILD OUTPUT DESCRIPTION +======================== + +When you build an Java application project that has a main class, the IDE +automatically copies all of the JAR +files on the projects classpath to your projects dist/lib folder. The IDE +also adds each of the JAR files to the Class-Path element in the application +JAR files manifest file (MANIFEST.MF). + +To run the project from the command line, go to the dist folder and +type the following: + +java -jar "chl_08.jar" + +To distribute this project, zip up the dist folder (including the lib folder) +and distribute the ZIP file. + +Notes: + +* If two JAR files on the project classpath have the same name, only the first +JAR file is copied to the lib folder. +* Only JAR files are copied to the lib folder. +If the classpath contains other types of files or folders, these files (folders) +are not copied. +* If a library on the projects classpath also has a Class-Path element +specified in the manifest,the content of the Class-Path element has to be on +the projects runtime path. +* To set a main class in a standard Java project, right-click the project node +in the Projects window and choose Properties. Then click Run and enter the +class name in the Main Class field. Alternatively, you can manually type the +class name in the manifest Main-Class element. diff --git a/Pro Java 7 NIO.2/Chapter07/channels/chl_08/dist/chl_08.jar b/Pro Java 7 NIO.2/Chapter07/channels/chl_08/dist/chl_08.jar new file mode 100644 index 0000000..4fff9a0 Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter07/channels/chl_08/dist/chl_08.jar differ diff --git a/Pro Java 7 NIO.2/Chapter07/channels/chl_08/manifest.mf b/Pro Java 7 NIO.2/Chapter07/channels/chl_08/manifest.mf new file mode 100644 index 0000000..328e8e5 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter07/channels/chl_08/manifest.mf @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +X-COMMENT: Main-Class will be added automatically by build + diff --git a/Pro Java 7 NIO.2/Chapter07/channels/chl_08/nbproject/build-impl.xml b/Pro Java 7 NIO.2/Chapter07/channels/chl_08/nbproject/build-impl.xml new file mode 100644 index 0000000..3e9224c --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter07/channels/chl_08/nbproject/build-impl.xml @@ -0,0 +1,1041 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set src.dir + Must set test.src.dir + Must set build.dir + Must set dist.dir + Must set build.classes.dir + Must set dist.javadoc.dir + Must set build.test.classes.dir + Must set build.test.results.dir + Must set build.classes.excludes + Must set dist.jar + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set JVM to use for profiling in profiler.info.jvm + Must set profiler agent JVM arguments in profiler.info.jvmargs.agent + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + + + + + + java -cp "${run.classpath.with.dist.jar}" ${main.class} + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + java -jar "${dist.jar.resolved}" + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set run.class + + + + Must select one file in the IDE or set run.class + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set debug.class + + + + + Must select one file in the IDE or set debug.class + + + + + Must set fix.includes + + + + + + + + + + + + + + + + + Must select one file in the IDE or set profile.class + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + Some tests failed; see details above. + + + + + + + + + Must select some files in the IDE or set test.includes + + + + Some tests failed; see details above. + + + + + Must select one file in the IDE or set test.class + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Pro Java 7 NIO.2/Chapter07/channels/chl_08/nbproject/genfiles.properties b/Pro Java 7 NIO.2/Chapter07/channels/chl_08/nbproject/genfiles.properties new file mode 100644 index 0000000..e571772 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter07/channels/chl_08/nbproject/genfiles.properties @@ -0,0 +1,8 @@ +build.xml.data.CRC32=2fe70d78 +build.xml.script.CRC32=f7d29217 +build.xml.stylesheet.CRC32=28e38971@1.43.1.45 +# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. +# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. +nbproject/build-impl.xml.data.CRC32=2fe70d78 +nbproject/build-impl.xml.script.CRC32=e04057e0 +nbproject/build-impl.xml.stylesheet.CRC32=0c01fd8e@1.43.1.45 diff --git a/Pro Java 7 NIO.2/Chapter07/channels/chl_08/nbproject/private/config.properties b/Pro Java 7 NIO.2/Chapter07/channels/chl_08/nbproject/private/config.properties new file mode 100644 index 0000000..e69de29 diff --git a/Pro Java 7 NIO.2/Chapter07/channels/chl_08/nbproject/private/private.properties b/Pro Java 7 NIO.2/Chapter07/channels/chl_08/nbproject/private/private.properties new file mode 100644 index 0000000..a5ab360 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter07/channels/chl_08/nbproject/private/private.properties @@ -0,0 +1,6 @@ +compile.on.save=true +do.depend=false +do.jar=true +javac.debug=true +javadoc.preview=true +user.properties.file=C:\\Users\\Leo\\.netbeans\\7.0\\build.properties diff --git a/Pro Java 7 NIO.2/Chapter07/channels/chl_08/nbproject/private/private.xml b/Pro Java 7 NIO.2/Chapter07/channels/chl_08/nbproject/private/private.xml new file mode 100644 index 0000000..c1f155a --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter07/channels/chl_08/nbproject/private/private.xml @@ -0,0 +1,4 @@ + + + + diff --git a/Pro Java 7 NIO.2/Chapter07/channels/chl_08/nbproject/project.properties b/Pro Java 7 NIO.2/Chapter07/channels/chl_08/nbproject/project.properties new file mode 100644 index 0000000..f7d9411 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter07/channels/chl_08/nbproject/project.properties @@ -0,0 +1,72 @@ +annotation.processing.enabled=true +annotation.processing.enabled.in.editor=false +annotation.processing.run.all.processors=true +annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output +application.title=chl_08 +application.vendor=Leo +build.classes.dir=${build.dir}/classes +build.classes.excludes=**/*.java,**/*.form +# This directory is removed when the project is cleaned: +build.dir=build +build.generated.dir=${build.dir}/generated +build.generated.sources.dir=${build.dir}/generated-sources +# Only compile against the classpath explicitly listed here: +build.sysclasspath=ignore +build.test.classes.dir=${build.dir}/test/classes +build.test.results.dir=${build.dir}/test/results +# Uncomment to specify the preferred debugger connection transport: +#debug.transport=dt_socket +debug.classpath=\ + ${run.classpath} +debug.test.classpath=\ + ${run.test.classpath} +# This directory is removed when the project is cleaned: +dist.dir=dist +dist.jar=${dist.dir}/chl_08.jar +dist.javadoc.dir=${dist.dir}/javadoc +endorsed.classpath= +excludes= +includes=** +jar.compress=false +javac.classpath= +# Space-separated list of extra javac options +javac.compilerargs= +javac.deprecation=false +javac.processorpath=\ + ${javac.classpath} +javac.source=1.7 +javac.target=1.7 +javac.test.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +javac.test.processorpath=\ + ${javac.test.classpath} +javadoc.additionalparam= +javadoc.author=false +javadoc.encoding=${source.encoding} +javadoc.noindex=false +javadoc.nonavbar=false +javadoc.notree=false +javadoc.private=false +javadoc.splitindex=true +javadoc.use=true +javadoc.version=false +javadoc.windowtitle= +main.class=chl_08.Main +manifest.file=manifest.mf +meta.inf.dir=${src.dir}/META-INF +mkdist.disabled=false +platform.active=default_platform +run.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +# Space-separated list of JVM arguments used when running the project +# (you may also define separate properties like run-sys-prop.name=value instead of -Dname=value +# or test-sys-prop.name=value to set system properties for unit tests): +run.jvmargs= +run.test.classpath=\ + ${javac.test.classpath}:\ + ${build.test.classes.dir} +source.encoding=UTF-8 +src.dir=src +test.src.dir=test diff --git a/Pro Java 7 NIO.2/Chapter07/channels/chl_08/nbproject/project.xml b/Pro Java 7 NIO.2/Chapter07/channels/chl_08/nbproject/project.xml new file mode 100644 index 0000000..59a1303 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter07/channels/chl_08/nbproject/project.xml @@ -0,0 +1,15 @@ + + + org.netbeans.modules.java.j2seproject + + + chl_08 + + + + + + + + + diff --git a/Pro Java 7 NIO.2/Chapter07/channels/chl_08/src/chl_08/Main.java b/Pro Java 7 NIO.2/Chapter07/channels/chl_08/src/chl_08/Main.java new file mode 100644 index 0000000..1b4af43 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter07/channels/chl_08/src/chl_08/Main.java @@ -0,0 +1,48 @@ +package chl_08; + +import java.io.IOException; +import java.nio.CharBuffer; +import java.nio.MappedByteBuffer; +import java.nio.channels.FileChannel; +import java.nio.charset.CharacterCodingException; +import java.nio.charset.Charset; +import java.nio.charset.CharsetDecoder; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.nio.file.StandardOpenOption; +import java.util.EnumSet; + +/** + * + * @author Apress + */ +public class Main { + + public static void main(String[] args) { + + Path path = Paths.get("C:/rafaelnadal/tournaments/2009", "BrasilOpen.txt"); + MappedByteBuffer buffer = null; + + try (FileChannel fileChannel = (FileChannel.open(path, EnumSet.of(StandardOpenOption.READ)))) { + + buffer = fileChannel.map(FileChannel.MapMode.READ_ONLY, 0, fileChannel.size()); + + } catch (IOException ex) { + System.err.println(ex); + } + + if (buffer != null) { + try { + Charset charset = Charset.defaultCharset(); + CharsetDecoder decoder = charset.newDecoder(); + CharBuffer charBuffer = decoder.decode(buffer); + String content = charBuffer.toString(); + System.out.println(content); + + buffer.clear(); + } catch (CharacterCodingException ex) { + System.err.println(ex); + } + } + } +} diff --git a/Pro Java 7 NIO.2/Chapter07/channels/chl_09/build.xml b/Pro Java 7 NIO.2/Chapter07/channels/chl_09/build.xml new file mode 100644 index 0000000..f57f88c --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter07/channels/chl_09/build.xml @@ -0,0 +1,74 @@ + + + + + + + + + + + Builds, tests, and runs the project chl_09. + + + diff --git a/Pro Java 7 NIO.2/Chapter07/channels/chl_09/build/built-jar.properties b/Pro Java 7 NIO.2/Chapter07/channels/chl_09/build/built-jar.properties new file mode 100644 index 0000000..7f6c97c --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter07/channels/chl_09/build/built-jar.properties @@ -0,0 +1,4 @@ +#Wed, 26 Oct 2011 09:30:33 +0200 + + +C\:\\NIO\\channels\\chl_09= diff --git a/Pro Java 7 NIO.2/Chapter07/channels/chl_09/build/classes/.netbeans_automatic_build b/Pro Java 7 NIO.2/Chapter07/channels/chl_09/build/classes/.netbeans_automatic_build new file mode 100644 index 0000000..e69de29 diff --git a/Pro Java 7 NIO.2/Chapter07/channels/chl_09/build/classes/chl_09/Main.class b/Pro Java 7 NIO.2/Chapter07/channels/chl_09/build/classes/chl_09/Main.class new file mode 100644 index 0000000..14d26a3 Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter07/channels/chl_09/build/classes/chl_09/Main.class differ diff --git a/Pro Java 7 NIO.2/Chapter07/channels/chl_09/dist/README.TXT b/Pro Java 7 NIO.2/Chapter07/channels/chl_09/dist/README.TXT new file mode 100644 index 0000000..db638bf --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter07/channels/chl_09/dist/README.TXT @@ -0,0 +1,32 @@ +======================== +BUILD OUTPUT DESCRIPTION +======================== + +When you build an Java application project that has a main class, the IDE +automatically copies all of the JAR +files on the projects classpath to your projects dist/lib folder. The IDE +also adds each of the JAR files to the Class-Path element in the application +JAR files manifest file (MANIFEST.MF). + +To run the project from the command line, go to the dist folder and +type the following: + +java -jar "chl_09.jar" + +To distribute this project, zip up the dist folder (including the lib folder) +and distribute the ZIP file. + +Notes: + +* If two JAR files on the project classpath have the same name, only the first +JAR file is copied to the lib folder. +* Only JAR files are copied to the lib folder. +If the classpath contains other types of files or folders, these files (folders) +are not copied. +* If a library on the projects classpath also has a Class-Path element +specified in the manifest,the content of the Class-Path element has to be on +the projects runtime path. +* To set a main class in a standard Java project, right-click the project node +in the Projects window and choose Properties. Then click Run and enter the +class name in the Main Class field. Alternatively, you can manually type the +class name in the manifest Main-Class element. diff --git a/Pro Java 7 NIO.2/Chapter07/channels/chl_09/dist/chl_09.jar b/Pro Java 7 NIO.2/Chapter07/channels/chl_09/dist/chl_09.jar new file mode 100644 index 0000000..88e259b Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter07/channels/chl_09/dist/chl_09.jar differ diff --git a/Pro Java 7 NIO.2/Chapter07/channels/chl_09/manifest.mf b/Pro Java 7 NIO.2/Chapter07/channels/chl_09/manifest.mf new file mode 100644 index 0000000..328e8e5 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter07/channels/chl_09/manifest.mf @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +X-COMMENT: Main-Class will be added automatically by build + diff --git a/Pro Java 7 NIO.2/Chapter07/channels/chl_09/nbproject/build-impl.xml b/Pro Java 7 NIO.2/Chapter07/channels/chl_09/nbproject/build-impl.xml new file mode 100644 index 0000000..639e893 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter07/channels/chl_09/nbproject/build-impl.xml @@ -0,0 +1,1041 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set src.dir + Must set test.src.dir + Must set build.dir + Must set dist.dir + Must set build.classes.dir + Must set dist.javadoc.dir + Must set build.test.classes.dir + Must set build.test.results.dir + Must set build.classes.excludes + Must set dist.jar + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set JVM to use for profiling in profiler.info.jvm + Must set profiler agent JVM arguments in profiler.info.jvmargs.agent + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + + + + + + java -cp "${run.classpath.with.dist.jar}" ${main.class} + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + java -jar "${dist.jar.resolved}" + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set run.class + + + + Must select one file in the IDE or set run.class + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set debug.class + + + + + Must select one file in the IDE or set debug.class + + + + + Must set fix.includes + + + + + + + + + + + + + + + + + Must select one file in the IDE or set profile.class + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + Some tests failed; see details above. + + + + + + + + + Must select some files in the IDE or set test.includes + + + + Some tests failed; see details above. + + + + + Must select one file in the IDE or set test.class + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Pro Java 7 NIO.2/Chapter07/channels/chl_09/nbproject/genfiles.properties b/Pro Java 7 NIO.2/Chapter07/channels/chl_09/nbproject/genfiles.properties new file mode 100644 index 0000000..072ecbf --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter07/channels/chl_09/nbproject/genfiles.properties @@ -0,0 +1,8 @@ +build.xml.data.CRC32=27f4815e +build.xml.script.CRC32=81aad50a +build.xml.stylesheet.CRC32=28e38971@1.43.1.45 +# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. +# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. +nbproject/build-impl.xml.data.CRC32=27f4815e +nbproject/build-impl.xml.script.CRC32=d4f371c8 +nbproject/build-impl.xml.stylesheet.CRC32=0c01fd8e@1.43.1.45 diff --git a/Pro Java 7 NIO.2/Chapter07/channels/chl_09/nbproject/private/config.properties b/Pro Java 7 NIO.2/Chapter07/channels/chl_09/nbproject/private/config.properties new file mode 100644 index 0000000..e69de29 diff --git a/Pro Java 7 NIO.2/Chapter07/channels/chl_09/nbproject/private/private.properties b/Pro Java 7 NIO.2/Chapter07/channels/chl_09/nbproject/private/private.properties new file mode 100644 index 0000000..a5ab360 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter07/channels/chl_09/nbproject/private/private.properties @@ -0,0 +1,6 @@ +compile.on.save=true +do.depend=false +do.jar=true +javac.debug=true +javadoc.preview=true +user.properties.file=C:\\Users\\Leo\\.netbeans\\7.0\\build.properties diff --git a/Pro Java 7 NIO.2/Chapter07/channels/chl_09/nbproject/private/private.xml b/Pro Java 7 NIO.2/Chapter07/channels/chl_09/nbproject/private/private.xml new file mode 100644 index 0000000..c1f155a --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter07/channels/chl_09/nbproject/private/private.xml @@ -0,0 +1,4 @@ + + + + diff --git a/Pro Java 7 NIO.2/Chapter07/channels/chl_09/nbproject/project.properties b/Pro Java 7 NIO.2/Chapter07/channels/chl_09/nbproject/project.properties new file mode 100644 index 0000000..18656f1 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter07/channels/chl_09/nbproject/project.properties @@ -0,0 +1,72 @@ +annotation.processing.enabled=true +annotation.processing.enabled.in.editor=false +annotation.processing.run.all.processors=true +annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output +application.title=chl_09 +application.vendor=Leo +build.classes.dir=${build.dir}/classes +build.classes.excludes=**/*.java,**/*.form +# This directory is removed when the project is cleaned: +build.dir=build +build.generated.dir=${build.dir}/generated +build.generated.sources.dir=${build.dir}/generated-sources +# Only compile against the classpath explicitly listed here: +build.sysclasspath=ignore +build.test.classes.dir=${build.dir}/test/classes +build.test.results.dir=${build.dir}/test/results +# Uncomment to specify the preferred debugger connection transport: +#debug.transport=dt_socket +debug.classpath=\ + ${run.classpath} +debug.test.classpath=\ + ${run.test.classpath} +# This directory is removed when the project is cleaned: +dist.dir=dist +dist.jar=${dist.dir}/chl_09.jar +dist.javadoc.dir=${dist.dir}/javadoc +endorsed.classpath= +excludes= +includes=** +jar.compress=false +javac.classpath= +# Space-separated list of extra javac options +javac.compilerargs= +javac.deprecation=false +javac.processorpath=\ + ${javac.classpath} +javac.source=1.7 +javac.target=1.7 +javac.test.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +javac.test.processorpath=\ + ${javac.test.classpath} +javadoc.additionalparam= +javadoc.author=false +javadoc.encoding=${source.encoding} +javadoc.noindex=false +javadoc.nonavbar=false +javadoc.notree=false +javadoc.private=false +javadoc.splitindex=true +javadoc.use=true +javadoc.version=false +javadoc.windowtitle= +main.class=chl_09.Main +manifest.file=manifest.mf +meta.inf.dir=${src.dir}/META-INF +mkdist.disabled=false +platform.active=default_platform +run.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +# Space-separated list of JVM arguments used when running the project +# (you may also define separate properties like run-sys-prop.name=value instead of -Dname=value +# or test-sys-prop.name=value to set system properties for unit tests): +run.jvmargs= +run.test.classpath=\ + ${javac.test.classpath}:\ + ${build.test.classes.dir} +source.encoding=UTF-8 +src.dir=src +test.src.dir=test diff --git a/Pro Java 7 NIO.2/Chapter07/channels/chl_09/nbproject/project.xml b/Pro Java 7 NIO.2/Chapter07/channels/chl_09/nbproject/project.xml new file mode 100644 index 0000000..e7bb0ff --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter07/channels/chl_09/nbproject/project.xml @@ -0,0 +1,15 @@ + + + org.netbeans.modules.java.j2seproject + + + chl_09 + + + + + + + + + diff --git a/Pro Java 7 NIO.2/Chapter07/channels/chl_09/src/chl_09/Main.java b/Pro Java 7 NIO.2/Chapter07/channels/chl_09/src/chl_09/Main.java new file mode 100644 index 0000000..f7ee9ea --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter07/channels/chl_09/src/chl_09/Main.java @@ -0,0 +1,58 @@ +package chl_09; + +import java.io.IOException; +import java.nio.ByteBuffer; +import java.nio.channels.FileChannel; +import java.nio.channels.FileLock; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.nio.file.StandardOpenOption; +import java.util.EnumSet; + +public class Main { + + public static void main(String[] args) { + Path path = Paths.get("C:/rafaelnadal/email", "vamos.txt"); + ByteBuffer buffer = ByteBuffer.wrap("Vamos Rafa!".getBytes()); + + try (FileChannel fileChannel = (FileChannel.open(path, EnumSet.of(StandardOpenOption.READ, StandardOpenOption.WRITE)))) { + + // Use the file channel to create a lock on the file. + // This method blocks until it can retrieve the lock. + FileLock lock = fileChannel.lock(); + + // Try acquiring the lock without blocking. This method returns + // null or throws an exception if the file is already locked. + //try { + // lock = fileChannel.tryLock(); + //} catch (OverlappingFileLockException e) { + // File is already locked in this thread or virtual machine + //} + + if (lock.isValid()) { + + System.out.println("Writing to a locked file ..."); + try { + Thread.sleep(60000); + } catch (InterruptedException ex) { + System.err.println(ex); + } + fileChannel.position(0); + fileChannel.write(buffer); + try { + Thread.sleep(60000); + } catch (InterruptedException ex) { + System.err.println(ex); + } + } + + // Release the lock + lock.release(); + + System.out.println("\nLock released!"); + + } catch (IOException ex) { + System.err.println(ex); + } + } +} diff --git a/Pro Java 7 NIO.2/Chapter07/channels/chl_09_testLock/build.xml b/Pro Java 7 NIO.2/Chapter07/channels/chl_09_testLock/build.xml new file mode 100644 index 0000000..5de8b9f --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter07/channels/chl_09_testLock/build.xml @@ -0,0 +1,74 @@ + + + + + + + + + + + Builds, tests, and runs the project chl_09_testLock. + + + diff --git a/Pro Java 7 NIO.2/Chapter07/channels/chl_09_testLock/build/built-jar.properties b/Pro Java 7 NIO.2/Chapter07/channels/chl_09_testLock/build/built-jar.properties new file mode 100644 index 0000000..4f5c1ac --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter07/channels/chl_09_testLock/build/built-jar.properties @@ -0,0 +1,4 @@ +#Wed, 26 Oct 2011 09:33:35 +0200 + + +C\:\\NIO\\channels\\chl_09_testLock= diff --git a/Pro Java 7 NIO.2/Chapter07/channels/chl_09_testLock/build/classes/chl_09_testlock/Main.class b/Pro Java 7 NIO.2/Chapter07/channels/chl_09_testLock/build/classes/chl_09_testlock/Main.class new file mode 100644 index 0000000..1518392 Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter07/channels/chl_09_testLock/build/classes/chl_09_testlock/Main.class differ diff --git a/Pro Java 7 NIO.2/Chapter07/channels/chl_09_testLock/dist/README.TXT b/Pro Java 7 NIO.2/Chapter07/channels/chl_09_testLock/dist/README.TXT new file mode 100644 index 0000000..03853b9 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter07/channels/chl_09_testLock/dist/README.TXT @@ -0,0 +1,32 @@ +======================== +BUILD OUTPUT DESCRIPTION +======================== + +When you build an Java application project that has a main class, the IDE +automatically copies all of the JAR +files on the projects classpath to your projects dist/lib folder. The IDE +also adds each of the JAR files to the Class-Path element in the application +JAR files manifest file (MANIFEST.MF). + +To run the project from the command line, go to the dist folder and +type the following: + +java -jar "chl_09_testLock.jar" + +To distribute this project, zip up the dist folder (including the lib folder) +and distribute the ZIP file. + +Notes: + +* If two JAR files on the project classpath have the same name, only the first +JAR file is copied to the lib folder. +* Only JAR files are copied to the lib folder. +If the classpath contains other types of files or folders, these files (folders) +are not copied. +* If a library on the projects classpath also has a Class-Path element +specified in the manifest,the content of the Class-Path element has to be on +the projects runtime path. +* To set a main class in a standard Java project, right-click the project node +in the Projects window and choose Properties. Then click Run and enter the +class name in the Main Class field. Alternatively, you can manually type the +class name in the manifest Main-Class element. diff --git a/Pro Java 7 NIO.2/Chapter07/channels/chl_09_testLock/dist/chl_09_testLock.jar b/Pro Java 7 NIO.2/Chapter07/channels/chl_09_testLock/dist/chl_09_testLock.jar new file mode 100644 index 0000000..e834dc3 Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter07/channels/chl_09_testLock/dist/chl_09_testLock.jar differ diff --git a/Pro Java 7 NIO.2/Chapter07/channels/chl_09_testLock/manifest.mf b/Pro Java 7 NIO.2/Chapter07/channels/chl_09_testLock/manifest.mf new file mode 100644 index 0000000..328e8e5 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter07/channels/chl_09_testLock/manifest.mf @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +X-COMMENT: Main-Class will be added automatically by build + diff --git a/Pro Java 7 NIO.2/Chapter07/channels/chl_09_testLock/nbproject/build-impl.xml b/Pro Java 7 NIO.2/Chapter07/channels/chl_09_testLock/nbproject/build-impl.xml new file mode 100644 index 0000000..491000a --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter07/channels/chl_09_testLock/nbproject/build-impl.xml @@ -0,0 +1,1041 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set src.dir + Must set test.src.dir + Must set build.dir + Must set dist.dir + Must set build.classes.dir + Must set dist.javadoc.dir + Must set build.test.classes.dir + Must set build.test.results.dir + Must set build.classes.excludes + Must set dist.jar + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set JVM to use for profiling in profiler.info.jvm + Must set profiler agent JVM arguments in profiler.info.jvmargs.agent + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + + + + + + java -cp "${run.classpath.with.dist.jar}" ${main.class} + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + java -jar "${dist.jar.resolved}" + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set run.class + + + + Must select one file in the IDE or set run.class + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set debug.class + + + + + Must select one file in the IDE or set debug.class + + + + + Must set fix.includes + + + + + + + + + + + + + + + + + Must select one file in the IDE or set profile.class + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + Some tests failed; see details above. + + + + + + + + + Must select some files in the IDE or set test.includes + + + + Some tests failed; see details above. + + + + + Must select one file in the IDE or set test.class + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Pro Java 7 NIO.2/Chapter07/channels/chl_09_testLock/nbproject/genfiles.properties b/Pro Java 7 NIO.2/Chapter07/channels/chl_09_testLock/nbproject/genfiles.properties new file mode 100644 index 0000000..7314dd7 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter07/channels/chl_09_testLock/nbproject/genfiles.properties @@ -0,0 +1,8 @@ +build.xml.data.CRC32=739ac4c0 +build.xml.script.CRC32=a9e863d4 +build.xml.stylesheet.CRC32=28e38971@1.43.1.45 +# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. +# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. +nbproject/build-impl.xml.data.CRC32=739ac4c0 +nbproject/build-impl.xml.script.CRC32=8ec59fcd +nbproject/build-impl.xml.stylesheet.CRC32=0c01fd8e@1.43.1.45 diff --git a/Pro Java 7 NIO.2/Chapter07/channels/chl_09_testLock/nbproject/private/config.properties b/Pro Java 7 NIO.2/Chapter07/channels/chl_09_testLock/nbproject/private/config.properties new file mode 100644 index 0000000..e69de29 diff --git a/Pro Java 7 NIO.2/Chapter07/channels/chl_09_testLock/nbproject/private/private.properties b/Pro Java 7 NIO.2/Chapter07/channels/chl_09_testLock/nbproject/private/private.properties new file mode 100644 index 0000000..a5ab360 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter07/channels/chl_09_testLock/nbproject/private/private.properties @@ -0,0 +1,6 @@ +compile.on.save=true +do.depend=false +do.jar=true +javac.debug=true +javadoc.preview=true +user.properties.file=C:\\Users\\Leo\\.netbeans\\7.0\\build.properties diff --git a/Pro Java 7 NIO.2/Chapter07/channels/chl_09_testLock/nbproject/project.properties b/Pro Java 7 NIO.2/Chapter07/channels/chl_09_testLock/nbproject/project.properties new file mode 100644 index 0000000..79868f5 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter07/channels/chl_09_testLock/nbproject/project.properties @@ -0,0 +1,72 @@ +annotation.processing.enabled=true +annotation.processing.enabled.in.editor=false +annotation.processing.run.all.processors=true +annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output +application.title=chl_09_testLock +application.vendor=Leo +build.classes.dir=${build.dir}/classes +build.classes.excludes=**/*.java,**/*.form +# This directory is removed when the project is cleaned: +build.dir=build +build.generated.dir=${build.dir}/generated +build.generated.sources.dir=${build.dir}/generated-sources +# Only compile against the classpath explicitly listed here: +build.sysclasspath=ignore +build.test.classes.dir=${build.dir}/test/classes +build.test.results.dir=${build.dir}/test/results +# Uncomment to specify the preferred debugger connection transport: +#debug.transport=dt_socket +debug.classpath=\ + ${run.classpath} +debug.test.classpath=\ + ${run.test.classpath} +# This directory is removed when the project is cleaned: +dist.dir=dist +dist.jar=${dist.dir}/chl_09_testLock.jar +dist.javadoc.dir=${dist.dir}/javadoc +endorsed.classpath= +excludes= +includes=** +jar.compress=false +javac.classpath= +# Space-separated list of extra javac options +javac.compilerargs= +javac.deprecation=false +javac.processorpath=\ + ${javac.classpath} +javac.source=1.7 +javac.target=1.7 +javac.test.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +javac.test.processorpath=\ + ${javac.test.classpath} +javadoc.additionalparam= +javadoc.author=false +javadoc.encoding=${source.encoding} +javadoc.noindex=false +javadoc.nonavbar=false +javadoc.notree=false +javadoc.private=false +javadoc.splitindex=true +javadoc.use=true +javadoc.version=false +javadoc.windowtitle= +main.class=chl_09_testlock.Main +manifest.file=manifest.mf +meta.inf.dir=${src.dir}/META-INF +mkdist.disabled=false +platform.active=default_platform +run.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +# Space-separated list of JVM arguments used when running the project +# (you may also define separate properties like run-sys-prop.name=value instead of -Dname=value +# or test-sys-prop.name=value to set system properties for unit tests): +run.jvmargs= +run.test.classpath=\ + ${javac.test.classpath}:\ + ${build.test.classes.dir} +source.encoding=UTF-8 +src.dir=src +test.src.dir=test diff --git a/Pro Java 7 NIO.2/Chapter07/channels/chl_09_testLock/nbproject/project.xml b/Pro Java 7 NIO.2/Chapter07/channels/chl_09_testLock/nbproject/project.xml new file mode 100644 index 0000000..f46c1c1 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter07/channels/chl_09_testLock/nbproject/project.xml @@ -0,0 +1,15 @@ + + + org.netbeans.modules.java.j2seproject + + + chl_09_testLock + + + + + + + + + diff --git a/Pro Java 7 NIO.2/Chapter07/channels/chl_09_testLock/src/chl_09_testlock/Main.java b/Pro Java 7 NIO.2/Chapter07/channels/chl_09_testLock/src/chl_09_testlock/Main.java new file mode 100644 index 0000000..7e62437 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter07/channels/chl_09_testLock/src/chl_09_testlock/Main.java @@ -0,0 +1,32 @@ +package chl_09_testlock; + +import java.io.IOException; +import java.nio.ByteBuffer; +import java.nio.channels.FileChannel; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.nio.file.StandardOpenOption; +import java.util.EnumSet; + +/** + * + * @author Apress + */ +public class Main { + + public static void main(String[] args) { + + Path path = Paths.get("C:/rafaelnadal/email", "vamos.txt"); + ByteBuffer buffer = ByteBuffer.wrap("Hai Hanescu !".getBytes()); + + try (FileChannel fileChannel = (FileChannel.open(path, EnumSet.of(StandardOpenOption.READ, StandardOpenOption.WRITE)))) { + + fileChannel.position(0); + fileChannel.write(buffer); + + } catch (IOException ex) { + System.err.println(ex); + } + + } +} diff --git a/Pro Java 7 NIO.2/Chapter07/channels/chl_10/build.xml b/Pro Java 7 NIO.2/Chapter07/channels/chl_10/build.xml new file mode 100644 index 0000000..fc032ae --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter07/channels/chl_10/build.xml @@ -0,0 +1,74 @@ + + + + + + + + + + + Builds, tests, and runs the project chl_10. + + + diff --git a/Pro Java 7 NIO.2/Chapter07/channels/chl_10/build/built-jar.properties b/Pro Java 7 NIO.2/Chapter07/channels/chl_10/build/built-jar.properties new file mode 100644 index 0000000..c6936c8 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter07/channels/chl_10/build/built-jar.properties @@ -0,0 +1,4 @@ +#Wed, 26 Oct 2011 08:59:09 +0200 + + +C\:\\NIO\\channels\\chl_10= diff --git a/Pro Java 7 NIO.2/Chapter07/channels/chl_10/build/classes/chl_10/Main.class b/Pro Java 7 NIO.2/Chapter07/channels/chl_10/build/classes/chl_10/Main.class new file mode 100644 index 0000000..4d2cef2 Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter07/channels/chl_10/build/classes/chl_10/Main.class differ diff --git a/Pro Java 7 NIO.2/Chapter07/channels/chl_10/dist/README.TXT b/Pro Java 7 NIO.2/Chapter07/channels/chl_10/dist/README.TXT new file mode 100644 index 0000000..0fc53ba --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter07/channels/chl_10/dist/README.TXT @@ -0,0 +1,32 @@ +======================== +BUILD OUTPUT DESCRIPTION +======================== + +When you build an Java application project that has a main class, the IDE +automatically copies all of the JAR +files on the projects classpath to your projects dist/lib folder. The IDE +also adds each of the JAR files to the Class-Path element in the application +JAR files manifest file (MANIFEST.MF). + +To run the project from the command line, go to the dist folder and +type the following: + +java -jar "chl_10.jar" + +To distribute this project, zip up the dist folder (including the lib folder) +and distribute the ZIP file. + +Notes: + +* If two JAR files on the project classpath have the same name, only the first +JAR file is copied to the lib folder. +* Only JAR files are copied to the lib folder. +If the classpath contains other types of files or folders, these files (folders) +are not copied. +* If a library on the projects classpath also has a Class-Path element +specified in the manifest,the content of the Class-Path element has to be on +the projects runtime path. +* To set a main class in a standard Java project, right-click the project node +in the Projects window and choose Properties. Then click Run and enter the +class name in the Main Class field. Alternatively, you can manually type the +class name in the manifest Main-Class element. diff --git a/Pro Java 7 NIO.2/Chapter07/channels/chl_10/dist/chl_10.jar b/Pro Java 7 NIO.2/Chapter07/channels/chl_10/dist/chl_10.jar new file mode 100644 index 0000000..60c00c4 Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter07/channels/chl_10/dist/chl_10.jar differ diff --git a/Pro Java 7 NIO.2/Chapter07/channels/chl_10/manifest.mf b/Pro Java 7 NIO.2/Chapter07/channels/chl_10/manifest.mf new file mode 100644 index 0000000..328e8e5 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter07/channels/chl_10/manifest.mf @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +X-COMMENT: Main-Class will be added automatically by build + diff --git a/Pro Java 7 NIO.2/Chapter07/channels/chl_10/nbproject/build-impl.xml b/Pro Java 7 NIO.2/Chapter07/channels/chl_10/nbproject/build-impl.xml new file mode 100644 index 0000000..34433bb --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter07/channels/chl_10/nbproject/build-impl.xml @@ -0,0 +1,1041 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set src.dir + Must set test.src.dir + Must set build.dir + Must set dist.dir + Must set build.classes.dir + Must set dist.javadoc.dir + Must set build.test.classes.dir + Must set build.test.results.dir + Must set build.classes.excludes + Must set dist.jar + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set JVM to use for profiling in profiler.info.jvm + Must set profiler agent JVM arguments in profiler.info.jvmargs.agent + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + + + + + + java -cp "${run.classpath.with.dist.jar}" ${main.class} + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + java -jar "${dist.jar.resolved}" + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set run.class + + + + Must select one file in the IDE or set run.class + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set debug.class + + + + + Must select one file in the IDE or set debug.class + + + + + Must set fix.includes + + + + + + + + + + + + + + + + + Must select one file in the IDE or set profile.class + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + Some tests failed; see details above. + + + + + + + + + Must select some files in the IDE or set test.includes + + + + Some tests failed; see details above. + + + + + Must select one file in the IDE or set test.class + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Pro Java 7 NIO.2/Chapter07/channels/chl_10/nbproject/genfiles.properties b/Pro Java 7 NIO.2/Chapter07/channels/chl_10/nbproject/genfiles.properties new file mode 100644 index 0000000..21d65ae --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter07/channels/chl_10/nbproject/genfiles.properties @@ -0,0 +1,8 @@ +build.xml.data.CRC32=bd7efa39 +build.xml.script.CRC32=9182b2e3 +build.xml.stylesheet.CRC32=28e38971@1.43.1.45 +# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. +# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. +nbproject/build-impl.xml.data.CRC32=bd7efa39 +nbproject/build-impl.xml.script.CRC32=ab297b3d +nbproject/build-impl.xml.stylesheet.CRC32=0c01fd8e@1.43.1.45 diff --git a/Pro Java 7 NIO.2/Chapter07/channels/chl_10/nbproject/private/config.properties b/Pro Java 7 NIO.2/Chapter07/channels/chl_10/nbproject/private/config.properties new file mode 100644 index 0000000..e69de29 diff --git a/Pro Java 7 NIO.2/Chapter07/channels/chl_10/nbproject/private/private.properties b/Pro Java 7 NIO.2/Chapter07/channels/chl_10/nbproject/private/private.properties new file mode 100644 index 0000000..a5ab360 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter07/channels/chl_10/nbproject/private/private.properties @@ -0,0 +1,6 @@ +compile.on.save=true +do.depend=false +do.jar=true +javac.debug=true +javadoc.preview=true +user.properties.file=C:\\Users\\Leo\\.netbeans\\7.0\\build.properties diff --git a/Pro Java 7 NIO.2/Chapter07/channels/chl_10/nbproject/private/private.xml b/Pro Java 7 NIO.2/Chapter07/channels/chl_10/nbproject/private/private.xml new file mode 100644 index 0000000..c1f155a --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter07/channels/chl_10/nbproject/private/private.xml @@ -0,0 +1,4 @@ + + + + diff --git a/Pro Java 7 NIO.2/Chapter07/channels/chl_10/nbproject/project.properties b/Pro Java 7 NIO.2/Chapter07/channels/chl_10/nbproject/project.properties new file mode 100644 index 0000000..5102c18 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter07/channels/chl_10/nbproject/project.properties @@ -0,0 +1,72 @@ +annotation.processing.enabled=true +annotation.processing.enabled.in.editor=false +annotation.processing.run.all.processors=true +annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output +application.title=chl_10 +application.vendor=Leo +build.classes.dir=${build.dir}/classes +build.classes.excludes=**/*.java,**/*.form +# This directory is removed when the project is cleaned: +build.dir=build +build.generated.dir=${build.dir}/generated +build.generated.sources.dir=${build.dir}/generated-sources +# Only compile against the classpath explicitly listed here: +build.sysclasspath=ignore +build.test.classes.dir=${build.dir}/test/classes +build.test.results.dir=${build.dir}/test/results +# Uncomment to specify the preferred debugger connection transport: +#debug.transport=dt_socket +debug.classpath=\ + ${run.classpath} +debug.test.classpath=\ + ${run.test.classpath} +# This directory is removed when the project is cleaned: +dist.dir=dist +dist.jar=${dist.dir}/chl_10.jar +dist.javadoc.dir=${dist.dir}/javadoc +endorsed.classpath= +excludes= +includes=** +jar.compress=false +javac.classpath= +# Space-separated list of extra javac options +javac.compilerargs= +javac.deprecation=false +javac.processorpath=\ + ${javac.classpath} +javac.source=1.7 +javac.target=1.7 +javac.test.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +javac.test.processorpath=\ + ${javac.test.classpath} +javadoc.additionalparam= +javadoc.author=false +javadoc.encoding=${source.encoding} +javadoc.noindex=false +javadoc.nonavbar=false +javadoc.notree=false +javadoc.private=false +javadoc.splitindex=true +javadoc.use=true +javadoc.version=false +javadoc.windowtitle= +main.class=chl_10.Main +manifest.file=manifest.mf +meta.inf.dir=${src.dir}/META-INF +mkdist.disabled=false +platform.active=default_platform +run.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +# Space-separated list of JVM arguments used when running the project +# (you may also define separate properties like run-sys-prop.name=value instead of -Dname=value +# or test-sys-prop.name=value to set system properties for unit tests): +run.jvmargs= +run.test.classpath=\ + ${javac.test.classpath}:\ + ${build.test.classes.dir} +source.encoding=UTF-8 +src.dir=src +test.src.dir=test diff --git a/Pro Java 7 NIO.2/Chapter07/channels/chl_10/nbproject/project.xml b/Pro Java 7 NIO.2/Chapter07/channels/chl_10/nbproject/project.xml new file mode 100644 index 0000000..ee2f022 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter07/channels/chl_10/nbproject/project.xml @@ -0,0 +1,15 @@ + + + org.netbeans.modules.java.j2seproject + + + chl_10 + + + + + + + + + diff --git a/Pro Java 7 NIO.2/Chapter07/channels/chl_10/src/chl_10/Main.java b/Pro Java 7 NIO.2/Chapter07/channels/chl_10/src/chl_10/Main.java new file mode 100644 index 0000000..4648813 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter07/channels/chl_10/src/chl_10/Main.java @@ -0,0 +1,58 @@ +package chl_10; + +import java.io.IOException; +import java.nio.ByteBuffer; +import java.nio.channels.SeekableByteChannel; +import java.nio.charset.Charset; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.nio.file.StandardOpenOption; +import java.util.EnumSet; + +/** + * + * @author Apress + */ +public class Main { + + public static void main(String[] args) { + + Path path = Paths.get("C:/rafaelnadal/tournaments/2009", "MovistarOpen.txt"); + ByteBuffer buffer = ByteBuffer.allocate(1); + String encoding = System.getProperty("file.encoding"); + + try (SeekableByteChannel seekableByteChannel = (Files.newByteChannel(path, EnumSet.of(StandardOpenOption.READ)))) { + + //the initial position should be 0 anyway + seekableByteChannel.position(0); + + System.out.println("Reading one character from position: " + seekableByteChannel.position()); + seekableByteChannel.read(buffer); + buffer.flip(); + System.out.print(Charset.forName(encoding).decode(buffer)); + buffer.rewind(); + + //get into the middle + seekableByteChannel.position(seekableByteChannel.size()/2); + + System.out.println("\nReading one character from position: " + seekableByteChannel.position()); + seekableByteChannel.read(buffer); + buffer.flip(); + System.out.print(Charset.forName(encoding).decode(buffer)); + buffer.rewind(); + + //get to the end + seekableByteChannel.position(seekableByteChannel.size()-1); + + System.out.println("\nReading one character from position: " + seekableByteChannel.position()); + seekableByteChannel.read(buffer); + buffer.flip(); + System.out.print(Charset.forName(encoding).decode(buffer)); + buffer.clear(); + + } catch (IOException ex) { + System.err.println(ex); + } + } +} diff --git a/Pro Java 7 NIO.2/Chapter08/sockets/mch_01/build.xml b/Pro Java 7 NIO.2/Chapter08/sockets/mch_01/build.xml new file mode 100644 index 0000000..e63e6c0 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter08/sockets/mch_01/build.xml @@ -0,0 +1,74 @@ + + + + + + + + + + + Builds, tests, and runs the project mch_01. + + + diff --git a/Pro Java 7 NIO.2/Chapter08/sockets/mch_01/build/built-jar.properties b/Pro Java 7 NIO.2/Chapter08/sockets/mch_01/build/built-jar.properties new file mode 100644 index 0000000..9a3638c --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter08/sockets/mch_01/build/built-jar.properties @@ -0,0 +1,4 @@ +#Sun, 30 Oct 2011 07:49:38 +0200 + + +C\:\\NIO\\sockets\\mch_01= diff --git a/Pro Java 7 NIO.2/Chapter08/sockets/mch_01/build/classes/mch_01/Main.class b/Pro Java 7 NIO.2/Chapter08/sockets/mch_01/build/classes/mch_01/Main.class new file mode 100644 index 0000000..02e0591 Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter08/sockets/mch_01/build/classes/mch_01/Main.class differ diff --git a/Pro Java 7 NIO.2/Chapter08/sockets/mch_01/dist/README.TXT b/Pro Java 7 NIO.2/Chapter08/sockets/mch_01/dist/README.TXT new file mode 100644 index 0000000..8b28bca --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter08/sockets/mch_01/dist/README.TXT @@ -0,0 +1,32 @@ +======================== +BUILD OUTPUT DESCRIPTION +======================== + +When you build an Java application project that has a main class, the IDE +automatically copies all of the JAR +files on the projects classpath to your projects dist/lib folder. The IDE +also adds each of the JAR files to the Class-Path element in the application +JAR files manifest file (MANIFEST.MF). + +To run the project from the command line, go to the dist folder and +type the following: + +java -jar "mch_01.jar" + +To distribute this project, zip up the dist folder (including the lib folder) +and distribute the ZIP file. + +Notes: + +* If two JAR files on the project classpath have the same name, only the first +JAR file is copied to the lib folder. +* Only JAR files are copied to the lib folder. +If the classpath contains other types of files or folders, these files (folders) +are not copied. +* If a library on the projects classpath also has a Class-Path element +specified in the manifest,the content of the Class-Path element has to be on +the projects runtime path. +* To set a main class in a standard Java project, right-click the project node +in the Projects window and choose Properties. Then click Run and enter the +class name in the Main Class field. Alternatively, you can manually type the +class name in the manifest Main-Class element. diff --git a/Pro Java 7 NIO.2/Chapter08/sockets/mch_01/dist/mch_01.jar b/Pro Java 7 NIO.2/Chapter08/sockets/mch_01/dist/mch_01.jar new file mode 100644 index 0000000..93cdccb Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter08/sockets/mch_01/dist/mch_01.jar differ diff --git a/Pro Java 7 NIO.2/Chapter08/sockets/mch_01/manifest.mf b/Pro Java 7 NIO.2/Chapter08/sockets/mch_01/manifest.mf new file mode 100644 index 0000000..328e8e5 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter08/sockets/mch_01/manifest.mf @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +X-COMMENT: Main-Class will be added automatically by build + diff --git a/Pro Java 7 NIO.2/Chapter08/sockets/mch_01/nbproject/build-impl.xml b/Pro Java 7 NIO.2/Chapter08/sockets/mch_01/nbproject/build-impl.xml new file mode 100644 index 0000000..2f8c988 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter08/sockets/mch_01/nbproject/build-impl.xml @@ -0,0 +1,1041 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set src.dir + Must set test.src.dir + Must set build.dir + Must set dist.dir + Must set build.classes.dir + Must set dist.javadoc.dir + Must set build.test.classes.dir + Must set build.test.results.dir + Must set build.classes.excludes + Must set dist.jar + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set JVM to use for profiling in profiler.info.jvm + Must set profiler agent JVM arguments in profiler.info.jvmargs.agent + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + + + + + + java -cp "${run.classpath.with.dist.jar}" ${main.class} + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + java -jar "${dist.jar.resolved}" + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set run.class + + + + Must select one file in the IDE or set run.class + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set debug.class + + + + + Must select one file in the IDE or set debug.class + + + + + Must set fix.includes + + + + + + + + + + + + + + + + + Must select one file in the IDE or set profile.class + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + Some tests failed; see details above. + + + + + + + + + Must select some files in the IDE or set test.includes + + + + Some tests failed; see details above. + + + + + Must select one file in the IDE or set test.class + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Pro Java 7 NIO.2/Chapter08/sockets/mch_01/nbproject/genfiles.properties b/Pro Java 7 NIO.2/Chapter08/sockets/mch_01/nbproject/genfiles.properties new file mode 100644 index 0000000..ebcad72 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter08/sockets/mch_01/nbproject/genfiles.properties @@ -0,0 +1,8 @@ +build.xml.data.CRC32=69e35cdd +build.xml.script.CRC32=e5ad310e +build.xml.stylesheet.CRC32=28e38971@1.43.1.45 +# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. +# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. +nbproject/build-impl.xml.data.CRC32=69e35cdd +nbproject/build-impl.xml.script.CRC32=96f81355 +nbproject/build-impl.xml.stylesheet.CRC32=0c01fd8e@1.43.1.45 diff --git a/Pro Java 7 NIO.2/Chapter08/sockets/mch_01/nbproject/private/config.properties b/Pro Java 7 NIO.2/Chapter08/sockets/mch_01/nbproject/private/config.properties new file mode 100644 index 0000000..e69de29 diff --git a/Pro Java 7 NIO.2/Chapter08/sockets/mch_01/nbproject/private/private.properties b/Pro Java 7 NIO.2/Chapter08/sockets/mch_01/nbproject/private/private.properties new file mode 100644 index 0000000..a5ab360 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter08/sockets/mch_01/nbproject/private/private.properties @@ -0,0 +1,6 @@ +compile.on.save=true +do.depend=false +do.jar=true +javac.debug=true +javadoc.preview=true +user.properties.file=C:\\Users\\Leo\\.netbeans\\7.0\\build.properties diff --git a/Pro Java 7 NIO.2/Chapter08/sockets/mch_01/nbproject/private/private.xml b/Pro Java 7 NIO.2/Chapter08/sockets/mch_01/nbproject/private/private.xml new file mode 100644 index 0000000..c1f155a --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter08/sockets/mch_01/nbproject/private/private.xml @@ -0,0 +1,4 @@ + + + + diff --git a/Pro Java 7 NIO.2/Chapter08/sockets/mch_01/nbproject/project.properties b/Pro Java 7 NIO.2/Chapter08/sockets/mch_01/nbproject/project.properties new file mode 100644 index 0000000..47b5933 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter08/sockets/mch_01/nbproject/project.properties @@ -0,0 +1,72 @@ +annotation.processing.enabled=true +annotation.processing.enabled.in.editor=false +annotation.processing.run.all.processors=true +annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output +application.title=mch_01 +application.vendor=Leo +build.classes.dir=${build.dir}/classes +build.classes.excludes=**/*.java,**/*.form +# This directory is removed when the project is cleaned: +build.dir=build +build.generated.dir=${build.dir}/generated +build.generated.sources.dir=${build.dir}/generated-sources +# Only compile against the classpath explicitly listed here: +build.sysclasspath=ignore +build.test.classes.dir=${build.dir}/test/classes +build.test.results.dir=${build.dir}/test/results +# Uncomment to specify the preferred debugger connection transport: +#debug.transport=dt_socket +debug.classpath=\ + ${run.classpath} +debug.test.classpath=\ + ${run.test.classpath} +# This directory is removed when the project is cleaned: +dist.dir=dist +dist.jar=${dist.dir}/mch_01.jar +dist.javadoc.dir=${dist.dir}/javadoc +endorsed.classpath= +excludes= +includes=** +jar.compress=false +javac.classpath= +# Space-separated list of extra javac options +javac.compilerargs= +javac.deprecation=false +javac.processorpath=\ + ${javac.classpath} +javac.source=1.7 +javac.target=1.7 +javac.test.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +javac.test.processorpath=\ + ${javac.test.classpath} +javadoc.additionalparam= +javadoc.author=false +javadoc.encoding=${source.encoding} +javadoc.noindex=false +javadoc.nonavbar=false +javadoc.notree=false +javadoc.private=false +javadoc.splitindex=true +javadoc.use=true +javadoc.version=false +javadoc.windowtitle= +main.class=mch_01.Main +manifest.file=manifest.mf +meta.inf.dir=${src.dir}/META-INF +mkdist.disabled=false +platform.active=default_platform +run.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +# Space-separated list of JVM arguments used when running the project +# (you may also define separate properties like run-sys-prop.name=value instead of -Dname=value +# or test-sys-prop.name=value to set system properties for unit tests): +run.jvmargs= +run.test.classpath=\ + ${javac.test.classpath}:\ + ${build.test.classes.dir} +source.encoding=UTF-8 +src.dir=src +test.src.dir=test diff --git a/Pro Java 7 NIO.2/Chapter08/sockets/mch_01/nbproject/project.xml b/Pro Java 7 NIO.2/Chapter08/sockets/mch_01/nbproject/project.xml new file mode 100644 index 0000000..243b345 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter08/sockets/mch_01/nbproject/project.xml @@ -0,0 +1,15 @@ + + + org.netbeans.modules.java.j2seproject + + + mch_01 + + + + + + + + + diff --git a/Pro Java 7 NIO.2/Chapter08/sockets/mch_01/src/mch_01/Main.java b/Pro Java 7 NIO.2/Chapter08/sockets/mch_01/src/mch_01/Main.java new file mode 100644 index 0000000..d01ae02 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter08/sockets/mch_01/src/mch_01/Main.java @@ -0,0 +1,30 @@ +package mch_01; + +import java.net.InetAddress; +import java.net.NetworkInterface; +import java.util.Enumeration; + +/** + * + * @author Apress + */ +public class Main { + + public static void main(String argv[]) throws Exception { + Enumeration enumInterfaces = NetworkInterface.getNetworkInterfaces(); + while (enumInterfaces.hasMoreElements()) { + NetworkInterface net = (NetworkInterface) enumInterfaces.nextElement(); + System.out.println("Network Interface Display Name: " + net.getDisplayName()); + System.out.println(net.getDisplayName() + " is up and running ?" + net.isUp()); + System.out.println(net.getDisplayName() + " Supports Multicast: " + net.supportsMulticast()); + System.out.println(net.getDisplayName() + " Name: " + net.getName()); + System.out.println(net.getDisplayName() + " Is Virtual: " + net.isVirtual()); + System.out.println("IP addresses:"); + Enumeration enumIP = net.getInetAddresses(); + while (enumIP.hasMoreElements()) { + InetAddress ip = (InetAddress) enumIP.nextElement(); + System.out.println("IP address:" + ip); + } + } + } +} diff --git a/Pro Java 7 NIO.2/Chapter08/sockets/mch_02_client/build.xml b/Pro Java 7 NIO.2/Chapter08/sockets/mch_02_client/build.xml new file mode 100644 index 0000000..d6b8189 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter08/sockets/mch_02_client/build.xml @@ -0,0 +1,74 @@ + + + + + + + + + + + Builds, tests, and runs the project mch_02_client. + + + diff --git a/Pro Java 7 NIO.2/Chapter08/sockets/mch_02_client/build/built-jar.properties b/Pro Java 7 NIO.2/Chapter08/sockets/mch_02_client/build/built-jar.properties new file mode 100644 index 0000000..fa06024 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter08/sockets/mch_02_client/build/built-jar.properties @@ -0,0 +1,4 @@ +#Sun, 30 Oct 2011 07:51:05 +0200 + + +C\:\\NIO\\sockets\\mch_02_client= diff --git a/Pro Java 7 NIO.2/Chapter08/sockets/mch_02_client/build/classes/mch_02_client/Main.class b/Pro Java 7 NIO.2/Chapter08/sockets/mch_02_client/build/classes/mch_02_client/Main.class new file mode 100644 index 0000000..afd6691 Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter08/sockets/mch_02_client/build/classes/mch_02_client/Main.class differ diff --git a/Pro Java 7 NIO.2/Chapter08/sockets/mch_02_client/dist/README.TXT b/Pro Java 7 NIO.2/Chapter08/sockets/mch_02_client/dist/README.TXT new file mode 100644 index 0000000..5dc5949 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter08/sockets/mch_02_client/dist/README.TXT @@ -0,0 +1,32 @@ +======================== +BUILD OUTPUT DESCRIPTION +======================== + +When you build an Java application project that has a main class, the IDE +automatically copies all of the JAR +files on the projects classpath to your projects dist/lib folder. The IDE +also adds each of the JAR files to the Class-Path element in the application +JAR files manifest file (MANIFEST.MF). + +To run the project from the command line, go to the dist folder and +type the following: + +java -jar "mch_02_client.jar" + +To distribute this project, zip up the dist folder (including the lib folder) +and distribute the ZIP file. + +Notes: + +* If two JAR files on the project classpath have the same name, only the first +JAR file is copied to the lib folder. +* Only JAR files are copied to the lib folder. +If the classpath contains other types of files or folders, these files (folders) +are not copied. +* If a library on the projects classpath also has a Class-Path element +specified in the manifest,the content of the Class-Path element has to be on +the projects runtime path. +* To set a main class in a standard Java project, right-click the project node +in the Projects window and choose Properties. Then click Run and enter the +class name in the Main Class field. Alternatively, you can manually type the +class name in the manifest Main-Class element. diff --git a/Pro Java 7 NIO.2/Chapter08/sockets/mch_02_client/dist/mch_02_client.jar b/Pro Java 7 NIO.2/Chapter08/sockets/mch_02_client/dist/mch_02_client.jar new file mode 100644 index 0000000..c3de5e1 Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter08/sockets/mch_02_client/dist/mch_02_client.jar differ diff --git a/Pro Java 7 NIO.2/Chapter08/sockets/mch_02_client/manifest.mf b/Pro Java 7 NIO.2/Chapter08/sockets/mch_02_client/manifest.mf new file mode 100644 index 0000000..328e8e5 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter08/sockets/mch_02_client/manifest.mf @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +X-COMMENT: Main-Class will be added automatically by build + diff --git a/Pro Java 7 NIO.2/Chapter08/sockets/mch_02_client/nbproject/build-impl.xml b/Pro Java 7 NIO.2/Chapter08/sockets/mch_02_client/nbproject/build-impl.xml new file mode 100644 index 0000000..d1a2e73 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter08/sockets/mch_02_client/nbproject/build-impl.xml @@ -0,0 +1,1041 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set src.dir + Must set test.src.dir + Must set build.dir + Must set dist.dir + Must set build.classes.dir + Must set dist.javadoc.dir + Must set build.test.classes.dir + Must set build.test.results.dir + Must set build.classes.excludes + Must set dist.jar + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set JVM to use for profiling in profiler.info.jvm + Must set profiler agent JVM arguments in profiler.info.jvmargs.agent + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + + + + + + java -cp "${run.classpath.with.dist.jar}" ${main.class} + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + java -jar "${dist.jar.resolved}" + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set run.class + + + + Must select one file in the IDE or set run.class + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set debug.class + + + + + Must select one file in the IDE or set debug.class + + + + + Must set fix.includes + + + + + + + + + + + + + + + + + Must select one file in the IDE or set profile.class + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + Some tests failed; see details above. + + + + + + + + + Must select some files in the IDE or set test.includes + + + + Some tests failed; see details above. + + + + + Must select one file in the IDE or set test.class + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Pro Java 7 NIO.2/Chapter08/sockets/mch_02_client/nbproject/genfiles.properties b/Pro Java 7 NIO.2/Chapter08/sockets/mch_02_client/nbproject/genfiles.properties new file mode 100644 index 0000000..83e9efc --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter08/sockets/mch_02_client/nbproject/genfiles.properties @@ -0,0 +1,8 @@ +build.xml.data.CRC32=7fe9a49d +build.xml.script.CRC32=a278d7e6 +build.xml.stylesheet.CRC32=28e38971@1.43.1.45 +# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. +# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. +nbproject/build-impl.xml.data.CRC32=7fe9a49d +nbproject/build-impl.xml.script.CRC32=82fe9b31 +nbproject/build-impl.xml.stylesheet.CRC32=0c01fd8e@1.43.1.45 diff --git a/Pro Java 7 NIO.2/Chapter08/sockets/mch_02_client/nbproject/private/config.properties b/Pro Java 7 NIO.2/Chapter08/sockets/mch_02_client/nbproject/private/config.properties new file mode 100644 index 0000000..e69de29 diff --git a/Pro Java 7 NIO.2/Chapter08/sockets/mch_02_client/nbproject/private/private.properties b/Pro Java 7 NIO.2/Chapter08/sockets/mch_02_client/nbproject/private/private.properties new file mode 100644 index 0000000..a5ab360 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter08/sockets/mch_02_client/nbproject/private/private.properties @@ -0,0 +1,6 @@ +compile.on.save=true +do.depend=false +do.jar=true +javac.debug=true +javadoc.preview=true +user.properties.file=C:\\Users\\Leo\\.netbeans\\7.0\\build.properties diff --git a/Pro Java 7 NIO.2/Chapter08/sockets/mch_02_client/nbproject/private/private.xml b/Pro Java 7 NIO.2/Chapter08/sockets/mch_02_client/nbproject/private/private.xml new file mode 100644 index 0000000..c1f155a --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter08/sockets/mch_02_client/nbproject/private/private.xml @@ -0,0 +1,4 @@ + + + + diff --git a/Pro Java 7 NIO.2/Chapter08/sockets/mch_02_client/nbproject/project.properties b/Pro Java 7 NIO.2/Chapter08/sockets/mch_02_client/nbproject/project.properties new file mode 100644 index 0000000..ba3c916 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter08/sockets/mch_02_client/nbproject/project.properties @@ -0,0 +1,72 @@ +annotation.processing.enabled=true +annotation.processing.enabled.in.editor=false +annotation.processing.run.all.processors=true +annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output +application.title=mch_02_client +application.vendor=Leo +build.classes.dir=${build.dir}/classes +build.classes.excludes=**/*.java,**/*.form +# This directory is removed when the project is cleaned: +build.dir=build +build.generated.dir=${build.dir}/generated +build.generated.sources.dir=${build.dir}/generated-sources +# Only compile against the classpath explicitly listed here: +build.sysclasspath=ignore +build.test.classes.dir=${build.dir}/test/classes +build.test.results.dir=${build.dir}/test/results +# Uncomment to specify the preferred debugger connection transport: +#debug.transport=dt_socket +debug.classpath=\ + ${run.classpath} +debug.test.classpath=\ + ${run.test.classpath} +# This directory is removed when the project is cleaned: +dist.dir=dist +dist.jar=${dist.dir}/mch_02_client.jar +dist.javadoc.dir=${dist.dir}/javadoc +endorsed.classpath= +excludes= +includes=** +jar.compress=false +javac.classpath= +# Space-separated list of extra javac options +javac.compilerargs= +javac.deprecation=false +javac.processorpath=\ + ${javac.classpath} +javac.source=1.7 +javac.target=1.7 +javac.test.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +javac.test.processorpath=\ + ${javac.test.classpath} +javadoc.additionalparam= +javadoc.author=false +javadoc.encoding=${source.encoding} +javadoc.noindex=false +javadoc.nonavbar=false +javadoc.notree=false +javadoc.private=false +javadoc.splitindex=true +javadoc.use=true +javadoc.version=false +javadoc.windowtitle= +main.class=mch_02_client.Main +manifest.file=manifest.mf +meta.inf.dir=${src.dir}/META-INF +mkdist.disabled=false +platform.active=default_platform +run.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +# Space-separated list of JVM arguments used when running the project +# (you may also define separate properties like run-sys-prop.name=value instead of -Dname=value +# or test-sys-prop.name=value to set system properties for unit tests): +run.jvmargs= +run.test.classpath=\ + ${javac.test.classpath}:\ + ${build.test.classes.dir} +source.encoding=UTF-8 +src.dir=src +test.src.dir=test diff --git a/Pro Java 7 NIO.2/Chapter08/sockets/mch_02_client/nbproject/project.xml b/Pro Java 7 NIO.2/Chapter08/sockets/mch_02_client/nbproject/project.xml new file mode 100644 index 0000000..f7aade0 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter08/sockets/mch_02_client/nbproject/project.xml @@ -0,0 +1,15 @@ + + + org.netbeans.modules.java.j2seproject + + + mch_02_client + + + + + + + + + diff --git a/Pro Java 7 NIO.2/Chapter08/sockets/mch_02_client/src/mch_02_client/Main.java b/Pro Java 7 NIO.2/Chapter08/sockets/mch_02_client/src/mch_02_client/Main.java new file mode 100644 index 0000000..9369755 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter08/sockets/mch_02_client/src/mch_02_client/Main.java @@ -0,0 +1,71 @@ +package mch_02_client; + +import java.io.IOException; +import java.net.InetSocketAddress; +import java.net.StandardProtocolFamily; +import java.nio.channels.DatagramChannel; +import java.net.StandardSocketOptions; +import java.nio.ByteBuffer; +import java.nio.CharBuffer; +import java.nio.channels.ClosedChannelException; +import java.nio.charset.Charset; +import java.nio.charset.CharsetDecoder; + +/** + * + * @author Apress + */ +public class Main { + + public static void main(String[] args) throws IOException { + + final int REMOTE_PORT = 5555; + final String REMOTE_IP = "127.0.0.1"; //modify this accordingly if you want to test remote + final int MAX_PACKET_SIZE = 65507; + + CharBuffer charBuffer = null; + Charset charset = Charset.defaultCharset(); + CharsetDecoder decoder = charset.newDecoder(); + ByteBuffer textToEcho = ByteBuffer.wrap("Echo this: I'm a big and ugly server!".getBytes()); + ByteBuffer echoedText = ByteBuffer.allocateDirect(MAX_PACKET_SIZE); + + //create a new datagram channel + try (DatagramChannel datagramChannel = DatagramChannel.open(StandardProtocolFamily.INET)) { + + //check if it the channel was successfully opened + if (datagramChannel.isOpen()) { + + //set some options + datagramChannel.setOption(StandardSocketOptions.SO_RCVBUF, 4 * 1024); + datagramChannel.setOption(StandardSocketOptions.SO_SNDBUF, 4 * 1024); + + //transmitting data packets + int sent = datagramChannel.send(textToEcho, new InetSocketAddress(REMOTE_IP, REMOTE_PORT)); + System.out.println("I have successfully sent " + sent + " bytes to the Echo Server!"); + + datagramChannel.receive(echoedText); +Thread.sleep(5000); + echoedText.flip(); + charBuffer = decoder.decode(echoedText); + System.out.println(charBuffer.toString()); + echoedText.clear(); + + } else { + System.out.println("The channel cannot be opened!"); + } + } catch (Exception ex) { + if (ex instanceof ClosedChannelException) { + System.err.println("The channel was unexpected closed ..."); + } + if (ex instanceof SecurityException) { + System.err.println("A security exception occured ..."); + } + if (ex instanceof IOException) { + System.err.println("An I/O error occured ..."); + } + + System.err.println("\n" + ex); + } + + } +} diff --git a/Pro Java 7 NIO.2/Chapter08/sockets/mch_02_client_rw/build.xml b/Pro Java 7 NIO.2/Chapter08/sockets/mch_02_client_rw/build.xml new file mode 100644 index 0000000..62cb388 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter08/sockets/mch_02_client_rw/build.xml @@ -0,0 +1,74 @@ + + + + + + + + + + + Builds, tests, and runs the project mch_02_client_rw. + + + diff --git a/Pro Java 7 NIO.2/Chapter08/sockets/mch_02_client_rw/build/built-jar.properties b/Pro Java 7 NIO.2/Chapter08/sockets/mch_02_client_rw/build/built-jar.properties new file mode 100644 index 0000000..b2e0713 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter08/sockets/mch_02_client_rw/build/built-jar.properties @@ -0,0 +1,4 @@ +#Sun, 30 Oct 2011 07:51:46 +0200 + + +C\:\\NIO\\sockets\\mch_02_client_rw= diff --git a/Pro Java 7 NIO.2/Chapter08/sockets/mch_02_client_rw/build/classes/mch_02_client_rw/Main.class b/Pro Java 7 NIO.2/Chapter08/sockets/mch_02_client_rw/build/classes/mch_02_client_rw/Main.class new file mode 100644 index 0000000..20e4730 Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter08/sockets/mch_02_client_rw/build/classes/mch_02_client_rw/Main.class differ diff --git a/Pro Java 7 NIO.2/Chapter08/sockets/mch_02_client_rw/dist/README.TXT b/Pro Java 7 NIO.2/Chapter08/sockets/mch_02_client_rw/dist/README.TXT new file mode 100644 index 0000000..a6ab101 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter08/sockets/mch_02_client_rw/dist/README.TXT @@ -0,0 +1,32 @@ +======================== +BUILD OUTPUT DESCRIPTION +======================== + +When you build an Java application project that has a main class, the IDE +automatically copies all of the JAR +files on the projects classpath to your projects dist/lib folder. The IDE +also adds each of the JAR files to the Class-Path element in the application +JAR files manifest file (MANIFEST.MF). + +To run the project from the command line, go to the dist folder and +type the following: + +java -jar "mch_02_client_rw.jar" + +To distribute this project, zip up the dist folder (including the lib folder) +and distribute the ZIP file. + +Notes: + +* If two JAR files on the project classpath have the same name, only the first +JAR file is copied to the lib folder. +* Only JAR files are copied to the lib folder. +If the classpath contains other types of files or folders, these files (folders) +are not copied. +* If a library on the projects classpath also has a Class-Path element +specified in the manifest,the content of the Class-Path element has to be on +the projects runtime path. +* To set a main class in a standard Java project, right-click the project node +in the Projects window and choose Properties. Then click Run and enter the +class name in the Main Class field. Alternatively, you can manually type the +class name in the manifest Main-Class element. diff --git a/Pro Java 7 NIO.2/Chapter08/sockets/mch_02_client_rw/dist/mch_02_client_rw.jar b/Pro Java 7 NIO.2/Chapter08/sockets/mch_02_client_rw/dist/mch_02_client_rw.jar new file mode 100644 index 0000000..68bbcf5 Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter08/sockets/mch_02_client_rw/dist/mch_02_client_rw.jar differ diff --git a/Pro Java 7 NIO.2/Chapter08/sockets/mch_02_client_rw/manifest.mf b/Pro Java 7 NIO.2/Chapter08/sockets/mch_02_client_rw/manifest.mf new file mode 100644 index 0000000..328e8e5 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter08/sockets/mch_02_client_rw/manifest.mf @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +X-COMMENT: Main-Class will be added automatically by build + diff --git a/Pro Java 7 NIO.2/Chapter08/sockets/mch_02_client_rw/nbproject/build-impl.xml b/Pro Java 7 NIO.2/Chapter08/sockets/mch_02_client_rw/nbproject/build-impl.xml new file mode 100644 index 0000000..7cf1a60 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter08/sockets/mch_02_client_rw/nbproject/build-impl.xml @@ -0,0 +1,1041 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set src.dir + Must set test.src.dir + Must set build.dir + Must set dist.dir + Must set build.classes.dir + Must set dist.javadoc.dir + Must set build.test.classes.dir + Must set build.test.results.dir + Must set build.classes.excludes + Must set dist.jar + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set JVM to use for profiling in profiler.info.jvm + Must set profiler agent JVM arguments in profiler.info.jvmargs.agent + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + + + + + + java -cp "${run.classpath.with.dist.jar}" ${main.class} + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + java -jar "${dist.jar.resolved}" + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set run.class + + + + Must select one file in the IDE or set run.class + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set debug.class + + + + + Must select one file in the IDE or set debug.class + + + + + Must set fix.includes + + + + + + + + + + + + + + + + + Must select one file in the IDE or set profile.class + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + Some tests failed; see details above. + + + + + + + + + Must select some files in the IDE or set test.includes + + + + Some tests failed; see details above. + + + + + Must select one file in the IDE or set test.class + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Pro Java 7 NIO.2/Chapter08/sockets/mch_02_client_rw/nbproject/genfiles.properties b/Pro Java 7 NIO.2/Chapter08/sockets/mch_02_client_rw/nbproject/genfiles.properties new file mode 100644 index 0000000..20fba1b --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter08/sockets/mch_02_client_rw/nbproject/genfiles.properties @@ -0,0 +1,8 @@ +build.xml.data.CRC32=b94bf027 +build.xml.script.CRC32=02d5876b +build.xml.stylesheet.CRC32=28e38971@1.43.1.45 +# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. +# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. +nbproject/build-impl.xml.data.CRC32=b94bf027 +nbproject/build-impl.xml.script.CRC32=db298ff9 +nbproject/build-impl.xml.stylesheet.CRC32=0c01fd8e@1.43.1.45 diff --git a/Pro Java 7 NIO.2/Chapter08/sockets/mch_02_client_rw/nbproject/private/config.properties b/Pro Java 7 NIO.2/Chapter08/sockets/mch_02_client_rw/nbproject/private/config.properties new file mode 100644 index 0000000..e69de29 diff --git a/Pro Java 7 NIO.2/Chapter08/sockets/mch_02_client_rw/nbproject/private/private.properties b/Pro Java 7 NIO.2/Chapter08/sockets/mch_02_client_rw/nbproject/private/private.properties new file mode 100644 index 0000000..a5ab360 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter08/sockets/mch_02_client_rw/nbproject/private/private.properties @@ -0,0 +1,6 @@ +compile.on.save=true +do.depend=false +do.jar=true +javac.debug=true +javadoc.preview=true +user.properties.file=C:\\Users\\Leo\\.netbeans\\7.0\\build.properties diff --git a/Pro Java 7 NIO.2/Chapter08/sockets/mch_02_client_rw/nbproject/private/private.xml b/Pro Java 7 NIO.2/Chapter08/sockets/mch_02_client_rw/nbproject/private/private.xml new file mode 100644 index 0000000..c1f155a --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter08/sockets/mch_02_client_rw/nbproject/private/private.xml @@ -0,0 +1,4 @@ + + + + diff --git a/Pro Java 7 NIO.2/Chapter08/sockets/mch_02_client_rw/nbproject/project.properties b/Pro Java 7 NIO.2/Chapter08/sockets/mch_02_client_rw/nbproject/project.properties new file mode 100644 index 0000000..a176651 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter08/sockets/mch_02_client_rw/nbproject/project.properties @@ -0,0 +1,72 @@ +annotation.processing.enabled=true +annotation.processing.enabled.in.editor=false +annotation.processing.run.all.processors=true +annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output +application.title=mch_02_client_rw +application.vendor=Leo +build.classes.dir=${build.dir}/classes +build.classes.excludes=**/*.java,**/*.form +# This directory is removed when the project is cleaned: +build.dir=build +build.generated.dir=${build.dir}/generated +build.generated.sources.dir=${build.dir}/generated-sources +# Only compile against the classpath explicitly listed here: +build.sysclasspath=ignore +build.test.classes.dir=${build.dir}/test/classes +build.test.results.dir=${build.dir}/test/results +# Uncomment to specify the preferred debugger connection transport: +#debug.transport=dt_socket +debug.classpath=\ + ${run.classpath} +debug.test.classpath=\ + ${run.test.classpath} +# This directory is removed when the project is cleaned: +dist.dir=dist +dist.jar=${dist.dir}/mch_02_client_rw.jar +dist.javadoc.dir=${dist.dir}/javadoc +endorsed.classpath= +excludes= +includes=** +jar.compress=false +javac.classpath= +# Space-separated list of extra javac options +javac.compilerargs= +javac.deprecation=false +javac.processorpath=\ + ${javac.classpath} +javac.source=1.7 +javac.target=1.7 +javac.test.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +javac.test.processorpath=\ + ${javac.test.classpath} +javadoc.additionalparam= +javadoc.author=false +javadoc.encoding=${source.encoding} +javadoc.noindex=false +javadoc.nonavbar=false +javadoc.notree=false +javadoc.private=false +javadoc.splitindex=true +javadoc.use=true +javadoc.version=false +javadoc.windowtitle= +main.class=mch_02_client_rw.Main +manifest.file=manifest.mf +meta.inf.dir=${src.dir}/META-INF +mkdist.disabled=false +platform.active=default_platform +run.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +# Space-separated list of JVM arguments used when running the project +# (you may also define separate properties like run-sys-prop.name=value instead of -Dname=value +# or test-sys-prop.name=value to set system properties for unit tests): +run.jvmargs= +run.test.classpath=\ + ${javac.test.classpath}:\ + ${build.test.classes.dir} +source.encoding=UTF-8 +src.dir=src +test.src.dir=test diff --git a/Pro Java 7 NIO.2/Chapter08/sockets/mch_02_client_rw/nbproject/project.xml b/Pro Java 7 NIO.2/Chapter08/sockets/mch_02_client_rw/nbproject/project.xml new file mode 100644 index 0000000..dbdf062 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter08/sockets/mch_02_client_rw/nbproject/project.xml @@ -0,0 +1,15 @@ + + + org.netbeans.modules.java.j2seproject + + + mch_02_client_rw + + + + + + + + + diff --git a/Pro Java 7 NIO.2/Chapter08/sockets/mch_02_client_rw/src/mch_02_client_rw/Main.java b/Pro Java 7 NIO.2/Chapter08/sockets/mch_02_client_rw/src/mch_02_client_rw/Main.java new file mode 100644 index 0000000..1cc8380 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter08/sockets/mch_02_client_rw/src/mch_02_client_rw/Main.java @@ -0,0 +1,80 @@ +package mch_02_client_rw; + +import java.io.IOException; +import java.net.InetSocketAddress; +import java.net.StandardProtocolFamily; +import java.nio.channels.DatagramChannel; +import java.net.StandardSocketOptions; +import java.nio.ByteBuffer; +import java.nio.CharBuffer; +import java.nio.channels.ClosedChannelException; +import java.nio.charset.Charset; +import java.nio.charset.CharsetDecoder; + +/** + * + * @author Apress + */ +public class Main { + + public static void main(String[] args) throws IOException { + + final int REMOTE_PORT = 5555; + final String REMOTE_IP = "127.0.0.1"; //modify this accordingly if you want to test remote + final int MAX_PACKET_SIZE = 65507; + + CharBuffer charBuffer = null; + Charset charset = Charset.defaultCharset(); + CharsetDecoder decoder = charset.newDecoder(); + ByteBuffer textToEcho = ByteBuffer.wrap("Echo this: I'm a big and ugly server!".getBytes()); + ByteBuffer echoedText = ByteBuffer.allocateDirect(MAX_PACKET_SIZE); + + //create a new datagram channel + try (DatagramChannel datagramChannel = DatagramChannel.open(StandardProtocolFamily.INET)) { + + //set some options + datagramChannel.setOption(StandardSocketOptions.SO_RCVBUF, 4 * 1024); + datagramChannel.setOption(StandardSocketOptions.SO_SNDBUF, 4 * 1024); + + //check if it the channel was successfully opened + if (datagramChannel.isOpen()) { + + //connect to remote address + datagramChannel.connect(new InetSocketAddress(REMOTE_IP, REMOTE_PORT)); + + //check if it the channel was successfully connected + if (datagramChannel.isConnected()) { + + //transmitting data packets + int sent = datagramChannel.write(textToEcho); + System.out.println("I have successfully sent " + sent + " bytes to the Echo Server!"); + + datagramChannel.read(echoedText); + + echoedText.flip(); + charBuffer = decoder.decode(echoedText); + System.out.println(charBuffer.toString()); + echoedText.clear(); + + } else { + System.out.println("The channel cannot be connected!"); + } + } else { + System.out.println("The channel cannot be opened!"); + } + } catch (Exception ex) { + if (ex instanceof ClosedChannelException) { + System.err.println("The channel was unexpected closed ..."); + } + if (ex instanceof SecurityException) { + System.err.println("A security exception occured ..."); + } + if (ex instanceof IOException) { + System.err.println("An I/O error occured ..."); + } + + System.err.println("\n" + ex); + } + + } +} diff --git a/Pro Java 7 NIO.2/Chapter08/sockets/mch_02_server/build.xml b/Pro Java 7 NIO.2/Chapter08/sockets/mch_02_server/build.xml new file mode 100644 index 0000000..5234ee3 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter08/sockets/mch_02_server/build.xml @@ -0,0 +1,74 @@ + + + + + + + + + + + Builds, tests, and runs the project mch_02_server. + + + diff --git a/Pro Java 7 NIO.2/Chapter08/sockets/mch_02_server/build/built-jar.properties b/Pro Java 7 NIO.2/Chapter08/sockets/mch_02_server/build/built-jar.properties new file mode 100644 index 0000000..98ae3a1 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter08/sockets/mch_02_server/build/built-jar.properties @@ -0,0 +1,4 @@ +#Sun, 30 Oct 2011 07:50:20 +0200 + + +C\:\\NIO\\sockets\\mch_02_server= diff --git a/Pro Java 7 NIO.2/Chapter08/sockets/mch_02_server/build/classes/.netbeans_automatic_build b/Pro Java 7 NIO.2/Chapter08/sockets/mch_02_server/build/classes/.netbeans_automatic_build new file mode 100644 index 0000000..e69de29 diff --git a/Pro Java 7 NIO.2/Chapter08/sockets/mch_02_server/build/classes/mch_02_server/Main.class b/Pro Java 7 NIO.2/Chapter08/sockets/mch_02_server/build/classes/mch_02_server/Main.class new file mode 100644 index 0000000..e5ec8f0 Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter08/sockets/mch_02_server/build/classes/mch_02_server/Main.class differ diff --git a/Pro Java 7 NIO.2/Chapter08/sockets/mch_02_server/dist/README.TXT b/Pro Java 7 NIO.2/Chapter08/sockets/mch_02_server/dist/README.TXT new file mode 100644 index 0000000..358c3e4 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter08/sockets/mch_02_server/dist/README.TXT @@ -0,0 +1,32 @@ +======================== +BUILD OUTPUT DESCRIPTION +======================== + +When you build an Java application project that has a main class, the IDE +automatically copies all of the JAR +files on the projects classpath to your projects dist/lib folder. The IDE +also adds each of the JAR files to the Class-Path element in the application +JAR files manifest file (MANIFEST.MF). + +To run the project from the command line, go to the dist folder and +type the following: + +java -jar "mch_02_server.jar" + +To distribute this project, zip up the dist folder (including the lib folder) +and distribute the ZIP file. + +Notes: + +* If two JAR files on the project classpath have the same name, only the first +JAR file is copied to the lib folder. +* Only JAR files are copied to the lib folder. +If the classpath contains other types of files or folders, these files (folders) +are not copied. +* If a library on the projects classpath also has a Class-Path element +specified in the manifest,the content of the Class-Path element has to be on +the projects runtime path. +* To set a main class in a standard Java project, right-click the project node +in the Projects window and choose Properties. Then click Run and enter the +class name in the Main Class field. Alternatively, you can manually type the +class name in the manifest Main-Class element. diff --git a/Pro Java 7 NIO.2/Chapter08/sockets/mch_02_server/dist/mch_02_server.jar b/Pro Java 7 NIO.2/Chapter08/sockets/mch_02_server/dist/mch_02_server.jar new file mode 100644 index 0000000..ab2db94 Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter08/sockets/mch_02_server/dist/mch_02_server.jar differ diff --git a/Pro Java 7 NIO.2/Chapter08/sockets/mch_02_server/manifest.mf b/Pro Java 7 NIO.2/Chapter08/sockets/mch_02_server/manifest.mf new file mode 100644 index 0000000..328e8e5 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter08/sockets/mch_02_server/manifest.mf @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +X-COMMENT: Main-Class will be added automatically by build + diff --git a/Pro Java 7 NIO.2/Chapter08/sockets/mch_02_server/nbproject/build-impl.xml b/Pro Java 7 NIO.2/Chapter08/sockets/mch_02_server/nbproject/build-impl.xml new file mode 100644 index 0000000..a19c32c --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter08/sockets/mch_02_server/nbproject/build-impl.xml @@ -0,0 +1,1041 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set src.dir + Must set test.src.dir + Must set build.dir + Must set dist.dir + Must set build.classes.dir + Must set dist.javadoc.dir + Must set build.test.classes.dir + Must set build.test.results.dir + Must set build.classes.excludes + Must set dist.jar + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set JVM to use for profiling in profiler.info.jvm + Must set profiler agent JVM arguments in profiler.info.jvmargs.agent + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + + + + + + java -cp "${run.classpath.with.dist.jar}" ${main.class} + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + java -jar "${dist.jar.resolved}" + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set run.class + + + + Must select one file in the IDE or set run.class + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set debug.class + + + + + Must select one file in the IDE or set debug.class + + + + + Must set fix.includes + + + + + + + + + + + + + + + + + Must select one file in the IDE or set profile.class + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + Some tests failed; see details above. + + + + + + + + + Must select some files in the IDE or set test.includes + + + + Some tests failed; see details above. + + + + + Must select one file in the IDE or set test.class + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Pro Java 7 NIO.2/Chapter08/sockets/mch_02_server/nbproject/genfiles.properties b/Pro Java 7 NIO.2/Chapter08/sockets/mch_02_server/nbproject/genfiles.properties new file mode 100644 index 0000000..cb8b216 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter08/sockets/mch_02_server/nbproject/genfiles.properties @@ -0,0 +1,8 @@ +build.xml.data.CRC32=a8b7008a +build.xml.script.CRC32=fd03aadf +build.xml.stylesheet.CRC32=28e38971@1.43.1.45 +# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. +# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. +nbproject/build-impl.xml.data.CRC32=a8b7008a +nbproject/build-impl.xml.script.CRC32=4a297a32 +nbproject/build-impl.xml.stylesheet.CRC32=0c01fd8e@1.43.1.45 diff --git a/Pro Java 7 NIO.2/Chapter08/sockets/mch_02_server/nbproject/private/config.properties b/Pro Java 7 NIO.2/Chapter08/sockets/mch_02_server/nbproject/private/config.properties new file mode 100644 index 0000000..e69de29 diff --git a/Pro Java 7 NIO.2/Chapter08/sockets/mch_02_server/nbproject/private/private.properties b/Pro Java 7 NIO.2/Chapter08/sockets/mch_02_server/nbproject/private/private.properties new file mode 100644 index 0000000..a5ab360 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter08/sockets/mch_02_server/nbproject/private/private.properties @@ -0,0 +1,6 @@ +compile.on.save=true +do.depend=false +do.jar=true +javac.debug=true +javadoc.preview=true +user.properties.file=C:\\Users\\Leo\\.netbeans\\7.0\\build.properties diff --git a/Pro Java 7 NIO.2/Chapter08/sockets/mch_02_server/nbproject/private/private.xml b/Pro Java 7 NIO.2/Chapter08/sockets/mch_02_server/nbproject/private/private.xml new file mode 100644 index 0000000..c1f155a --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter08/sockets/mch_02_server/nbproject/private/private.xml @@ -0,0 +1,4 @@ + + + + diff --git a/Pro Java 7 NIO.2/Chapter08/sockets/mch_02_server/nbproject/project.properties b/Pro Java 7 NIO.2/Chapter08/sockets/mch_02_server/nbproject/project.properties new file mode 100644 index 0000000..7604f54 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter08/sockets/mch_02_server/nbproject/project.properties @@ -0,0 +1,72 @@ +annotation.processing.enabled=true +annotation.processing.enabled.in.editor=false +annotation.processing.run.all.processors=true +annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output +application.title=mch_02_server +application.vendor=Leo +build.classes.dir=${build.dir}/classes +build.classes.excludes=**/*.java,**/*.form +# This directory is removed when the project is cleaned: +build.dir=build +build.generated.dir=${build.dir}/generated +build.generated.sources.dir=${build.dir}/generated-sources +# Only compile against the classpath explicitly listed here: +build.sysclasspath=ignore +build.test.classes.dir=${build.dir}/test/classes +build.test.results.dir=${build.dir}/test/results +# Uncomment to specify the preferred debugger connection transport: +#debug.transport=dt_socket +debug.classpath=\ + ${run.classpath} +debug.test.classpath=\ + ${run.test.classpath} +# This directory is removed when the project is cleaned: +dist.dir=dist +dist.jar=${dist.dir}/mch_02_server.jar +dist.javadoc.dir=${dist.dir}/javadoc +endorsed.classpath= +excludes= +includes=** +jar.compress=false +javac.classpath= +# Space-separated list of extra javac options +javac.compilerargs= +javac.deprecation=false +javac.processorpath=\ + ${javac.classpath} +javac.source=1.7 +javac.target=1.7 +javac.test.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +javac.test.processorpath=\ + ${javac.test.classpath} +javadoc.additionalparam= +javadoc.author=false +javadoc.encoding=${source.encoding} +javadoc.noindex=false +javadoc.nonavbar=false +javadoc.notree=false +javadoc.private=false +javadoc.splitindex=true +javadoc.use=true +javadoc.version=false +javadoc.windowtitle= +main.class=mch_02_server.Main +manifest.file=manifest.mf +meta.inf.dir=${src.dir}/META-INF +mkdist.disabled=false +platform.active=default_platform +run.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +# Space-separated list of JVM arguments used when running the project +# (you may also define separate properties like run-sys-prop.name=value instead of -Dname=value +# or test-sys-prop.name=value to set system properties for unit tests): +run.jvmargs= +run.test.classpath=\ + ${javac.test.classpath}:\ + ${build.test.classes.dir} +source.encoding=UTF-8 +src.dir=src +test.src.dir=test diff --git a/Pro Java 7 NIO.2/Chapter08/sockets/mch_02_server/nbproject/project.xml b/Pro Java 7 NIO.2/Chapter08/sockets/mch_02_server/nbproject/project.xml new file mode 100644 index 0000000..190894a --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter08/sockets/mch_02_server/nbproject/project.xml @@ -0,0 +1,15 @@ + + + org.netbeans.modules.java.j2seproject + + + mch_02_server + + + + + + + + + diff --git a/Pro Java 7 NIO.2/Chapter08/sockets/mch_02_server/src/mch_02_server/Main.java b/Pro Java 7 NIO.2/Chapter08/sockets/mch_02_server/src/mch_02_server/Main.java new file mode 100644 index 0000000..4ead35a --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter08/sockets/mch_02_server/src/mch_02_server/Main.java @@ -0,0 +1,67 @@ +package mch_02_server; + +import java.io.IOException; +import java.net.InetSocketAddress; +import java.net.SocketAddress; +import java.net.StandardProtocolFamily; +import java.nio.channels.DatagramChannel; +import java.net.StandardSocketOptions; +import java.nio.ByteBuffer; +import java.nio.channels.ClosedChannelException; + +/** + * + * @author Apress + */ +public class Main { + + public static void main(String[] args) { + final int LOCAL_PORT = 5555; + final String LOCAL_IP = "127.0.0.1"; //modify this to your local IP + final int MAX_PACKET_SIZE = 65507; + + ByteBuffer echoText = ByteBuffer.allocateDirect(MAX_PACKET_SIZE); + + //create a new datagram channel + try (DatagramChannel datagramChannel = DatagramChannel.open(StandardProtocolFamily.INET)) { + + //check if it the channel was successfully opened + if (datagramChannel.isOpen()) { + + System.out.println("Echo server was successfully opened!"); + //set some options + datagramChannel.setOption(StandardSocketOptions.SO_RCVBUF, 4 * 1024); + datagramChannel.setOption(StandardSocketOptions.SO_SNDBUF, 4 * 1024); + //bind the channel to local address + datagramChannel.bind(new InetSocketAddress(LOCAL_IP, LOCAL_PORT)); + System.out.println("Echo server was binded on: " + datagramChannel.getLocalAddress()); + System.out.println("Echo server is ready to echo ..."); + + //transmitting data packets + while (true) { + + SocketAddress clientAddress = datagramChannel.receive(echoText); + + echoText.flip(); + System.out.println("I have received " + echoText.limit() + " bytes from " + clientAddress.toString() + "! Sending them back ..."); + datagramChannel.send(echoText, clientAddress); + echoText.clear(); + } + } else { + System.out.println("The channel cannot be opened!"); + } + } catch (Exception ex) { + if (ex instanceof ClosedChannelException) { + System.err.println("The channel was unexpected closed ..."); + } + if (ex instanceof SecurityException) { + System.err.println("A security exception occured ..."); + } + if (ex instanceof IOException) { + System.err.println("An I/O error occured ..."); + } + + System.err.println("\n" + ex); + } + } +} diff --git a/Pro Java 7 NIO.2/Chapter08/sockets/mch_03_multicast_client/build.xml b/Pro Java 7 NIO.2/Chapter08/sockets/mch_03_multicast_client/build.xml new file mode 100644 index 0000000..d679ccd --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter08/sockets/mch_03_multicast_client/build.xml @@ -0,0 +1,74 @@ + + + + + + + + + + + Builds, tests, and runs the project mch_03_multicast_client. + + + diff --git a/Pro Java 7 NIO.2/Chapter08/sockets/mch_03_multicast_client/build/built-jar.properties b/Pro Java 7 NIO.2/Chapter08/sockets/mch_03_multicast_client/build/built-jar.properties new file mode 100644 index 0000000..7a662a6 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter08/sockets/mch_03_multicast_client/build/built-jar.properties @@ -0,0 +1,4 @@ +#Sun, 30 Oct 2011 07:52:36 +0200 + + +C\:\\NIO\\sockets\\mch_03_multicast_client= diff --git a/Pro Java 7 NIO.2/Chapter08/sockets/mch_03_multicast_client/build/classes/.netbeans_automatic_build b/Pro Java 7 NIO.2/Chapter08/sockets/mch_03_multicast_client/build/classes/.netbeans_automatic_build new file mode 100644 index 0000000..e69de29 diff --git a/Pro Java 7 NIO.2/Chapter08/sockets/mch_03_multicast_client/build/classes/mch_03_multicast_client/Main.class b/Pro Java 7 NIO.2/Chapter08/sockets/mch_03_multicast_client/build/classes/mch_03_multicast_client/Main.class new file mode 100644 index 0000000..e0d3d20 Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter08/sockets/mch_03_multicast_client/build/classes/mch_03_multicast_client/Main.class differ diff --git a/Pro Java 7 NIO.2/Chapter08/sockets/mch_03_multicast_client/dist/README.TXT b/Pro Java 7 NIO.2/Chapter08/sockets/mch_03_multicast_client/dist/README.TXT new file mode 100644 index 0000000..9a2b16b --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter08/sockets/mch_03_multicast_client/dist/README.TXT @@ -0,0 +1,32 @@ +======================== +BUILD OUTPUT DESCRIPTION +======================== + +When you build an Java application project that has a main class, the IDE +automatically copies all of the JAR +files on the projects classpath to your projects dist/lib folder. The IDE +also adds each of the JAR files to the Class-Path element in the application +JAR files manifest file (MANIFEST.MF). + +To run the project from the command line, go to the dist folder and +type the following: + +java -jar "mch_03_multicast_client.jar" + +To distribute this project, zip up the dist folder (including the lib folder) +and distribute the ZIP file. + +Notes: + +* If two JAR files on the project classpath have the same name, only the first +JAR file is copied to the lib folder. +* Only JAR files are copied to the lib folder. +If the classpath contains other types of files or folders, these files (folders) +are not copied. +* If a library on the projects classpath also has a Class-Path element +specified in the manifest,the content of the Class-Path element has to be on +the projects runtime path. +* To set a main class in a standard Java project, right-click the project node +in the Projects window and choose Properties. Then click Run and enter the +class name in the Main Class field. Alternatively, you can manually type the +class name in the manifest Main-Class element. diff --git a/Pro Java 7 NIO.2/Chapter08/sockets/mch_03_multicast_client/dist/mch_03_multicast_client.jar b/Pro Java 7 NIO.2/Chapter08/sockets/mch_03_multicast_client/dist/mch_03_multicast_client.jar new file mode 100644 index 0000000..15b860e Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter08/sockets/mch_03_multicast_client/dist/mch_03_multicast_client.jar differ diff --git a/Pro Java 7 NIO.2/Chapter08/sockets/mch_03_multicast_client/manifest.mf b/Pro Java 7 NIO.2/Chapter08/sockets/mch_03_multicast_client/manifest.mf new file mode 100644 index 0000000..328e8e5 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter08/sockets/mch_03_multicast_client/manifest.mf @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +X-COMMENT: Main-Class will be added automatically by build + diff --git a/Pro Java 7 NIO.2/Chapter08/sockets/mch_03_multicast_client/nbproject/build-impl.xml b/Pro Java 7 NIO.2/Chapter08/sockets/mch_03_multicast_client/nbproject/build-impl.xml new file mode 100644 index 0000000..0c86de3 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter08/sockets/mch_03_multicast_client/nbproject/build-impl.xml @@ -0,0 +1,1041 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set src.dir + Must set test.src.dir + Must set build.dir + Must set dist.dir + Must set build.classes.dir + Must set dist.javadoc.dir + Must set build.test.classes.dir + Must set build.test.results.dir + Must set build.classes.excludes + Must set dist.jar + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set JVM to use for profiling in profiler.info.jvm + Must set profiler agent JVM arguments in profiler.info.jvmargs.agent + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + + + + + + java -cp "${run.classpath.with.dist.jar}" ${main.class} + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + java -jar "${dist.jar.resolved}" + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set run.class + + + + Must select one file in the IDE or set run.class + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set debug.class + + + + + Must select one file in the IDE or set debug.class + + + + + Must set fix.includes + + + + + + + + + + + + + + + + + Must select one file in the IDE or set profile.class + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + Some tests failed; see details above. + + + + + + + + + Must select some files in the IDE or set test.includes + + + + Some tests failed; see details above. + + + + + Must select one file in the IDE or set test.class + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Pro Java 7 NIO.2/Chapter08/sockets/mch_03_multicast_client/nbproject/genfiles.properties b/Pro Java 7 NIO.2/Chapter08/sockets/mch_03_multicast_client/nbproject/genfiles.properties new file mode 100644 index 0000000..b60eafc --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter08/sockets/mch_03_multicast_client/nbproject/genfiles.properties @@ -0,0 +1,8 @@ +build.xml.data.CRC32=f0f5daa7 +build.xml.script.CRC32=2249476e +build.xml.stylesheet.CRC32=28e38971@1.43.1.45 +# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. +# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. +nbproject/build-impl.xml.data.CRC32=f0f5daa7 +nbproject/build-impl.xml.script.CRC32=1c87235a +nbproject/build-impl.xml.stylesheet.CRC32=0c01fd8e@1.43.1.45 diff --git a/Pro Java 7 NIO.2/Chapter08/sockets/mch_03_multicast_client/nbproject/private/config.properties b/Pro Java 7 NIO.2/Chapter08/sockets/mch_03_multicast_client/nbproject/private/config.properties new file mode 100644 index 0000000..e69de29 diff --git a/Pro Java 7 NIO.2/Chapter08/sockets/mch_03_multicast_client/nbproject/private/private.properties b/Pro Java 7 NIO.2/Chapter08/sockets/mch_03_multicast_client/nbproject/private/private.properties new file mode 100644 index 0000000..a5ab360 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter08/sockets/mch_03_multicast_client/nbproject/private/private.properties @@ -0,0 +1,6 @@ +compile.on.save=true +do.depend=false +do.jar=true +javac.debug=true +javadoc.preview=true +user.properties.file=C:\\Users\\Leo\\.netbeans\\7.0\\build.properties diff --git a/Pro Java 7 NIO.2/Chapter08/sockets/mch_03_multicast_client/nbproject/private/private.xml b/Pro Java 7 NIO.2/Chapter08/sockets/mch_03_multicast_client/nbproject/private/private.xml new file mode 100644 index 0000000..c1f155a --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter08/sockets/mch_03_multicast_client/nbproject/private/private.xml @@ -0,0 +1,4 @@ + + + + diff --git a/Pro Java 7 NIO.2/Chapter08/sockets/mch_03_multicast_client/nbproject/project.properties b/Pro Java 7 NIO.2/Chapter08/sockets/mch_03_multicast_client/nbproject/project.properties new file mode 100644 index 0000000..41e3d73 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter08/sockets/mch_03_multicast_client/nbproject/project.properties @@ -0,0 +1,72 @@ +annotation.processing.enabled=true +annotation.processing.enabled.in.editor=false +annotation.processing.run.all.processors=true +annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output +application.title=mch_03_multicast_client +application.vendor=Leo +build.classes.dir=${build.dir}/classes +build.classes.excludes=**/*.java,**/*.form +# This directory is removed when the project is cleaned: +build.dir=build +build.generated.dir=${build.dir}/generated +build.generated.sources.dir=${build.dir}/generated-sources +# Only compile against the classpath explicitly listed here: +build.sysclasspath=ignore +build.test.classes.dir=${build.dir}/test/classes +build.test.results.dir=${build.dir}/test/results +# Uncomment to specify the preferred debugger connection transport: +#debug.transport=dt_socket +debug.classpath=\ + ${run.classpath} +debug.test.classpath=\ + ${run.test.classpath} +# This directory is removed when the project is cleaned: +dist.dir=dist +dist.jar=${dist.dir}/mch_03_multicast_client.jar +dist.javadoc.dir=${dist.dir}/javadoc +endorsed.classpath= +excludes= +includes=** +jar.compress=false +javac.classpath= +# Space-separated list of extra javac options +javac.compilerargs= +javac.deprecation=false +javac.processorpath=\ + ${javac.classpath} +javac.source=1.7 +javac.target=1.7 +javac.test.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +javac.test.processorpath=\ + ${javac.test.classpath} +javadoc.additionalparam= +javadoc.author=false +javadoc.encoding=${source.encoding} +javadoc.noindex=false +javadoc.nonavbar=false +javadoc.notree=false +javadoc.private=false +javadoc.splitindex=true +javadoc.use=true +javadoc.version=false +javadoc.windowtitle= +main.class=mch_03_multicast_client.Main +manifest.file=manifest.mf +meta.inf.dir=${src.dir}/META-INF +mkdist.disabled=false +platform.active=default_platform +run.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +# Space-separated list of JVM arguments used when running the project +# (you may also define separate properties like run-sys-prop.name=value instead of -Dname=value +# or test-sys-prop.name=value to set system properties for unit tests): +run.jvmargs= +run.test.classpath=\ + ${javac.test.classpath}:\ + ${build.test.classes.dir} +source.encoding=UTF-8 +src.dir=src +test.src.dir=test diff --git a/Pro Java 7 NIO.2/Chapter08/sockets/mch_03_multicast_client/nbproject/project.xml b/Pro Java 7 NIO.2/Chapter08/sockets/mch_03_multicast_client/nbproject/project.xml new file mode 100644 index 0000000..c10023e --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter08/sockets/mch_03_multicast_client/nbproject/project.xml @@ -0,0 +1,15 @@ + + + org.netbeans.modules.java.j2seproject + + + mch_03_multicast_client + + + + + + + + + diff --git a/Pro Java 7 NIO.2/Chapter08/sockets/mch_03_multicast_client/src/mch_03_multicast_client/Main.java b/Pro Java 7 NIO.2/Chapter08/sockets/mch_03_multicast_client/src/mch_03_multicast_client/Main.java new file mode 100644 index 0000000..cfdf2ed --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter08/sockets/mch_03_multicast_client/src/mch_03_multicast_client/Main.java @@ -0,0 +1,80 @@ +package mch_03_multicast_client; + +import java.io.IOException; +import java.net.InetAddress; +import java.net.InetSocketAddress; +import java.net.NetworkInterface; +import java.net.StandardProtocolFamily; +import java.nio.channels.DatagramChannel; +import java.net.StandardSocketOptions; +import java.nio.ByteBuffer; +import java.nio.CharBuffer; +import java.nio.channels.MembershipKey; +import java.nio.charset.Charset; +import java.nio.charset.CharsetDecoder; + +/** + * + * @author Apress + */ +public class Main { + + public static void main(String[] args) { + + final int DEFAULT_PORT = 5555; + final int MAX_PACKET_SIZE = 65507; + final String GROUP = "225.4.5.6"; + + CharBuffer charBuffer = null; + Charset charset = Charset.defaultCharset(); + CharsetDecoder decoder = charset.newDecoder(); + ByteBuffer datetime = ByteBuffer.allocateDirect(MAX_PACKET_SIZE); + + //create a new channel + try (DatagramChannel datagramChannel = DatagramChannel.open(StandardProtocolFamily.INET)) { + + InetAddress group = InetAddress.getByName(GROUP); + //check if the group address is multicast + if (group.isMulticastAddress()) { + //check if the channel was successfully created + if (datagramChannel.isOpen()) { + + //get the network interface used for multicast + NetworkInterface networkInterface = NetworkInterface.getByName("eth3"); + + //set some options + datagramChannel.setOption(StandardSocketOptions.SO_REUSEADDR, true); + //bind the channel to the local address + datagramChannel.bind(new InetSocketAddress(DEFAULT_PORT)); + //join the multicast group and get ready to receive datagrams + MembershipKey key = datagramChannel.join(group, networkInterface); + + //wait for datagrams + while (true) { + + if (key.isValid()) { + + datagramChannel.receive(datetime); + datetime.flip(); + charBuffer = decoder.decode(datetime); + System.out.println(charBuffer.toString()); + datetime.clear(); + } else { + break; + } + } + + } else { + System.out.println("The channel cannot be opened!"); + } + } else { + System.out.println("This is not multicast address!"); + } + + } catch (IOException ex) { + System.err.println(ex); + } + + } +} + diff --git a/Pro Java 7 NIO.2/Chapter08/sockets/mch_03_multicast_server/build.xml b/Pro Java 7 NIO.2/Chapter08/sockets/mch_03_multicast_server/build.xml new file mode 100644 index 0000000..83c403d --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter08/sockets/mch_03_multicast_server/build.xml @@ -0,0 +1,74 @@ + + + + + + + + + + + Builds, tests, and runs the project mch_03_multicast_server. + + + diff --git a/Pro Java 7 NIO.2/Chapter08/sockets/mch_03_multicast_server/build/built-jar.properties b/Pro Java 7 NIO.2/Chapter08/sockets/mch_03_multicast_server/build/built-jar.properties new file mode 100644 index 0000000..a9b6717 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter08/sockets/mch_03_multicast_server/build/built-jar.properties @@ -0,0 +1,4 @@ +#Sun, 30 Oct 2011 07:52:27 +0200 + + +C\:\\NIO\\sockets\\mch_03_multicast_server= diff --git a/Pro Java 7 NIO.2/Chapter08/sockets/mch_03_multicast_server/build/classes/.netbeans_automatic_build b/Pro Java 7 NIO.2/Chapter08/sockets/mch_03_multicast_server/build/classes/.netbeans_automatic_build new file mode 100644 index 0000000..e69de29 diff --git a/Pro Java 7 NIO.2/Chapter08/sockets/mch_03_multicast_server/build/classes/mch_03_multicast_server/Main.class b/Pro Java 7 NIO.2/Chapter08/sockets/mch_03_multicast_server/build/classes/mch_03_multicast_server/Main.class new file mode 100644 index 0000000..2344e98 Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter08/sockets/mch_03_multicast_server/build/classes/mch_03_multicast_server/Main.class differ diff --git a/Pro Java 7 NIO.2/Chapter08/sockets/mch_03_multicast_server/dist/README.TXT b/Pro Java 7 NIO.2/Chapter08/sockets/mch_03_multicast_server/dist/README.TXT new file mode 100644 index 0000000..ccff182 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter08/sockets/mch_03_multicast_server/dist/README.TXT @@ -0,0 +1,32 @@ +======================== +BUILD OUTPUT DESCRIPTION +======================== + +When you build an Java application project that has a main class, the IDE +automatically copies all of the JAR +files on the projects classpath to your projects dist/lib folder. The IDE +also adds each of the JAR files to the Class-Path element in the application +JAR files manifest file (MANIFEST.MF). + +To run the project from the command line, go to the dist folder and +type the following: + +java -jar "mch_03_multicast_server.jar" + +To distribute this project, zip up the dist folder (including the lib folder) +and distribute the ZIP file. + +Notes: + +* If two JAR files on the project classpath have the same name, only the first +JAR file is copied to the lib folder. +* Only JAR files are copied to the lib folder. +If the classpath contains other types of files or folders, these files (folders) +are not copied. +* If a library on the projects classpath also has a Class-Path element +specified in the manifest,the content of the Class-Path element has to be on +the projects runtime path. +* To set a main class in a standard Java project, right-click the project node +in the Projects window and choose Properties. Then click Run and enter the +class name in the Main Class field. Alternatively, you can manually type the +class name in the manifest Main-Class element. diff --git a/Pro Java 7 NIO.2/Chapter08/sockets/mch_03_multicast_server/dist/mch_03_multicast_server.jar b/Pro Java 7 NIO.2/Chapter08/sockets/mch_03_multicast_server/dist/mch_03_multicast_server.jar new file mode 100644 index 0000000..cf544ef Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter08/sockets/mch_03_multicast_server/dist/mch_03_multicast_server.jar differ diff --git a/Pro Java 7 NIO.2/Chapter08/sockets/mch_03_multicast_server/manifest.mf b/Pro Java 7 NIO.2/Chapter08/sockets/mch_03_multicast_server/manifest.mf new file mode 100644 index 0000000..328e8e5 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter08/sockets/mch_03_multicast_server/manifest.mf @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +X-COMMENT: Main-Class will be added automatically by build + diff --git a/Pro Java 7 NIO.2/Chapter08/sockets/mch_03_multicast_server/nbproject/build-impl.xml b/Pro Java 7 NIO.2/Chapter08/sockets/mch_03_multicast_server/nbproject/build-impl.xml new file mode 100644 index 0000000..3e27537 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter08/sockets/mch_03_multicast_server/nbproject/build-impl.xml @@ -0,0 +1,1041 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set src.dir + Must set test.src.dir + Must set build.dir + Must set dist.dir + Must set build.classes.dir + Must set dist.javadoc.dir + Must set build.test.classes.dir + Must set build.test.results.dir + Must set build.classes.excludes + Must set dist.jar + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set JVM to use for profiling in profiler.info.jvm + Must set profiler agent JVM arguments in profiler.info.jvmargs.agent + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + + + + + + java -cp "${run.classpath.with.dist.jar}" ${main.class} + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + java -jar "${dist.jar.resolved}" + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set run.class + + + + Must select one file in the IDE or set run.class + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set debug.class + + + + + Must select one file in the IDE or set debug.class + + + + + Must set fix.includes + + + + + + + + + + + + + + + + + Must select one file in the IDE or set profile.class + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + Some tests failed; see details above. + + + + + + + + + Must select some files in the IDE or set test.includes + + + + Some tests failed; see details above. + + + + + Must select one file in the IDE or set test.class + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Pro Java 7 NIO.2/Chapter08/sockets/mch_03_multicast_server/nbproject/genfiles.properties b/Pro Java 7 NIO.2/Chapter08/sockets/mch_03_multicast_server/nbproject/genfiles.properties new file mode 100644 index 0000000..ba09f29 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter08/sockets/mch_03_multicast_server/nbproject/genfiles.properties @@ -0,0 +1,8 @@ +build.xml.data.CRC32=27ab7eb0 +build.xml.script.CRC32=8d675706 +build.xml.stylesheet.CRC32=28e38971@1.43.1.45 +# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. +# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. +nbproject/build-impl.xml.data.CRC32=27ab7eb0 +nbproject/build-impl.xml.script.CRC32=13e11b1c +nbproject/build-impl.xml.stylesheet.CRC32=0c01fd8e@1.43.1.45 diff --git a/Pro Java 7 NIO.2/Chapter08/sockets/mch_03_multicast_server/nbproject/private/config.properties b/Pro Java 7 NIO.2/Chapter08/sockets/mch_03_multicast_server/nbproject/private/config.properties new file mode 100644 index 0000000..e69de29 diff --git a/Pro Java 7 NIO.2/Chapter08/sockets/mch_03_multicast_server/nbproject/private/private.properties b/Pro Java 7 NIO.2/Chapter08/sockets/mch_03_multicast_server/nbproject/private/private.properties new file mode 100644 index 0000000..a5ab360 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter08/sockets/mch_03_multicast_server/nbproject/private/private.properties @@ -0,0 +1,6 @@ +compile.on.save=true +do.depend=false +do.jar=true +javac.debug=true +javadoc.preview=true +user.properties.file=C:\\Users\\Leo\\.netbeans\\7.0\\build.properties diff --git a/Pro Java 7 NIO.2/Chapter08/sockets/mch_03_multicast_server/nbproject/private/private.xml b/Pro Java 7 NIO.2/Chapter08/sockets/mch_03_multicast_server/nbproject/private/private.xml new file mode 100644 index 0000000..c1f155a --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter08/sockets/mch_03_multicast_server/nbproject/private/private.xml @@ -0,0 +1,4 @@ + + + + diff --git a/Pro Java 7 NIO.2/Chapter08/sockets/mch_03_multicast_server/nbproject/project.properties b/Pro Java 7 NIO.2/Chapter08/sockets/mch_03_multicast_server/nbproject/project.properties new file mode 100644 index 0000000..7afa155 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter08/sockets/mch_03_multicast_server/nbproject/project.properties @@ -0,0 +1,72 @@ +annotation.processing.enabled=true +annotation.processing.enabled.in.editor=false +annotation.processing.run.all.processors=true +annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output +application.title=mch_03_multicast_server +application.vendor=Leo +build.classes.dir=${build.dir}/classes +build.classes.excludes=**/*.java,**/*.form +# This directory is removed when the project is cleaned: +build.dir=build +build.generated.dir=${build.dir}/generated +build.generated.sources.dir=${build.dir}/generated-sources +# Only compile against the classpath explicitly listed here: +build.sysclasspath=ignore +build.test.classes.dir=${build.dir}/test/classes +build.test.results.dir=${build.dir}/test/results +# Uncomment to specify the preferred debugger connection transport: +#debug.transport=dt_socket +debug.classpath=\ + ${run.classpath} +debug.test.classpath=\ + ${run.test.classpath} +# This directory is removed when the project is cleaned: +dist.dir=dist +dist.jar=${dist.dir}/mch_03_multicast_server.jar +dist.javadoc.dir=${dist.dir}/javadoc +endorsed.classpath= +excludes= +includes=** +jar.compress=false +javac.classpath= +# Space-separated list of extra javac options +javac.compilerargs= +javac.deprecation=false +javac.processorpath=\ + ${javac.classpath} +javac.source=1.7 +javac.target=1.7 +javac.test.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +javac.test.processorpath=\ + ${javac.test.classpath} +javadoc.additionalparam= +javadoc.author=false +javadoc.encoding=${source.encoding} +javadoc.noindex=false +javadoc.nonavbar=false +javadoc.notree=false +javadoc.private=false +javadoc.splitindex=true +javadoc.use=true +javadoc.version=false +javadoc.windowtitle= +main.class=mch_03_multicast_server.Main +manifest.file=manifest.mf +meta.inf.dir=${src.dir}/META-INF +mkdist.disabled=false +platform.active=default_platform +run.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +# Space-separated list of JVM arguments used when running the project +# (you may also define separate properties like run-sys-prop.name=value instead of -Dname=value +# or test-sys-prop.name=value to set system properties for unit tests): +run.jvmargs= +run.test.classpath=\ + ${javac.test.classpath}:\ + ${build.test.classes.dir} +source.encoding=UTF-8 +src.dir=src +test.src.dir=test diff --git a/Pro Java 7 NIO.2/Chapter08/sockets/mch_03_multicast_server/nbproject/project.xml b/Pro Java 7 NIO.2/Chapter08/sockets/mch_03_multicast_server/nbproject/project.xml new file mode 100644 index 0000000..834818e --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter08/sockets/mch_03_multicast_server/nbproject/project.xml @@ -0,0 +1,15 @@ + + + org.netbeans.modules.java.j2seproject + + + mch_03_multicast_server + + + + + + + + + diff --git a/Pro Java 7 NIO.2/Chapter08/sockets/mch_03_multicast_server/src/mch_03_multicast_server/Main.java b/Pro Java 7 NIO.2/Chapter08/sockets/mch_03_multicast_server/src/mch_03_multicast_server/Main.java new file mode 100644 index 0000000..c9dde87 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter08/sockets/mch_03_multicast_server/src/mch_03_multicast_server/Main.java @@ -0,0 +1,64 @@ +package mch_03_multicast_server; + +import java.io.IOException; +import java.net.InetAddress; +import java.net.InetSocketAddress; +import java.net.NetworkInterface; +import java.net.StandardProtocolFamily; +import java.nio.channels.DatagramChannel; +import java.net.StandardSocketOptions; +import java.nio.ByteBuffer; +import java.util.Date; + +/** + * + * @author Apress + */ +public class Main { + + public static void main(String[] args) { + + final int DEFAULT_PORT = 5555; + final String GROUP = "225.4.5.6"; + ByteBuffer datetime; + + //create a new channel + try (DatagramChannel datagramChannel = DatagramChannel.open(StandardProtocolFamily.INET)) { + + //check if the channel was successfully created + if (datagramChannel.isOpen()) { + + //get the network interface used for multicast + NetworkInterface networkInterface = NetworkInterface.getByName("eth3"); + + //set some options + datagramChannel.setOption(StandardSocketOptions.IP_MULTICAST_IF, networkInterface); + datagramChannel.setOption(StandardSocketOptions.SO_REUSEADDR, true); + + //bind the channel to the local address + datagramChannel.bind(new InetSocketAddress(DEFAULT_PORT)); + System.out.println("Date-time server is ready ... shortly I'll start sending ..."); + + //transmitting datagrams + while (true) { + + //sleep for 10 seconds + try { + Thread.sleep(10000); + } catch (InterruptedException ex) { + } + System.out.println("Sending data ..."); + + datetime = ByteBuffer.wrap(new Date().toString().getBytes()); + datagramChannel.send(datetime, new InetSocketAddress(InetAddress.getByName(GROUP), DEFAULT_PORT)); + datetime.flip(); + } + + } else { + System.out.println("The channel cannot be opened!"); + } + } catch (IOException ex) { + System.err.println(ex); + } + } +} diff --git a/Pro Java 7 NIO.2/Chapter08/sockets/mch_04_serverclient/build.xml b/Pro Java 7 NIO.2/Chapter08/sockets/mch_04_serverclient/build.xml new file mode 100644 index 0000000..5a3ebf9 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter08/sockets/mch_04_serverclient/build.xml @@ -0,0 +1,74 @@ + + + + + + + + + + + Builds, tests, and runs the project mch_04_serverclient. + + + diff --git a/Pro Java 7 NIO.2/Chapter08/sockets/mch_04_serverclient/build/built-jar.properties b/Pro Java 7 NIO.2/Chapter08/sockets/mch_04_serverclient/build/built-jar.properties new file mode 100644 index 0000000..4d8f27a --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter08/sockets/mch_04_serverclient/build/built-jar.properties @@ -0,0 +1,4 @@ +#Sun, 30 Oct 2011 07:55:25 +0200 + + +C\:\\NIO\\sockets\\mch_04_serverclient= diff --git a/Pro Java 7 NIO.2/Chapter08/sockets/mch_04_serverclient/build/classes/.netbeans_automatic_build b/Pro Java 7 NIO.2/Chapter08/sockets/mch_04_serverclient/build/classes/.netbeans_automatic_build new file mode 100644 index 0000000..e69de29 diff --git a/Pro Java 7 NIO.2/Chapter08/sockets/mch_04_serverclient/build/classes/mch_04_serverclient/Main.class b/Pro Java 7 NIO.2/Chapter08/sockets/mch_04_serverclient/build/classes/mch_04_serverclient/Main.class new file mode 100644 index 0000000..f1ef46c Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter08/sockets/mch_04_serverclient/build/classes/mch_04_serverclient/Main.class differ diff --git a/Pro Java 7 NIO.2/Chapter08/sockets/mch_04_serverclient/dist/README.TXT b/Pro Java 7 NIO.2/Chapter08/sockets/mch_04_serverclient/dist/README.TXT new file mode 100644 index 0000000..7bed11f --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter08/sockets/mch_04_serverclient/dist/README.TXT @@ -0,0 +1,32 @@ +======================== +BUILD OUTPUT DESCRIPTION +======================== + +When you build an Java application project that has a main class, the IDE +automatically copies all of the JAR +files on the projects classpath to your projects dist/lib folder. The IDE +also adds each of the JAR files to the Class-Path element in the application +JAR files manifest file (MANIFEST.MF). + +To run the project from the command line, go to the dist folder and +type the following: + +java -jar "mch_04_serverclient.jar" + +To distribute this project, zip up the dist folder (including the lib folder) +and distribute the ZIP file. + +Notes: + +* If two JAR files on the project classpath have the same name, only the first +JAR file is copied to the lib folder. +* Only JAR files are copied to the lib folder. +If the classpath contains other types of files or folders, these files (folders) +are not copied. +* If a library on the projects classpath also has a Class-Path element +specified in the manifest,the content of the Class-Path element has to be on +the projects runtime path. +* To set a main class in a standard Java project, right-click the project node +in the Projects window and choose Properties. Then click Run and enter the +class name in the Main Class field. Alternatively, you can manually type the +class name in the manifest Main-Class element. diff --git a/Pro Java 7 NIO.2/Chapter08/sockets/mch_04_serverclient/dist/mch_04_serverclient.jar b/Pro Java 7 NIO.2/Chapter08/sockets/mch_04_serverclient/dist/mch_04_serverclient.jar new file mode 100644 index 0000000..bc995a8 Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter08/sockets/mch_04_serverclient/dist/mch_04_serverclient.jar differ diff --git a/Pro Java 7 NIO.2/Chapter08/sockets/mch_04_serverclient/manifest.mf b/Pro Java 7 NIO.2/Chapter08/sockets/mch_04_serverclient/manifest.mf new file mode 100644 index 0000000..328e8e5 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter08/sockets/mch_04_serverclient/manifest.mf @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +X-COMMENT: Main-Class will be added automatically by build + diff --git a/Pro Java 7 NIO.2/Chapter08/sockets/mch_04_serverclient/nbproject/build-impl.xml b/Pro Java 7 NIO.2/Chapter08/sockets/mch_04_serverclient/nbproject/build-impl.xml new file mode 100644 index 0000000..a432757 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter08/sockets/mch_04_serverclient/nbproject/build-impl.xml @@ -0,0 +1,1041 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set src.dir + Must set test.src.dir + Must set build.dir + Must set dist.dir + Must set build.classes.dir + Must set dist.javadoc.dir + Must set build.test.classes.dir + Must set build.test.results.dir + Must set build.classes.excludes + Must set dist.jar + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set JVM to use for profiling in profiler.info.jvm + Must set profiler agent JVM arguments in profiler.info.jvmargs.agent + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + + + + + + java -cp "${run.classpath.with.dist.jar}" ${main.class} + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + java -jar "${dist.jar.resolved}" + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set run.class + + + + Must select one file in the IDE or set run.class + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set debug.class + + + + + Must select one file in the IDE or set debug.class + + + + + Must set fix.includes + + + + + + + + + + + + + + + + + Must select one file in the IDE or set profile.class + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + Some tests failed; see details above. + + + + + + + + + Must select some files in the IDE or set test.includes + + + + Some tests failed; see details above. + + + + + Must select one file in the IDE or set test.class + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Pro Java 7 NIO.2/Chapter08/sockets/mch_04_serverclient/nbproject/genfiles.properties b/Pro Java 7 NIO.2/Chapter08/sockets/mch_04_serverclient/nbproject/genfiles.properties new file mode 100644 index 0000000..c21a8cf --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter08/sockets/mch_04_serverclient/nbproject/genfiles.properties @@ -0,0 +1,8 @@ +build.xml.data.CRC32=63e42fdd +build.xml.script.CRC32=cb2fc8d8 +build.xml.stylesheet.CRC32=28e38971@1.43.1.45 +# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. +# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. +nbproject/build-impl.xml.data.CRC32=63e42fdd +nbproject/build-impl.xml.script.CRC32=53040b0f +nbproject/build-impl.xml.stylesheet.CRC32=0c01fd8e@1.43.1.45 diff --git a/Pro Java 7 NIO.2/Chapter08/sockets/mch_04_serverclient/nbproject/private/config.properties b/Pro Java 7 NIO.2/Chapter08/sockets/mch_04_serverclient/nbproject/private/config.properties new file mode 100644 index 0000000..e69de29 diff --git a/Pro Java 7 NIO.2/Chapter08/sockets/mch_04_serverclient/nbproject/private/private.properties b/Pro Java 7 NIO.2/Chapter08/sockets/mch_04_serverclient/nbproject/private/private.properties new file mode 100644 index 0000000..a5ab360 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter08/sockets/mch_04_serverclient/nbproject/private/private.properties @@ -0,0 +1,6 @@ +compile.on.save=true +do.depend=false +do.jar=true +javac.debug=true +javadoc.preview=true +user.properties.file=C:\\Users\\Leo\\.netbeans\\7.0\\build.properties diff --git a/Pro Java 7 NIO.2/Chapter08/sockets/mch_04_serverclient/nbproject/private/private.xml b/Pro Java 7 NIO.2/Chapter08/sockets/mch_04_serverclient/nbproject/private/private.xml new file mode 100644 index 0000000..c1f155a --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter08/sockets/mch_04_serverclient/nbproject/private/private.xml @@ -0,0 +1,4 @@ + + + + diff --git a/Pro Java 7 NIO.2/Chapter08/sockets/mch_04_serverclient/nbproject/project.properties b/Pro Java 7 NIO.2/Chapter08/sockets/mch_04_serverclient/nbproject/project.properties new file mode 100644 index 0000000..620f03b --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter08/sockets/mch_04_serverclient/nbproject/project.properties @@ -0,0 +1,72 @@ +annotation.processing.enabled=true +annotation.processing.enabled.in.editor=false +annotation.processing.run.all.processors=true +annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output +application.title=mch_04_serverclient +application.vendor=Leo +build.classes.dir=${build.dir}/classes +build.classes.excludes=**/*.java,**/*.form +# This directory is removed when the project is cleaned: +build.dir=build +build.generated.dir=${build.dir}/generated +build.generated.sources.dir=${build.dir}/generated-sources +# Only compile against the classpath explicitly listed here: +build.sysclasspath=ignore +build.test.classes.dir=${build.dir}/test/classes +build.test.results.dir=${build.dir}/test/results +# Uncomment to specify the preferred debugger connection transport: +#debug.transport=dt_socket +debug.classpath=\ + ${run.classpath} +debug.test.classpath=\ + ${run.test.classpath} +# This directory is removed when the project is cleaned: +dist.dir=dist +dist.jar=${dist.dir}/mch_04_serverclient.jar +dist.javadoc.dir=${dist.dir}/javadoc +endorsed.classpath= +excludes= +includes=** +jar.compress=false +javac.classpath= +# Space-separated list of extra javac options +javac.compilerargs= +javac.deprecation=false +javac.processorpath=\ + ${javac.classpath} +javac.source=1.7 +javac.target=1.7 +javac.test.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +javac.test.processorpath=\ + ${javac.test.classpath} +javadoc.additionalparam= +javadoc.author=false +javadoc.encoding=${source.encoding} +javadoc.noindex=false +javadoc.nonavbar=false +javadoc.notree=false +javadoc.private=false +javadoc.splitindex=true +javadoc.use=true +javadoc.version=false +javadoc.windowtitle= +main.class=mch_04_serverclient.Main +manifest.file=manifest.mf +meta.inf.dir=${src.dir}/META-INF +mkdist.disabled=false +platform.active=default_platform +run.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +# Space-separated list of JVM arguments used when running the project +# (you may also define separate properties like run-sys-prop.name=value instead of -Dname=value +# or test-sys-prop.name=value to set system properties for unit tests): +run.jvmargs= +run.test.classpath=\ + ${javac.test.classpath}:\ + ${build.test.classes.dir} +source.encoding=UTF-8 +src.dir=src +test.src.dir=test diff --git a/Pro Java 7 NIO.2/Chapter08/sockets/mch_04_serverclient/nbproject/project.xml b/Pro Java 7 NIO.2/Chapter08/sockets/mch_04_serverclient/nbproject/project.xml new file mode 100644 index 0000000..533cdc5 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter08/sockets/mch_04_serverclient/nbproject/project.xml @@ -0,0 +1,15 @@ + + + org.netbeans.modules.java.j2seproject + + + mch_04_serverclient + + + + + + + + + diff --git a/Pro Java 7 NIO.2/Chapter08/sockets/mch_04_serverclient/src/mch_04_serverclient/Main.java b/Pro Java 7 NIO.2/Chapter08/sockets/mch_04_serverclient/src/mch_04_serverclient/Main.java new file mode 100644 index 0000000..eee8e81 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter08/sockets/mch_04_serverclient/src/mch_04_serverclient/Main.java @@ -0,0 +1,86 @@ +package mch_04_serverclient; + +import java.io.IOException; +import java.net.InetSocketAddress; +import java.net.StandardSocketOptions; +import java.nio.ByteBuffer; +import java.nio.CharBuffer; +import java.nio.channels.SocketChannel; +import java.nio.charset.Charset; +import java.nio.charset.CharsetDecoder; +import java.util.Random; + +/** + * + * @author Apress + */ +public class Main { + + public static void main(String[] args) { + + final int DEFAULT_PORT = 5555; + final String IP = "127.0.0.1"; + ByteBuffer buffer = ByteBuffer.allocateDirect(1024); + ByteBuffer helloBuffer = ByteBuffer.wrap("Hello !".getBytes()); + ByteBuffer randomBuffer; + CharBuffer charBuffer; + Charset charset = Charset.defaultCharset(); + CharsetDecoder decoder = charset.newDecoder(); + + //create a new socket channel + try (SocketChannel socketChannel = SocketChannel.open()) { + + //continue if it was successfully created + if (socketChannel.isOpen()) { + + //set the blocking mode + socketChannel.configureBlocking(true); + //set some options + socketChannel.setOption(StandardSocketOptions.SO_RCVBUF, 128 * 1024); + socketChannel.setOption(StandardSocketOptions.SO_SNDBUF, 128 * 1024); + socketChannel.setOption(StandardSocketOptions.SO_KEEPALIVE, true); + socketChannel.setOption(StandardSocketOptions.SO_LINGER, 5); + //connect this channel's socket + socketChannel.connect(new InetSocketAddress(IP, DEFAULT_PORT)); + + //check if the connection was successfully accomplished + if (socketChannel.isConnected()) { + + //transmitting data + socketChannel.write(helloBuffer); + + while (socketChannel.read(buffer) != -1) { + + buffer.flip(); + + charBuffer = decoder.decode(buffer); + System.out.println(charBuffer.toString()); + + if (buffer.hasRemaining()) { + buffer.compact(); + } else { + buffer.clear(); + } + + int r = new Random().nextInt(100); + if (r == 50) { + System.out.println("50 was generated! Close the socket channel!"); + break; + } else { + randomBuffer = ByteBuffer.wrap("Random number:".concat(String.valueOf(r)).getBytes()); + socketChannel.write(randomBuffer); + } + } + } else { + System.out.println("The connection cannot be established!"); + } + } else { + System.out.println("The socket channel cannot be opened!"); + } + } catch (IOException ex) { + System.err.println(ex); + } + + + } +} diff --git a/Pro Java 7 NIO.2/Chapter08/sockets/mch_04_serversocket/build.xml b/Pro Java 7 NIO.2/Chapter08/sockets/mch_04_serversocket/build.xml new file mode 100644 index 0000000..fcad9b6 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter08/sockets/mch_04_serversocket/build.xml @@ -0,0 +1,74 @@ + + + + + + + + + + + Builds, tests, and runs the project mch_04_serversocket. + + + diff --git a/Pro Java 7 NIO.2/Chapter08/sockets/mch_04_serversocket/build/built-jar.properties b/Pro Java 7 NIO.2/Chapter08/sockets/mch_04_serversocket/build/built-jar.properties new file mode 100644 index 0000000..686a306 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter08/sockets/mch_04_serversocket/build/built-jar.properties @@ -0,0 +1,4 @@ +#Sun, 30 Oct 2011 07:55:20 +0200 + + +C\:\\NIO\\sockets\\mch_04_serversocket= diff --git a/Pro Java 7 NIO.2/Chapter08/sockets/mch_04_serversocket/build/classes/.netbeans_automatic_build b/Pro Java 7 NIO.2/Chapter08/sockets/mch_04_serversocket/build/classes/.netbeans_automatic_build new file mode 100644 index 0000000..e69de29 diff --git a/Pro Java 7 NIO.2/Chapter08/sockets/mch_04_serversocket/build/classes/mch_04_serversocket/Main.class b/Pro Java 7 NIO.2/Chapter08/sockets/mch_04_serversocket/build/classes/mch_04_serversocket/Main.class new file mode 100644 index 0000000..8a8bcb1 Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter08/sockets/mch_04_serversocket/build/classes/mch_04_serversocket/Main.class differ diff --git a/Pro Java 7 NIO.2/Chapter08/sockets/mch_04_serversocket/dist/README.TXT b/Pro Java 7 NIO.2/Chapter08/sockets/mch_04_serversocket/dist/README.TXT new file mode 100644 index 0000000..c91ed95 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter08/sockets/mch_04_serversocket/dist/README.TXT @@ -0,0 +1,32 @@ +======================== +BUILD OUTPUT DESCRIPTION +======================== + +When you build an Java application project that has a main class, the IDE +automatically copies all of the JAR +files on the projects classpath to your projects dist/lib folder. The IDE +also adds each of the JAR files to the Class-Path element in the application +JAR files manifest file (MANIFEST.MF). + +To run the project from the command line, go to the dist folder and +type the following: + +java -jar "mch_04_serversocket.jar" + +To distribute this project, zip up the dist folder (including the lib folder) +and distribute the ZIP file. + +Notes: + +* If two JAR files on the project classpath have the same name, only the first +JAR file is copied to the lib folder. +* Only JAR files are copied to the lib folder. +If the classpath contains other types of files or folders, these files (folders) +are not copied. +* If a library on the projects classpath also has a Class-Path element +specified in the manifest,the content of the Class-Path element has to be on +the projects runtime path. +* To set a main class in a standard Java project, right-click the project node +in the Projects window and choose Properties. Then click Run and enter the +class name in the Main Class field. Alternatively, you can manually type the +class name in the manifest Main-Class element. diff --git a/Pro Java 7 NIO.2/Chapter08/sockets/mch_04_serversocket/dist/mch_04_serversocket.jar b/Pro Java 7 NIO.2/Chapter08/sockets/mch_04_serversocket/dist/mch_04_serversocket.jar new file mode 100644 index 0000000..873e2ff Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter08/sockets/mch_04_serversocket/dist/mch_04_serversocket.jar differ diff --git a/Pro Java 7 NIO.2/Chapter08/sockets/mch_04_serversocket/manifest.mf b/Pro Java 7 NIO.2/Chapter08/sockets/mch_04_serversocket/manifest.mf new file mode 100644 index 0000000..328e8e5 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter08/sockets/mch_04_serversocket/manifest.mf @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +X-COMMENT: Main-Class will be added automatically by build + diff --git a/Pro Java 7 NIO.2/Chapter08/sockets/mch_04_serversocket/nbproject/build-impl.xml b/Pro Java 7 NIO.2/Chapter08/sockets/mch_04_serversocket/nbproject/build-impl.xml new file mode 100644 index 0000000..c9078aa --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter08/sockets/mch_04_serversocket/nbproject/build-impl.xml @@ -0,0 +1,1041 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set src.dir + Must set test.src.dir + Must set build.dir + Must set dist.dir + Must set build.classes.dir + Must set dist.javadoc.dir + Must set build.test.classes.dir + Must set build.test.results.dir + Must set build.classes.excludes + Must set dist.jar + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set JVM to use for profiling in profiler.info.jvm + Must set profiler agent JVM arguments in profiler.info.jvmargs.agent + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + + + + + + java -cp "${run.classpath.with.dist.jar}" ${main.class} + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + java -jar "${dist.jar.resolved}" + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set run.class + + + + Must select one file in the IDE or set run.class + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set debug.class + + + + + Must select one file in the IDE or set debug.class + + + + + Must set fix.includes + + + + + + + + + + + + + + + + + Must select one file in the IDE or set profile.class + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + Some tests failed; see details above. + + + + + + + + + Must select some files in the IDE or set test.includes + + + + Some tests failed; see details above. + + + + + Must select one file in the IDE or set test.class + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Pro Java 7 NIO.2/Chapter08/sockets/mch_04_serversocket/nbproject/genfiles.properties b/Pro Java 7 NIO.2/Chapter08/sockets/mch_04_serversocket/nbproject/genfiles.properties new file mode 100644 index 0000000..13e598d --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter08/sockets/mch_04_serversocket/nbproject/genfiles.properties @@ -0,0 +1,8 @@ +build.xml.data.CRC32=69e4993c +build.xml.script.CRC32=f26f175a +build.xml.stylesheet.CRC32=28e38971@1.43.1.45 +# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. +# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. +nbproject/build-impl.xml.data.CRC32=69e4993c +nbproject/build-impl.xml.script.CRC32=465dff9e +nbproject/build-impl.xml.stylesheet.CRC32=0c01fd8e@1.43.1.45 diff --git a/Pro Java 7 NIO.2/Chapter08/sockets/mch_04_serversocket/nbproject/private/config.properties b/Pro Java 7 NIO.2/Chapter08/sockets/mch_04_serversocket/nbproject/private/config.properties new file mode 100644 index 0000000..e69de29 diff --git a/Pro Java 7 NIO.2/Chapter08/sockets/mch_04_serversocket/nbproject/private/private.properties b/Pro Java 7 NIO.2/Chapter08/sockets/mch_04_serversocket/nbproject/private/private.properties new file mode 100644 index 0000000..a5ab360 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter08/sockets/mch_04_serversocket/nbproject/private/private.properties @@ -0,0 +1,6 @@ +compile.on.save=true +do.depend=false +do.jar=true +javac.debug=true +javadoc.preview=true +user.properties.file=C:\\Users\\Leo\\.netbeans\\7.0\\build.properties diff --git a/Pro Java 7 NIO.2/Chapter08/sockets/mch_04_serversocket/nbproject/private/private.xml b/Pro Java 7 NIO.2/Chapter08/sockets/mch_04_serversocket/nbproject/private/private.xml new file mode 100644 index 0000000..c1f155a --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter08/sockets/mch_04_serversocket/nbproject/private/private.xml @@ -0,0 +1,4 @@ + + + + diff --git a/Pro Java 7 NIO.2/Chapter08/sockets/mch_04_serversocket/nbproject/project.properties b/Pro Java 7 NIO.2/Chapter08/sockets/mch_04_serversocket/nbproject/project.properties new file mode 100644 index 0000000..ba31815 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter08/sockets/mch_04_serversocket/nbproject/project.properties @@ -0,0 +1,72 @@ +annotation.processing.enabled=true +annotation.processing.enabled.in.editor=false +annotation.processing.run.all.processors=true +annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output +application.title=mch_04_serversocket +application.vendor=Leo +build.classes.dir=${build.dir}/classes +build.classes.excludes=**/*.java,**/*.form +# This directory is removed when the project is cleaned: +build.dir=build +build.generated.dir=${build.dir}/generated +build.generated.sources.dir=${build.dir}/generated-sources +# Only compile against the classpath explicitly listed here: +build.sysclasspath=ignore +build.test.classes.dir=${build.dir}/test/classes +build.test.results.dir=${build.dir}/test/results +# Uncomment to specify the preferred debugger connection transport: +#debug.transport=dt_socket +debug.classpath=\ + ${run.classpath} +debug.test.classpath=\ + ${run.test.classpath} +# This directory is removed when the project is cleaned: +dist.dir=dist +dist.jar=${dist.dir}/mch_04_serversocket.jar +dist.javadoc.dir=${dist.dir}/javadoc +endorsed.classpath= +excludes= +includes=** +jar.compress=false +javac.classpath= +# Space-separated list of extra javac options +javac.compilerargs= +javac.deprecation=false +javac.processorpath=\ + ${javac.classpath} +javac.source=1.7 +javac.target=1.7 +javac.test.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +javac.test.processorpath=\ + ${javac.test.classpath} +javadoc.additionalparam= +javadoc.author=false +javadoc.encoding=${source.encoding} +javadoc.noindex=false +javadoc.nonavbar=false +javadoc.notree=false +javadoc.private=false +javadoc.splitindex=true +javadoc.use=true +javadoc.version=false +javadoc.windowtitle= +main.class=mch_04_serversocket.Main +manifest.file=manifest.mf +meta.inf.dir=${src.dir}/META-INF +mkdist.disabled=false +platform.active=default_platform +run.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +# Space-separated list of JVM arguments used when running the project +# (you may also define separate properties like run-sys-prop.name=value instead of -Dname=value +# or test-sys-prop.name=value to set system properties for unit tests): +run.jvmargs= +run.test.classpath=\ + ${javac.test.classpath}:\ + ${build.test.classes.dir} +source.encoding=UTF-8 +src.dir=src +test.src.dir=test diff --git a/Pro Java 7 NIO.2/Chapter08/sockets/mch_04_serversocket/nbproject/project.xml b/Pro Java 7 NIO.2/Chapter08/sockets/mch_04_serversocket/nbproject/project.xml new file mode 100644 index 0000000..4435c13 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter08/sockets/mch_04_serversocket/nbproject/project.xml @@ -0,0 +1,15 @@ + + + org.netbeans.modules.java.j2seproject + + + mch_04_serversocket + + + + + + + + + diff --git a/Pro Java 7 NIO.2/Chapter08/sockets/mch_04_serversocket/src/mch_04_serversocket/Main.java b/Pro Java 7 NIO.2/Chapter08/sockets/mch_04_serversocket/src/mch_04_serversocket/Main.java new file mode 100644 index 0000000..5334a5b --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter08/sockets/mch_04_serversocket/src/mch_04_serversocket/Main.java @@ -0,0 +1,68 @@ +package mch_04_serversocket; + +import java.io.IOException; +import java.net.InetSocketAddress; +import java.net.StandardSocketOptions; +import java.nio.ByteBuffer; +import java.nio.channels.ServerSocketChannel; +import java.nio.channels.SocketChannel; + +/** + * + * @author Apress + */ +public class Main { + + public static void main(String[] args) { + + final int DEFAULT_PORT = 5555; + final String IP = "127.0.0.1"; + + ByteBuffer buffer = ByteBuffer.allocateDirect(1024); + + //create a new server-socket channel + try (ServerSocketChannel serverSocketChannel = ServerSocketChannel.open()) { + + //continue if it was successfully created + if (serverSocketChannel.isOpen()) { + + //set the blocking mode + serverSocketChannel.configureBlocking(true); + //set some options + serverSocketChannel.setOption(StandardSocketOptions.SO_RCVBUF, 4 * 1024); + serverSocketChannel.setOption(StandardSocketOptions.SO_REUSEADDR, true); + //bind the server-socket channel to local address + serverSocketChannel.bind(new InetSocketAddress(IP, DEFAULT_PORT)); + + //display a waiting message while ... waiting clients + System.out.println("Waiting for connections ..."); + + //wait for incoming connections + while (true) { + try (SocketChannel socketChannel = serverSocketChannel.accept()) { + System.out.println("Incoming connection from: " + socketChannel.getRemoteAddress()); + + //transmitting data + while (socketChannel.read(buffer) != -1) { + + buffer.flip(); + + socketChannel.write(buffer); + + if (buffer.hasRemaining()) { + buffer.compact(); + } else { + buffer.clear(); + } + } + } catch (IOException ex) { + } + } + } else { + System.out.println("The server socket channel cannot be opened!"); + } + } catch (IOException ex) { + System.err.println(ex); + } + } +} diff --git a/Pro Java 7 NIO.2/Chapter08/sockets/mch_05_serverclient/build.xml b/Pro Java 7 NIO.2/Chapter08/sockets/mch_05_serverclient/build.xml new file mode 100644 index 0000000..be40aba --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter08/sockets/mch_05_serverclient/build.xml @@ -0,0 +1,74 @@ + + + + + + + + + + + Builds, tests, and runs the project mch_05_serverclient. + + + diff --git a/Pro Java 7 NIO.2/Chapter08/sockets/mch_05_serverclient/build/built-jar.properties b/Pro Java 7 NIO.2/Chapter08/sockets/mch_05_serverclient/build/built-jar.properties new file mode 100644 index 0000000..088bbe9 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter08/sockets/mch_05_serverclient/build/built-jar.properties @@ -0,0 +1,4 @@ +#Sun, 30 Oct 2011 07:58:55 +0200 + + +C\:\\NIO\\sockets\\mch_05_serverclient= diff --git a/Pro Java 7 NIO.2/Chapter08/sockets/mch_05_serverclient/build/classes/.netbeans_automatic_build b/Pro Java 7 NIO.2/Chapter08/sockets/mch_05_serverclient/build/classes/.netbeans_automatic_build new file mode 100644 index 0000000..e69de29 diff --git a/Pro Java 7 NIO.2/Chapter08/sockets/mch_05_serverclient/build/classes/mch_05_serverclient/Main.class b/Pro Java 7 NIO.2/Chapter08/sockets/mch_05_serverclient/build/classes/mch_05_serverclient/Main.class new file mode 100644 index 0000000..bf94fcf Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter08/sockets/mch_05_serverclient/build/classes/mch_05_serverclient/Main.class differ diff --git a/Pro Java 7 NIO.2/Chapter08/sockets/mch_05_serverclient/dist/README.TXT b/Pro Java 7 NIO.2/Chapter08/sockets/mch_05_serverclient/dist/README.TXT new file mode 100644 index 0000000..579881f --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter08/sockets/mch_05_serverclient/dist/README.TXT @@ -0,0 +1,32 @@ +======================== +BUILD OUTPUT DESCRIPTION +======================== + +When you build an Java application project that has a main class, the IDE +automatically copies all of the JAR +files on the projects classpath to your projects dist/lib folder. The IDE +also adds each of the JAR files to the Class-Path element in the application +JAR files manifest file (MANIFEST.MF). + +To run the project from the command line, go to the dist folder and +type the following: + +java -jar "mch_05_serverclient.jar" + +To distribute this project, zip up the dist folder (including the lib folder) +and distribute the ZIP file. + +Notes: + +* If two JAR files on the project classpath have the same name, only the first +JAR file is copied to the lib folder. +* Only JAR files are copied to the lib folder. +If the classpath contains other types of files or folders, these files (folders) +are not copied. +* If a library on the projects classpath also has a Class-Path element +specified in the manifest,the content of the Class-Path element has to be on +the projects runtime path. +* To set a main class in a standard Java project, right-click the project node +in the Projects window and choose Properties. Then click Run and enter the +class name in the Main Class field. Alternatively, you can manually type the +class name in the manifest Main-Class element. diff --git a/Pro Java 7 NIO.2/Chapter08/sockets/mch_05_serverclient/dist/mch_05_serverclient.jar b/Pro Java 7 NIO.2/Chapter08/sockets/mch_05_serverclient/dist/mch_05_serverclient.jar new file mode 100644 index 0000000..526690b Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter08/sockets/mch_05_serverclient/dist/mch_05_serverclient.jar differ diff --git a/Pro Java 7 NIO.2/Chapter08/sockets/mch_05_serverclient/manifest.mf b/Pro Java 7 NIO.2/Chapter08/sockets/mch_05_serverclient/manifest.mf new file mode 100644 index 0000000..328e8e5 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter08/sockets/mch_05_serverclient/manifest.mf @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +X-COMMENT: Main-Class will be added automatically by build + diff --git a/Pro Java 7 NIO.2/Chapter08/sockets/mch_05_serverclient/nbproject/build-impl.xml b/Pro Java 7 NIO.2/Chapter08/sockets/mch_05_serverclient/nbproject/build-impl.xml new file mode 100644 index 0000000..b4b2f25 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter08/sockets/mch_05_serverclient/nbproject/build-impl.xml @@ -0,0 +1,1041 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set src.dir + Must set test.src.dir + Must set build.dir + Must set dist.dir + Must set build.classes.dir + Must set dist.javadoc.dir + Must set build.test.classes.dir + Must set build.test.results.dir + Must set build.classes.excludes + Must set dist.jar + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set JVM to use for profiling in profiler.info.jvm + Must set profiler agent JVM arguments in profiler.info.jvmargs.agent + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + + + + + + java -cp "${run.classpath.with.dist.jar}" ${main.class} + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + java -jar "${dist.jar.resolved}" + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set run.class + + + + Must select one file in the IDE or set run.class + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set debug.class + + + + + Must select one file in the IDE or set debug.class + + + + + Must set fix.includes + + + + + + + + + + + + + + + + + Must select one file in the IDE or set profile.class + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + Some tests failed; see details above. + + + + + + + + + Must select some files in the IDE or set test.includes + + + + Some tests failed; see details above. + + + + + Must select one file in the IDE or set test.class + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Pro Java 7 NIO.2/Chapter08/sockets/mch_05_serverclient/nbproject/genfiles.properties b/Pro Java 7 NIO.2/Chapter08/sockets/mch_05_serverclient/nbproject/genfiles.properties new file mode 100644 index 0000000..dacf35b --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter08/sockets/mch_05_serverclient/nbproject/genfiles.properties @@ -0,0 +1,8 @@ +build.xml.data.CRC32=31717baa +build.xml.script.CRC32=7b4cf75c +build.xml.stylesheet.CRC32=28e38971@1.43.1.45 +# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. +# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. +nbproject/build-impl.xml.data.CRC32=31717baa +nbproject/build-impl.xml.script.CRC32=37cfbd46 +nbproject/build-impl.xml.stylesheet.CRC32=0c01fd8e@1.43.1.45 diff --git a/Pro Java 7 NIO.2/Chapter08/sockets/mch_05_serverclient/nbproject/private/config.properties b/Pro Java 7 NIO.2/Chapter08/sockets/mch_05_serverclient/nbproject/private/config.properties new file mode 100644 index 0000000..e69de29 diff --git a/Pro Java 7 NIO.2/Chapter08/sockets/mch_05_serverclient/nbproject/private/private.properties b/Pro Java 7 NIO.2/Chapter08/sockets/mch_05_serverclient/nbproject/private/private.properties new file mode 100644 index 0000000..a5ab360 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter08/sockets/mch_05_serverclient/nbproject/private/private.properties @@ -0,0 +1,6 @@ +compile.on.save=true +do.depend=false +do.jar=true +javac.debug=true +javadoc.preview=true +user.properties.file=C:\\Users\\Leo\\.netbeans\\7.0\\build.properties diff --git a/Pro Java 7 NIO.2/Chapter08/sockets/mch_05_serverclient/nbproject/private/private.xml b/Pro Java 7 NIO.2/Chapter08/sockets/mch_05_serverclient/nbproject/private/private.xml new file mode 100644 index 0000000..c1f155a --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter08/sockets/mch_05_serverclient/nbproject/private/private.xml @@ -0,0 +1,4 @@ + + + + diff --git a/Pro Java 7 NIO.2/Chapter08/sockets/mch_05_serverclient/nbproject/project.properties b/Pro Java 7 NIO.2/Chapter08/sockets/mch_05_serverclient/nbproject/project.properties new file mode 100644 index 0000000..30bde50 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter08/sockets/mch_05_serverclient/nbproject/project.properties @@ -0,0 +1,72 @@ +annotation.processing.enabled=true +annotation.processing.enabled.in.editor=false +annotation.processing.run.all.processors=true +annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output +application.title=mch_05_serverclient +application.vendor=Leo +build.classes.dir=${build.dir}/classes +build.classes.excludes=**/*.java,**/*.form +# This directory is removed when the project is cleaned: +build.dir=build +build.generated.dir=${build.dir}/generated +build.generated.sources.dir=${build.dir}/generated-sources +# Only compile against the classpath explicitly listed here: +build.sysclasspath=ignore +build.test.classes.dir=${build.dir}/test/classes +build.test.results.dir=${build.dir}/test/results +# Uncomment to specify the preferred debugger connection transport: +#debug.transport=dt_socket +debug.classpath=\ + ${run.classpath} +debug.test.classpath=\ + ${run.test.classpath} +# This directory is removed when the project is cleaned: +dist.dir=dist +dist.jar=${dist.dir}/mch_05_serverclient.jar +dist.javadoc.dir=${dist.dir}/javadoc +endorsed.classpath= +excludes= +includes=** +jar.compress=false +javac.classpath= +# Space-separated list of extra javac options +javac.compilerargs= +javac.deprecation=false +javac.processorpath=\ + ${javac.classpath} +javac.source=1.7 +javac.target=1.7 +javac.test.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +javac.test.processorpath=\ + ${javac.test.classpath} +javadoc.additionalparam= +javadoc.author=false +javadoc.encoding=${source.encoding} +javadoc.noindex=false +javadoc.nonavbar=false +javadoc.notree=false +javadoc.private=false +javadoc.splitindex=true +javadoc.use=true +javadoc.version=false +javadoc.windowtitle= +main.class=mch_05_serverclient.Main +manifest.file=manifest.mf +meta.inf.dir=${src.dir}/META-INF +mkdist.disabled=false +platform.active=default_platform +run.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +# Space-separated list of JVM arguments used when running the project +# (you may also define separate properties like run-sys-prop.name=value instead of -Dname=value +# or test-sys-prop.name=value to set system properties for unit tests): +run.jvmargs= +run.test.classpath=\ + ${javac.test.classpath}:\ + ${build.test.classes.dir} +source.encoding=UTF-8 +src.dir=src +test.src.dir=test diff --git a/Pro Java 7 NIO.2/Chapter08/sockets/mch_05_serverclient/nbproject/project.xml b/Pro Java 7 NIO.2/Chapter08/sockets/mch_05_serverclient/nbproject/project.xml new file mode 100644 index 0000000..ab7c0be --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter08/sockets/mch_05_serverclient/nbproject/project.xml @@ -0,0 +1,15 @@ + + + org.netbeans.modules.java.j2seproject + + + mch_05_serverclient + + + + + + + + + diff --git a/Pro Java 7 NIO.2/Chapter08/sockets/mch_05_serverclient/src/mch_05_serverclient/Main.java b/Pro Java 7 NIO.2/Chapter08/sockets/mch_05_serverclient/src/mch_05_serverclient/Main.java new file mode 100644 index 0000000..b26c0ed --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter08/sockets/mch_05_serverclient/src/mch_05_serverclient/Main.java @@ -0,0 +1,123 @@ +package mch_05_serverclient; + +import java.io.IOException; +import java.net.StandardSocketOptions; +import java.nio.ByteBuffer; +import java.nio.CharBuffer; +import java.nio.channels.SelectionKey; +import java.nio.channels.Selector; +import java.nio.channels.SocketChannel; +import java.nio.charset.Charset; +import java.nio.charset.CharsetDecoder; +import java.util.Iterator; +import java.util.Random; +import java.util.Set; + +/** + * + * @author Apress + */ +public class Main { + + public static void main(String[] args) { + + final int DEFAULT_PORT = 5555; + final String IP = "127.0.0.1"; + + ByteBuffer buffer = ByteBuffer.allocateDirect(2 * 1024); + ByteBuffer randomBuffer; + CharBuffer charBuffer; + + Charset charset = Charset.defaultCharset(); + CharsetDecoder decoder = charset.newDecoder(); + + //open Selector and ServerSocketChannel by calling the open() method + try (Selector selector = Selector.open(); + SocketChannel socketChannel = SocketChannel.open()) { + + //check that both of them were successfully opened + if ((socketChannel.isOpen()) && (selector.isOpen())) { + + //configure non-blocking mode + socketChannel.configureBlocking(false); + + //set some options + socketChannel.setOption(StandardSocketOptions.SO_RCVBUF, 128 * 1024); + socketChannel.setOption(StandardSocketOptions.SO_SNDBUF, 128 * 1024); + socketChannel.setOption(StandardSocketOptions.SO_KEEPALIVE, true); + + //register the current channel with the given selector + socketChannel.register(selector, SelectionKey.OP_CONNECT); + + //connect to remote host + socketChannel.connect(new java.net.InetSocketAddress(IP, DEFAULT_PORT)); + + System.out.println("Localhost: " + socketChannel.getLocalAddress()); + + //waiting for the connection + while (selector.select(1000) > 0) { + + //get keys + Set keys = selector.selectedKeys(); + Iterator its = keys.iterator(); + + //process each key + while (its.hasNext()) { + SelectionKey key = (SelectionKey) its.next(); + + //remove the current key + its.remove(); + + //get the socket channel for this key + try (SocketChannel keySocketChannel = (SocketChannel) key.channel()) { + + //attempt a connection + if (key.isConnectable()) { + + //signal connection success + System.out.println("I am connected!"); + + //close pendent connections + if (keySocketChannel.isConnectionPending()) { + keySocketChannel.finishConnect(); + } + + //read/write from/to server + while (keySocketChannel.read(buffer) != -1) { + + buffer.flip(); + + charBuffer = decoder.decode(buffer); + System.out.println(charBuffer.toString()); + + if (buffer.hasRemaining()) { + buffer.compact(); + } else { + buffer.clear(); + } + + int r = new Random().nextInt(100); + if (r == 50) { + System.out.println("50 was generated! Close the socket channel!"); + break; + } else { + randomBuffer = ByteBuffer.wrap("Random number:".concat(String.valueOf(r)).getBytes("UTF-8")); + keySocketChannel.write(randomBuffer); + } + } + } + } catch (IOException ex) { + System.err.println(ex); + } + } + } + } else { + System.out.println("The socket channel or selector cannot be opened!"); + } + } catch (IOException ex) { + System.err.println(ex); + } + + + } +} diff --git a/Pro Java 7 NIO.2/Chapter08/sockets/mch_05_serversocket/build.xml b/Pro Java 7 NIO.2/Chapter08/sockets/mch_05_serversocket/build.xml new file mode 100644 index 0000000..9087227 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter08/sockets/mch_05_serversocket/build.xml @@ -0,0 +1,74 @@ + + + + + + + + + + + Builds, tests, and runs the project mch_05_serversocket. + + + diff --git a/Pro Java 7 NIO.2/Chapter08/sockets/mch_05_serversocket/build/built-jar.properties b/Pro Java 7 NIO.2/Chapter08/sockets/mch_05_serversocket/build/built-jar.properties new file mode 100644 index 0000000..f175e9f --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter08/sockets/mch_05_serversocket/build/built-jar.properties @@ -0,0 +1,4 @@ +#Sun, 30 Oct 2011 07:58:49 +0200 + + +C\:\\NIO\\sockets\\mch_05_serversocket= diff --git a/Pro Java 7 NIO.2/Chapter08/sockets/mch_05_serversocket/build/classes/mch_05_serversocket/Main.class b/Pro Java 7 NIO.2/Chapter08/sockets/mch_05_serversocket/build/classes/mch_05_serversocket/Main.class new file mode 100644 index 0000000..d2444a4 Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter08/sockets/mch_05_serversocket/build/classes/mch_05_serversocket/Main.class differ diff --git a/Pro Java 7 NIO.2/Chapter08/sockets/mch_05_serversocket/dist/README.TXT b/Pro Java 7 NIO.2/Chapter08/sockets/mch_05_serversocket/dist/README.TXT new file mode 100644 index 0000000..de6bb69 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter08/sockets/mch_05_serversocket/dist/README.TXT @@ -0,0 +1,32 @@ +======================== +BUILD OUTPUT DESCRIPTION +======================== + +When you build an Java application project that has a main class, the IDE +automatically copies all of the JAR +files on the projects classpath to your projects dist/lib folder. The IDE +also adds each of the JAR files to the Class-Path element in the application +JAR files manifest file (MANIFEST.MF). + +To run the project from the command line, go to the dist folder and +type the following: + +java -jar "mch_05_serversocket.jar" + +To distribute this project, zip up the dist folder (including the lib folder) +and distribute the ZIP file. + +Notes: + +* If two JAR files on the project classpath have the same name, only the first +JAR file is copied to the lib folder. +* Only JAR files are copied to the lib folder. +If the classpath contains other types of files or folders, these files (folders) +are not copied. +* If a library on the projects classpath also has a Class-Path element +specified in the manifest,the content of the Class-Path element has to be on +the projects runtime path. +* To set a main class in a standard Java project, right-click the project node +in the Projects window and choose Properties. Then click Run and enter the +class name in the Main Class field. Alternatively, you can manually type the +class name in the manifest Main-Class element. diff --git a/Pro Java 7 NIO.2/Chapter08/sockets/mch_05_serversocket/dist/mch_05_serversocket.jar b/Pro Java 7 NIO.2/Chapter08/sockets/mch_05_serversocket/dist/mch_05_serversocket.jar new file mode 100644 index 0000000..0ac406d Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter08/sockets/mch_05_serversocket/dist/mch_05_serversocket.jar differ diff --git a/Pro Java 7 NIO.2/Chapter08/sockets/mch_05_serversocket/manifest.mf b/Pro Java 7 NIO.2/Chapter08/sockets/mch_05_serversocket/manifest.mf new file mode 100644 index 0000000..328e8e5 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter08/sockets/mch_05_serversocket/manifest.mf @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +X-COMMENT: Main-Class will be added automatically by build + diff --git a/Pro Java 7 NIO.2/Chapter08/sockets/mch_05_serversocket/nbproject/build-impl.xml b/Pro Java 7 NIO.2/Chapter08/sockets/mch_05_serversocket/nbproject/build-impl.xml new file mode 100644 index 0000000..a8c4868 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter08/sockets/mch_05_serversocket/nbproject/build-impl.xml @@ -0,0 +1,1041 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set src.dir + Must set test.src.dir + Must set build.dir + Must set dist.dir + Must set build.classes.dir + Must set dist.javadoc.dir + Must set build.test.classes.dir + Must set build.test.results.dir + Must set build.classes.excludes + Must set dist.jar + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set JVM to use for profiling in profiler.info.jvm + Must set profiler agent JVM arguments in profiler.info.jvmargs.agent + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + + + + + + java -cp "${run.classpath.with.dist.jar}" ${main.class} + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + java -jar "${dist.jar.resolved}" + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set run.class + + + + Must select one file in the IDE or set run.class + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set debug.class + + + + + Must select one file in the IDE or set debug.class + + + + + Must set fix.includes + + + + + + + + + + + + + + + + + Must select one file in the IDE or set profile.class + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + Some tests failed; see details above. + + + + + + + + + Must select some files in the IDE or set test.includes + + + + Some tests failed; see details above. + + + + + Must select one file in the IDE or set test.class + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Pro Java 7 NIO.2/Chapter08/sockets/mch_05_serversocket/nbproject/genfiles.properties b/Pro Java 7 NIO.2/Chapter08/sockets/mch_05_serversocket/nbproject/genfiles.properties new file mode 100644 index 0000000..d0fc29d --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter08/sockets/mch_05_serversocket/nbproject/genfiles.properties @@ -0,0 +1,8 @@ +build.xml.data.CRC32=3b71cd4b +build.xml.script.CRC32=420c28de +build.xml.stylesheet.CRC32=28e38971@1.43.1.45 +# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. +# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. +nbproject/build-impl.xml.data.CRC32=3b71cd4b +nbproject/build-impl.xml.script.CRC32=229649d7 +nbproject/build-impl.xml.stylesheet.CRC32=0c01fd8e@1.43.1.45 diff --git a/Pro Java 7 NIO.2/Chapter08/sockets/mch_05_serversocket/nbproject/private/config.properties b/Pro Java 7 NIO.2/Chapter08/sockets/mch_05_serversocket/nbproject/private/config.properties new file mode 100644 index 0000000..e69de29 diff --git a/Pro Java 7 NIO.2/Chapter08/sockets/mch_05_serversocket/nbproject/private/private.properties b/Pro Java 7 NIO.2/Chapter08/sockets/mch_05_serversocket/nbproject/private/private.properties new file mode 100644 index 0000000..a5ab360 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter08/sockets/mch_05_serversocket/nbproject/private/private.properties @@ -0,0 +1,6 @@ +compile.on.save=true +do.depend=false +do.jar=true +javac.debug=true +javadoc.preview=true +user.properties.file=C:\\Users\\Leo\\.netbeans\\7.0\\build.properties diff --git a/Pro Java 7 NIO.2/Chapter08/sockets/mch_05_serversocket/nbproject/private/private.xml b/Pro Java 7 NIO.2/Chapter08/sockets/mch_05_serversocket/nbproject/private/private.xml new file mode 100644 index 0000000..c1f155a --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter08/sockets/mch_05_serversocket/nbproject/private/private.xml @@ -0,0 +1,4 @@ + + + + diff --git a/Pro Java 7 NIO.2/Chapter08/sockets/mch_05_serversocket/nbproject/project.properties b/Pro Java 7 NIO.2/Chapter08/sockets/mch_05_serversocket/nbproject/project.properties new file mode 100644 index 0000000..b7b0ad3 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter08/sockets/mch_05_serversocket/nbproject/project.properties @@ -0,0 +1,72 @@ +annotation.processing.enabled=true +annotation.processing.enabled.in.editor=false +annotation.processing.run.all.processors=true +annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output +application.title=mch_05_serversocket +application.vendor=Leo +build.classes.dir=${build.dir}/classes +build.classes.excludes=**/*.java,**/*.form +# This directory is removed when the project is cleaned: +build.dir=build +build.generated.dir=${build.dir}/generated +build.generated.sources.dir=${build.dir}/generated-sources +# Only compile against the classpath explicitly listed here: +build.sysclasspath=ignore +build.test.classes.dir=${build.dir}/test/classes +build.test.results.dir=${build.dir}/test/results +# Uncomment to specify the preferred debugger connection transport: +#debug.transport=dt_socket +debug.classpath=\ + ${run.classpath} +debug.test.classpath=\ + ${run.test.classpath} +# This directory is removed when the project is cleaned: +dist.dir=dist +dist.jar=${dist.dir}/mch_05_serversocket.jar +dist.javadoc.dir=${dist.dir}/javadoc +endorsed.classpath= +excludes= +includes=** +jar.compress=false +javac.classpath= +# Space-separated list of extra javac options +javac.compilerargs= +javac.deprecation=false +javac.processorpath=\ + ${javac.classpath} +javac.source=1.7 +javac.target=1.7 +javac.test.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +javac.test.processorpath=\ + ${javac.test.classpath} +javadoc.additionalparam= +javadoc.author=false +javadoc.encoding=${source.encoding} +javadoc.noindex=false +javadoc.nonavbar=false +javadoc.notree=false +javadoc.private=false +javadoc.splitindex=true +javadoc.use=true +javadoc.version=false +javadoc.windowtitle= +main.class=mch_05_serversocket.Main +manifest.file=manifest.mf +meta.inf.dir=${src.dir}/META-INF +mkdist.disabled=false +platform.active=default_platform +run.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +# Space-separated list of JVM arguments used when running the project +# (you may also define separate properties like run-sys-prop.name=value instead of -Dname=value +# or test-sys-prop.name=value to set system properties for unit tests): +run.jvmargs= +run.test.classpath=\ + ${javac.test.classpath}:\ + ${build.test.classes.dir} +source.encoding=UTF-8 +src.dir=src +test.src.dir=test diff --git a/Pro Java 7 NIO.2/Chapter08/sockets/mch_05_serversocket/nbproject/project.xml b/Pro Java 7 NIO.2/Chapter08/sockets/mch_05_serversocket/nbproject/project.xml new file mode 100644 index 0000000..234e2af --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter08/sockets/mch_05_serversocket/nbproject/project.xml @@ -0,0 +1,15 @@ + + + org.netbeans.modules.java.j2seproject + + + mch_05_serversocket + + + + + + + + + diff --git a/Pro Java 7 NIO.2/Chapter08/sockets/mch_05_serversocket/src/mch_05_serversocket/Main.java b/Pro Java 7 NIO.2/Chapter08/sockets/mch_05_serversocket/src/mch_05_serversocket/Main.java new file mode 100644 index 0000000..d07127b --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter08/sockets/mch_05_serversocket/src/mch_05_serversocket/Main.java @@ -0,0 +1,167 @@ +package mch_05_serversocket; + +import java.io.IOException; +import java.net.InetSocketAddress; +import java.net.StandardSocketOptions; +import java.nio.ByteBuffer; +import java.nio.channels.SelectionKey; +import java.nio.channels.Selector; +import java.nio.channels.ServerSocketChannel; +import java.nio.channels.SocketChannel; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; + +/** + * + * @author Apress + */ +public class Main { + + private Map> keepDataTrack = new HashMap<>(); + private ByteBuffer buffer = ByteBuffer.allocate(2 * 1024); + + private void startEchoServer() { + + final int DEFAULT_PORT = 5555; + + //open Selector and ServerSocketChannel by calling the open() method + try (Selector selector = Selector.open(); + ServerSocketChannel serverSocketChannel = ServerSocketChannel.open()) { + + //check that both of them were successfully opened + if ((serverSocketChannel.isOpen()) && (selector.isOpen())) { + + //configure non-blocking mode + serverSocketChannel.configureBlocking(false); + + //set some options + serverSocketChannel.setOption(StandardSocketOptions.SO_RCVBUF, 256 * 1024); + serverSocketChannel.setOption(StandardSocketOptions.SO_REUSEADDR, true); + + //bind the server socket channel to port + serverSocketChannel.bind(new InetSocketAddress(DEFAULT_PORT)); + + //register the current channel with the given selector + serverSocketChannel.register(selector, SelectionKey.OP_ACCEPT); + + //display a waiting message while ... waiting! + System.out.println("Waiting for connections ..."); + + while (true) { + //wait for incomming events + selector.select(); + + //there is something to process on selected keys + Iterator keys = selector.selectedKeys().iterator(); + + while (keys.hasNext()) { + SelectionKey key = (SelectionKey) keys.next(); + + //prevent the same key from coming up again + keys.remove(); + + if (!key.isValid()) { + continue; + } + + if (key.isAcceptable()) { + acceptOP(key, selector); + } else if (key.isReadable()) { + this.readOP(key); + } else if (key.isWritable()) { + this.writeOP(key); + } + } + } + + } else { + System.out.println("The server socket channel or selector cannot be opened!"); + } + } catch (IOException ex) { + System.err.println(ex); + } + } + + //isAcceptable returned true + private void acceptOP(SelectionKey key, Selector selector) throws IOException { + + ServerSocketChannel serverChannel = (ServerSocketChannel) key.channel(); + SocketChannel socketChannel = serverChannel.accept(); + socketChannel.configureBlocking(false); + + System.out.println("Incoming connection from: " + socketChannel.getRemoteAddress()); + + // write an welcome message + socketChannel.write(ByteBuffer.wrap("Hello!\n".getBytes("UTF-8"))); + + //register channel with selector for further I/O + keepDataTrack.put(socketChannel, new ArrayList()); + socketChannel.register(selector, SelectionKey.OP_READ); + } + + //isReadable returned true + private void readOP(SelectionKey key) { + try { + SocketChannel socketChannel = (SocketChannel) key.channel(); + + buffer.clear(); + + int numRead = -1; + try { + numRead = socketChannel.read(buffer); + } catch (IOException e) { + System.err.println("Cannot read error!"); + } + + if (numRead == -1) { + this.keepDataTrack.remove(socketChannel); + System.out.println("Connection closed by: " + socketChannel.getRemoteAddress()); + socketChannel.close(); + key.cancel(); + return; + } + + byte[] data = new byte[numRead]; + System.arraycopy(buffer.array(), 0, data, 0, numRead); + System.out.println(new String(data, "UTF-8") + " from " + socketChannel.getRemoteAddress()); + + // write back to client + doEchoJob(key, data); + } catch (IOException ex) { + System.err.println(ex); + } + } + + //isWritable returned true + private void writeOP(SelectionKey key) throws IOException { + + SocketChannel socketChannel = (SocketChannel) key.channel(); + + List channelData = keepDataTrack.get(socketChannel); + Iterator its = channelData.iterator(); + + while (its.hasNext()) { + byte[] it = its.next(); + its.remove(); + socketChannel.write(ByteBuffer.wrap(it)); + } + + key.interestOps(SelectionKey.OP_READ); + } + + private void doEchoJob(SelectionKey key, byte[] data) { + SocketChannel socketChannel = (SocketChannel) key.channel(); + List channelData = keepDataTrack.get(socketChannel); + channelData.add(data); + + key.interestOps(SelectionKey.OP_WRITE); + } + + public static void main(String[] args) { + Main main = new Main(); + main.startEchoServer(); + } +} diff --git a/Pro Java 7 NIO.2/Chapter09/async/mch_01/build.xml b/Pro Java 7 NIO.2/Chapter09/async/mch_01/build.xml new file mode 100644 index 0000000..e63e6c0 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter09/async/mch_01/build.xml @@ -0,0 +1,74 @@ + + + + + + + + + + + Builds, tests, and runs the project mch_01. + + + diff --git a/Pro Java 7 NIO.2/Chapter09/async/mch_01/build/built-jar.properties b/Pro Java 7 NIO.2/Chapter09/async/mch_01/build/built-jar.properties new file mode 100644 index 0000000..e8a71db --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter09/async/mch_01/build/built-jar.properties @@ -0,0 +1,4 @@ +#Thu, 03 Nov 2011 07:01:35 +0200 + + +C\:\\NIO\\async\\mch_01= diff --git a/Pro Java 7 NIO.2/Chapter09/async/mch_01/build/classes/.netbeans_automatic_build b/Pro Java 7 NIO.2/Chapter09/async/mch_01/build/classes/.netbeans_automatic_build new file mode 100644 index 0000000..e69de29 diff --git a/Pro Java 7 NIO.2/Chapter09/async/mch_01/build/classes/mch_01/Main.class b/Pro Java 7 NIO.2/Chapter09/async/mch_01/build/classes/mch_01/Main.class new file mode 100644 index 0000000..b334d2a Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter09/async/mch_01/build/classes/mch_01/Main.class differ diff --git a/Pro Java 7 NIO.2/Chapter09/async/mch_01/dist/README.TXT b/Pro Java 7 NIO.2/Chapter09/async/mch_01/dist/README.TXT new file mode 100644 index 0000000..8b28bca --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter09/async/mch_01/dist/README.TXT @@ -0,0 +1,32 @@ +======================== +BUILD OUTPUT DESCRIPTION +======================== + +When you build an Java application project that has a main class, the IDE +automatically copies all of the JAR +files on the projects classpath to your projects dist/lib folder. The IDE +also adds each of the JAR files to the Class-Path element in the application +JAR files manifest file (MANIFEST.MF). + +To run the project from the command line, go to the dist folder and +type the following: + +java -jar "mch_01.jar" + +To distribute this project, zip up the dist folder (including the lib folder) +and distribute the ZIP file. + +Notes: + +* If two JAR files on the project classpath have the same name, only the first +JAR file is copied to the lib folder. +* Only JAR files are copied to the lib folder. +If the classpath contains other types of files or folders, these files (folders) +are not copied. +* If a library on the projects classpath also has a Class-Path element +specified in the manifest,the content of the Class-Path element has to be on +the projects runtime path. +* To set a main class in a standard Java project, right-click the project node +in the Projects window and choose Properties. Then click Run and enter the +class name in the Main Class field. Alternatively, you can manually type the +class name in the manifest Main-Class element. diff --git a/Pro Java 7 NIO.2/Chapter09/async/mch_01/dist/mch_01.jar b/Pro Java 7 NIO.2/Chapter09/async/mch_01/dist/mch_01.jar new file mode 100644 index 0000000..aa8b33c Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter09/async/mch_01/dist/mch_01.jar differ diff --git a/Pro Java 7 NIO.2/Chapter09/async/mch_01/manifest.mf b/Pro Java 7 NIO.2/Chapter09/async/mch_01/manifest.mf new file mode 100644 index 0000000..328e8e5 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter09/async/mch_01/manifest.mf @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +X-COMMENT: Main-Class will be added automatically by build + diff --git a/Pro Java 7 NIO.2/Chapter09/async/mch_01/nbproject/build-impl.xml b/Pro Java 7 NIO.2/Chapter09/async/mch_01/nbproject/build-impl.xml new file mode 100644 index 0000000..2f8c988 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter09/async/mch_01/nbproject/build-impl.xml @@ -0,0 +1,1041 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set src.dir + Must set test.src.dir + Must set build.dir + Must set dist.dir + Must set build.classes.dir + Must set dist.javadoc.dir + Must set build.test.classes.dir + Must set build.test.results.dir + Must set build.classes.excludes + Must set dist.jar + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set JVM to use for profiling in profiler.info.jvm + Must set profiler agent JVM arguments in profiler.info.jvmargs.agent + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + + + + + + java -cp "${run.classpath.with.dist.jar}" ${main.class} + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + java -jar "${dist.jar.resolved}" + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set run.class + + + + Must select one file in the IDE or set run.class + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set debug.class + + + + + Must select one file in the IDE or set debug.class + + + + + Must set fix.includes + + + + + + + + + + + + + + + + + Must select one file in the IDE or set profile.class + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + Some tests failed; see details above. + + + + + + + + + Must select some files in the IDE or set test.includes + + + + Some tests failed; see details above. + + + + + Must select one file in the IDE or set test.class + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Pro Java 7 NIO.2/Chapter09/async/mch_01/nbproject/genfiles.properties b/Pro Java 7 NIO.2/Chapter09/async/mch_01/nbproject/genfiles.properties new file mode 100644 index 0000000..ebcad72 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter09/async/mch_01/nbproject/genfiles.properties @@ -0,0 +1,8 @@ +build.xml.data.CRC32=69e35cdd +build.xml.script.CRC32=e5ad310e +build.xml.stylesheet.CRC32=28e38971@1.43.1.45 +# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. +# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. +nbproject/build-impl.xml.data.CRC32=69e35cdd +nbproject/build-impl.xml.script.CRC32=96f81355 +nbproject/build-impl.xml.stylesheet.CRC32=0c01fd8e@1.43.1.45 diff --git a/Pro Java 7 NIO.2/Chapter09/async/mch_01/nbproject/private/config.properties b/Pro Java 7 NIO.2/Chapter09/async/mch_01/nbproject/private/config.properties new file mode 100644 index 0000000..e69de29 diff --git a/Pro Java 7 NIO.2/Chapter09/async/mch_01/nbproject/private/private.properties b/Pro Java 7 NIO.2/Chapter09/async/mch_01/nbproject/private/private.properties new file mode 100644 index 0000000..a5ab360 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter09/async/mch_01/nbproject/private/private.properties @@ -0,0 +1,6 @@ +compile.on.save=true +do.depend=false +do.jar=true +javac.debug=true +javadoc.preview=true +user.properties.file=C:\\Users\\Leo\\.netbeans\\7.0\\build.properties diff --git a/Pro Java 7 NIO.2/Chapter09/async/mch_01/nbproject/private/private.xml b/Pro Java 7 NIO.2/Chapter09/async/mch_01/nbproject/private/private.xml new file mode 100644 index 0000000..c1f155a --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter09/async/mch_01/nbproject/private/private.xml @@ -0,0 +1,4 @@ + + + + diff --git a/Pro Java 7 NIO.2/Chapter09/async/mch_01/nbproject/project.properties b/Pro Java 7 NIO.2/Chapter09/async/mch_01/nbproject/project.properties new file mode 100644 index 0000000..47b5933 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter09/async/mch_01/nbproject/project.properties @@ -0,0 +1,72 @@ +annotation.processing.enabled=true +annotation.processing.enabled.in.editor=false +annotation.processing.run.all.processors=true +annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output +application.title=mch_01 +application.vendor=Leo +build.classes.dir=${build.dir}/classes +build.classes.excludes=**/*.java,**/*.form +# This directory is removed when the project is cleaned: +build.dir=build +build.generated.dir=${build.dir}/generated +build.generated.sources.dir=${build.dir}/generated-sources +# Only compile against the classpath explicitly listed here: +build.sysclasspath=ignore +build.test.classes.dir=${build.dir}/test/classes +build.test.results.dir=${build.dir}/test/results +# Uncomment to specify the preferred debugger connection transport: +#debug.transport=dt_socket +debug.classpath=\ + ${run.classpath} +debug.test.classpath=\ + ${run.test.classpath} +# This directory is removed when the project is cleaned: +dist.dir=dist +dist.jar=${dist.dir}/mch_01.jar +dist.javadoc.dir=${dist.dir}/javadoc +endorsed.classpath= +excludes= +includes=** +jar.compress=false +javac.classpath= +# Space-separated list of extra javac options +javac.compilerargs= +javac.deprecation=false +javac.processorpath=\ + ${javac.classpath} +javac.source=1.7 +javac.target=1.7 +javac.test.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +javac.test.processorpath=\ + ${javac.test.classpath} +javadoc.additionalparam= +javadoc.author=false +javadoc.encoding=${source.encoding} +javadoc.noindex=false +javadoc.nonavbar=false +javadoc.notree=false +javadoc.private=false +javadoc.splitindex=true +javadoc.use=true +javadoc.version=false +javadoc.windowtitle= +main.class=mch_01.Main +manifest.file=manifest.mf +meta.inf.dir=${src.dir}/META-INF +mkdist.disabled=false +platform.active=default_platform +run.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +# Space-separated list of JVM arguments used when running the project +# (you may also define separate properties like run-sys-prop.name=value instead of -Dname=value +# or test-sys-prop.name=value to set system properties for unit tests): +run.jvmargs= +run.test.classpath=\ + ${javac.test.classpath}:\ + ${build.test.classes.dir} +source.encoding=UTF-8 +src.dir=src +test.src.dir=test diff --git a/Pro Java 7 NIO.2/Chapter09/async/mch_01/nbproject/project.xml b/Pro Java 7 NIO.2/Chapter09/async/mch_01/nbproject/project.xml new file mode 100644 index 0000000..243b345 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter09/async/mch_01/nbproject/project.xml @@ -0,0 +1,15 @@ + + + org.netbeans.modules.java.j2seproject + + + mch_01 + + + + + + + + + diff --git a/Pro Java 7 NIO.2/Chapter09/async/mch_01/src/mch_01/Main.java b/Pro Java 7 NIO.2/Chapter09/async/mch_01/src/mch_01/Main.java new file mode 100644 index 0000000..15f2c6f --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter09/async/mch_01/src/mch_01/Main.java @@ -0,0 +1,47 @@ +package mch_01; + +import java.nio.ByteBuffer; +import java.nio.channels.AsynchronousFileChannel; +import java.nio.channels.FileLock; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.nio.file.StandardOpenOption; +import java.util.concurrent.Future; + +/** + * + * @author Apress + */ +public class Main { + + public static void main(String[] args) { + + ByteBuffer buffer = ByteBuffer.wrap("Argentines At Home In Buenos Aires Cathedral\n The Copa Claro is the third stop of the four-tournament Latin American swing, and is contested on clay at the Buenos Aires Lawn Tennis Club, known as the Cathedral of Argentinean tennis. An Argentine has reached the final in nine of the 11 editions of the ATP World Tour 250 tournament, with champions including Guillermo Coria, Gaston Gaudio, Juan Monaco and David Nalbandian.".getBytes()); + + Path path = Paths.get("C:/rafaelnadal/tournaments/2009", "CopaClaro.txt"); + try (AsynchronousFileChannel asynchronousFileChannel = AsynchronousFileChannel.open(path, StandardOpenOption.WRITE)) { + + Future featureLock = asynchronousFileChannel.lock(); + System.out.println("Waiting the file to be locked ..."); + FileLock lock = featureLock.get(); + //or, use shortcut + //FileLock lock = asynchronousFileChannel.lock().get(); + + if (lock.isValid()) { + Future featureWrite = asynchronousFileChannel.write(buffer, 0); + System.out.println("Waiting the bytes to be written ..."); + int written = featureWrite.get(); + //or, use shorcut + //int written = asynchronousFileChannel.write(buffer,0).get(); + + System.out.println("I written " + written + " bytes into " + path.getFileName() + " locked file!"); + + lock.release(); + } + + } catch (Exception ex) { + System.err.println(ex); + } + + } +} diff --git a/Pro Java 7 NIO.2/Chapter09/async/mch_02/build.xml b/Pro Java 7 NIO.2/Chapter09/async/mch_02/build.xml new file mode 100644 index 0000000..3864d8f --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter09/async/mch_02/build.xml @@ -0,0 +1,74 @@ + + + + + + + + + + + Builds, tests, and runs the project mch_02. + + + diff --git a/Pro Java 7 NIO.2/Chapter09/async/mch_02/build/built-jar.properties b/Pro Java 7 NIO.2/Chapter09/async/mch_02/build/built-jar.properties new file mode 100644 index 0000000..1e0112c --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter09/async/mch_02/build/built-jar.properties @@ -0,0 +1,4 @@ +#Thu, 03 Nov 2011 07:16:04 +0200 + + +C\:\\NIO\\async\\mch_02= diff --git a/Pro Java 7 NIO.2/Chapter09/async/mch_02/build/classes/.netbeans_automatic_build b/Pro Java 7 NIO.2/Chapter09/async/mch_02/build/classes/.netbeans_automatic_build new file mode 100644 index 0000000..e69de29 diff --git a/Pro Java 7 NIO.2/Chapter09/async/mch_02/build/classes/mch_02/Main$1.class b/Pro Java 7 NIO.2/Chapter09/async/mch_02/build/classes/mch_02/Main$1.class new file mode 100644 index 0000000..00fdc7f Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter09/async/mch_02/build/classes/mch_02/Main$1.class differ diff --git a/Pro Java 7 NIO.2/Chapter09/async/mch_02/build/classes/mch_02/Main.class b/Pro Java 7 NIO.2/Chapter09/async/mch_02/build/classes/mch_02/Main.class new file mode 100644 index 0000000..127913f Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter09/async/mch_02/build/classes/mch_02/Main.class differ diff --git a/Pro Java 7 NIO.2/Chapter09/async/mch_02/dist/README.TXT b/Pro Java 7 NIO.2/Chapter09/async/mch_02/dist/README.TXT new file mode 100644 index 0000000..c0ee462 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter09/async/mch_02/dist/README.TXT @@ -0,0 +1,32 @@ +======================== +BUILD OUTPUT DESCRIPTION +======================== + +When you build an Java application project that has a main class, the IDE +automatically copies all of the JAR +files on the projects classpath to your projects dist/lib folder. The IDE +also adds each of the JAR files to the Class-Path element in the application +JAR files manifest file (MANIFEST.MF). + +To run the project from the command line, go to the dist folder and +type the following: + +java -jar "mch_02.jar" + +To distribute this project, zip up the dist folder (including the lib folder) +and distribute the ZIP file. + +Notes: + +* If two JAR files on the project classpath have the same name, only the first +JAR file is copied to the lib folder. +* Only JAR files are copied to the lib folder. +If the classpath contains other types of files or folders, these files (folders) +are not copied. +* If a library on the projects classpath also has a Class-Path element +specified in the manifest,the content of the Class-Path element has to be on +the projects runtime path. +* To set a main class in a standard Java project, right-click the project node +in the Projects window and choose Properties. Then click Run and enter the +class name in the Main Class field. Alternatively, you can manually type the +class name in the manifest Main-Class element. diff --git a/Pro Java 7 NIO.2/Chapter09/async/mch_02/dist/mch_02.jar b/Pro Java 7 NIO.2/Chapter09/async/mch_02/dist/mch_02.jar new file mode 100644 index 0000000..7797a10 Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter09/async/mch_02/dist/mch_02.jar differ diff --git a/Pro Java 7 NIO.2/Chapter09/async/mch_02/manifest.mf b/Pro Java 7 NIO.2/Chapter09/async/mch_02/manifest.mf new file mode 100644 index 0000000..328e8e5 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter09/async/mch_02/manifest.mf @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +X-COMMENT: Main-Class will be added automatically by build + diff --git a/Pro Java 7 NIO.2/Chapter09/async/mch_02/nbproject/build-impl.xml b/Pro Java 7 NIO.2/Chapter09/async/mch_02/nbproject/build-impl.xml new file mode 100644 index 0000000..feb0673 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter09/async/mch_02/nbproject/build-impl.xml @@ -0,0 +1,1041 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set src.dir + Must set test.src.dir + Must set build.dir + Must set dist.dir + Must set build.classes.dir + Must set dist.javadoc.dir + Must set build.test.classes.dir + Must set build.test.results.dir + Must set build.classes.excludes + Must set dist.jar + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set JVM to use for profiling in profiler.info.jvm + Must set profiler agent JVM arguments in profiler.info.jvmargs.agent + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + + + + + + java -cp "${run.classpath.with.dist.jar}" ${main.class} + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + java -jar "${dist.jar.resolved}" + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set run.class + + + + Must select one file in the IDE or set run.class + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set debug.class + + + + + Must select one file in the IDE or set debug.class + + + + + Must set fix.includes + + + + + + + + + + + + + + + + + Must select one file in the IDE or set profile.class + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + Some tests failed; see details above. + + + + + + + + + Must select some files in the IDE or set test.includes + + + + Some tests failed; see details above. + + + + + Must select one file in the IDE or set test.class + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Pro Java 7 NIO.2/Chapter09/async/mch_02/nbproject/genfiles.properties b/Pro Java 7 NIO.2/Chapter09/async/mch_02/nbproject/genfiles.properties new file mode 100644 index 0000000..0ab6368 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter09/async/mch_02/nbproject/genfiles.properties @@ -0,0 +1,8 @@ +build.xml.data.CRC32=71d7c8b7 +build.xml.script.CRC32=7f25f829 +build.xml.stylesheet.CRC32=28e38971@1.43.1.45 +# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. +# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. +nbproject/build-impl.xml.data.CRC32=71d7c8b7 +nbproject/build-impl.xml.script.CRC32=cb2d792d +nbproject/build-impl.xml.stylesheet.CRC32=0c01fd8e@1.43.1.45 diff --git a/Pro Java 7 NIO.2/Chapter09/async/mch_02/nbproject/private/config.properties b/Pro Java 7 NIO.2/Chapter09/async/mch_02/nbproject/private/config.properties new file mode 100644 index 0000000..e69de29 diff --git a/Pro Java 7 NIO.2/Chapter09/async/mch_02/nbproject/private/private.properties b/Pro Java 7 NIO.2/Chapter09/async/mch_02/nbproject/private/private.properties new file mode 100644 index 0000000..a5ab360 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter09/async/mch_02/nbproject/private/private.properties @@ -0,0 +1,6 @@ +compile.on.save=true +do.depend=false +do.jar=true +javac.debug=true +javadoc.preview=true +user.properties.file=C:\\Users\\Leo\\.netbeans\\7.0\\build.properties diff --git a/Pro Java 7 NIO.2/Chapter09/async/mch_02/nbproject/private/private.xml b/Pro Java 7 NIO.2/Chapter09/async/mch_02/nbproject/private/private.xml new file mode 100644 index 0000000..c1f155a --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter09/async/mch_02/nbproject/private/private.xml @@ -0,0 +1,4 @@ + + + + diff --git a/Pro Java 7 NIO.2/Chapter09/async/mch_02/nbproject/project.properties b/Pro Java 7 NIO.2/Chapter09/async/mch_02/nbproject/project.properties new file mode 100644 index 0000000..a4812ca --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter09/async/mch_02/nbproject/project.properties @@ -0,0 +1,72 @@ +annotation.processing.enabled=true +annotation.processing.enabled.in.editor=false +annotation.processing.run.all.processors=true +annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output +application.title=mch_02 +application.vendor=Leo +build.classes.dir=${build.dir}/classes +build.classes.excludes=**/*.java,**/*.form +# This directory is removed when the project is cleaned: +build.dir=build +build.generated.dir=${build.dir}/generated +build.generated.sources.dir=${build.dir}/generated-sources +# Only compile against the classpath explicitly listed here: +build.sysclasspath=ignore +build.test.classes.dir=${build.dir}/test/classes +build.test.results.dir=${build.dir}/test/results +# Uncomment to specify the preferred debugger connection transport: +#debug.transport=dt_socket +debug.classpath=\ + ${run.classpath} +debug.test.classpath=\ + ${run.test.classpath} +# This directory is removed when the project is cleaned: +dist.dir=dist +dist.jar=${dist.dir}/mch_02.jar +dist.javadoc.dir=${dist.dir}/javadoc +endorsed.classpath= +excludes= +includes=** +jar.compress=false +javac.classpath= +# Space-separated list of extra javac options +javac.compilerargs= +javac.deprecation=false +javac.processorpath=\ + ${javac.classpath} +javac.source=1.7 +javac.target=1.7 +javac.test.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +javac.test.processorpath=\ + ${javac.test.classpath} +javadoc.additionalparam= +javadoc.author=false +javadoc.encoding=${source.encoding} +javadoc.noindex=false +javadoc.nonavbar=false +javadoc.notree=false +javadoc.private=false +javadoc.splitindex=true +javadoc.use=true +javadoc.version=false +javadoc.windowtitle= +main.class=mch_02.Main +manifest.file=manifest.mf +meta.inf.dir=${src.dir}/META-INF +mkdist.disabled=false +platform.active=default_platform +run.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +# Space-separated list of JVM arguments used when running the project +# (you may also define separate properties like run-sys-prop.name=value instead of -Dname=value +# or test-sys-prop.name=value to set system properties for unit tests): +run.jvmargs= +run.test.classpath=\ + ${javac.test.classpath}:\ + ${build.test.classes.dir} +source.encoding=UTF-8 +src.dir=src +test.src.dir=test diff --git a/Pro Java 7 NIO.2/Chapter09/async/mch_02/nbproject/project.xml b/Pro Java 7 NIO.2/Chapter09/async/mch_02/nbproject/project.xml new file mode 100644 index 0000000..3728be1 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter09/async/mch_02/nbproject/project.xml @@ -0,0 +1,15 @@ + + + org.netbeans.modules.java.j2seproject + + + mch_02 + + + + + + + + + diff --git a/Pro Java 7 NIO.2/Chapter09/async/mch_02/src/mch_02/Main.java b/Pro Java 7 NIO.2/Chapter09/async/mch_02/src/mch_02/Main.java new file mode 100644 index 0000000..42d956a --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter09/async/mch_02/src/mch_02/Main.java @@ -0,0 +1,65 @@ +package mch_02; + +import java.io.IOException; +import java.nio.channels.AsynchronousFileChannel; +import java.nio.channels.CompletionHandler; +import java.nio.channels.FileLock; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.nio.file.StandardOpenOption; + +/** + * + * @author Apress + */ +public class Main { + + static Thread current; + + public static void main(String[] args) { + + Path path = Paths.get("C:/rafaelnadal/tournaments/2009", "CopaClaro.txt"); + + try (AsynchronousFileChannel asynchronousFileChannel = AsynchronousFileChannel.open(path, StandardOpenOption.READ, StandardOpenOption.WRITE)) { + + current = Thread.currentThread(); + asynchronousFileChannel.lock("Lock operation status:", new CompletionHandler() { + + @Override + public void completed(FileLock result, Object attachment) { + System.out.println(attachment + " " + result.isValid()); + + if (result.isValid()) { + //... processing ... + System.out.println("Processing the locked file ..."); + //... + try { + result.release(); + } catch (IOException ex) { + System.err.println(ex); + } + } + current.interrupt(); + } + + @Override + public void failed(Throwable exc, Object attachment) { + System.out.println(attachment); + System.out.println("Error:" + exc); + current.interrupt(); + } + }); + + System.out.println("Waiting for file to be locked and process ... \n"); + try { + current.join(); + } catch (InterruptedException e) { + } + System.out.println("\n\nClosing everything and leave! Bye, bye ..."); + + } catch (Exception ex) { + System.err.println(ex); + } + + } +} diff --git a/Pro Java 7 NIO.2/Chapter09/async/mch_03/build.xml b/Pro Java 7 NIO.2/Chapter09/async/mch_03/build.xml new file mode 100644 index 0000000..e8d462d --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter09/async/mch_03/build.xml @@ -0,0 +1,74 @@ + + + + + + + + + + + Builds, tests, and runs the project mch_03. + + + diff --git a/Pro Java 7 NIO.2/Chapter09/async/mch_03/build/built-jar.properties b/Pro Java 7 NIO.2/Chapter09/async/mch_03/build/built-jar.properties new file mode 100644 index 0000000..895df53 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter09/async/mch_03/build/built-jar.properties @@ -0,0 +1,4 @@ +#Thu, 03 Nov 2011 07:17:07 +0200 + + +C\:\\NIO\\async\\mch_03= diff --git a/Pro Java 7 NIO.2/Chapter09/async/mch_03/build/classes/.netbeans_automatic_build b/Pro Java 7 NIO.2/Chapter09/async/mch_03/build/classes/.netbeans_automatic_build new file mode 100644 index 0000000..e69de29 diff --git a/Pro Java 7 NIO.2/Chapter09/async/mch_03/build/classes/mch_03/Main$1.class b/Pro Java 7 NIO.2/Chapter09/async/mch_03/build/classes/mch_03/Main$1.class new file mode 100644 index 0000000..b445509 Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter09/async/mch_03/build/classes/mch_03/Main$1.class differ diff --git a/Pro Java 7 NIO.2/Chapter09/async/mch_03/build/classes/mch_03/Main.class b/Pro Java 7 NIO.2/Chapter09/async/mch_03/build/classes/mch_03/Main.class new file mode 100644 index 0000000..e511e55 Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter09/async/mch_03/build/classes/mch_03/Main.class differ diff --git a/Pro Java 7 NIO.2/Chapter09/async/mch_03/dist/README.TXT b/Pro Java 7 NIO.2/Chapter09/async/mch_03/dist/README.TXT new file mode 100644 index 0000000..ddf7fe2 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter09/async/mch_03/dist/README.TXT @@ -0,0 +1,32 @@ +======================== +BUILD OUTPUT DESCRIPTION +======================== + +When you build an Java application project that has a main class, the IDE +automatically copies all of the JAR +files on the projects classpath to your projects dist/lib folder. The IDE +also adds each of the JAR files to the Class-Path element in the application +JAR files manifest file (MANIFEST.MF). + +To run the project from the command line, go to the dist folder and +type the following: + +java -jar "mch_03.jar" + +To distribute this project, zip up the dist folder (including the lib folder) +and distribute the ZIP file. + +Notes: + +* If two JAR files on the project classpath have the same name, only the first +JAR file is copied to the lib folder. +* Only JAR files are copied to the lib folder. +If the classpath contains other types of files or folders, these files (folders) +are not copied. +* If a library on the projects classpath also has a Class-Path element +specified in the manifest,the content of the Class-Path element has to be on +the projects runtime path. +* To set a main class in a standard Java project, right-click the project node +in the Projects window and choose Properties. Then click Run and enter the +class name in the Main Class field. Alternatively, you can manually type the +class name in the manifest Main-Class element. diff --git a/Pro Java 7 NIO.2/Chapter09/async/mch_03/dist/mch_03.jar b/Pro Java 7 NIO.2/Chapter09/async/mch_03/dist/mch_03.jar new file mode 100644 index 0000000..73383da Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter09/async/mch_03/dist/mch_03.jar differ diff --git a/Pro Java 7 NIO.2/Chapter09/async/mch_03/manifest.mf b/Pro Java 7 NIO.2/Chapter09/async/mch_03/manifest.mf new file mode 100644 index 0000000..328e8e5 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter09/async/mch_03/manifest.mf @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +X-COMMENT: Main-Class will be added automatically by build + diff --git a/Pro Java 7 NIO.2/Chapter09/async/mch_03/nbproject/build-impl.xml b/Pro Java 7 NIO.2/Chapter09/async/mch_03/nbproject/build-impl.xml new file mode 100644 index 0000000..7883758 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter09/async/mch_03/nbproject/build-impl.xml @@ -0,0 +1,1041 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set src.dir + Must set test.src.dir + Must set build.dir + Must set dist.dir + Must set build.classes.dir + Must set dist.javadoc.dir + Must set build.test.classes.dir + Must set build.test.results.dir + Must set build.classes.excludes + Must set dist.jar + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set JVM to use for profiling in profiler.info.jvm + Must set profiler agent JVM arguments in profiler.info.jvmargs.agent + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + + + + + + java -cp "${run.classpath.with.dist.jar}" ${main.class} + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + java -jar "${dist.jar.resolved}" + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set run.class + + + + Must select one file in the IDE or set run.class + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set debug.class + + + + + Must select one file in the IDE or set debug.class + + + + + Must set fix.includes + + + + + + + + + + + + + + + + + Must select one file in the IDE or set profile.class + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + Some tests failed; see details above. + + + + + + + + + Must select some files in the IDE or set test.includes + + + + Some tests failed; see details above. + + + + + Must select one file in the IDE or set test.class + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Pro Java 7 NIO.2/Chapter09/async/mch_03/nbproject/genfiles.properties b/Pro Java 7 NIO.2/Chapter09/async/mch_03/nbproject/genfiles.properties new file mode 100644 index 0000000..bf0574c --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter09/async/mch_03/nbproject/genfiles.properties @@ -0,0 +1,8 @@ +build.xml.data.CRC32=79c44491 +build.xml.script.CRC32=095dbf34 +build.xml.stylesheet.CRC32=28e38971@1.43.1.45 +# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. +# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. +nbproject/build-impl.xml.data.CRC32=79c44491 +nbproject/build-impl.xml.script.CRC32=ff9e5f05 +nbproject/build-impl.xml.stylesheet.CRC32=0c01fd8e@1.43.1.45 diff --git a/Pro Java 7 NIO.2/Chapter09/async/mch_03/nbproject/private/config.properties b/Pro Java 7 NIO.2/Chapter09/async/mch_03/nbproject/private/config.properties new file mode 100644 index 0000000..e69de29 diff --git a/Pro Java 7 NIO.2/Chapter09/async/mch_03/nbproject/private/private.properties b/Pro Java 7 NIO.2/Chapter09/async/mch_03/nbproject/private/private.properties new file mode 100644 index 0000000..a5ab360 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter09/async/mch_03/nbproject/private/private.properties @@ -0,0 +1,6 @@ +compile.on.save=true +do.depend=false +do.jar=true +javac.debug=true +javadoc.preview=true +user.properties.file=C:\\Users\\Leo\\.netbeans\\7.0\\build.properties diff --git a/Pro Java 7 NIO.2/Chapter09/async/mch_03/nbproject/private/private.xml b/Pro Java 7 NIO.2/Chapter09/async/mch_03/nbproject/private/private.xml new file mode 100644 index 0000000..c1f155a --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter09/async/mch_03/nbproject/private/private.xml @@ -0,0 +1,4 @@ + + + + diff --git a/Pro Java 7 NIO.2/Chapter09/async/mch_03/nbproject/project.properties b/Pro Java 7 NIO.2/Chapter09/async/mch_03/nbproject/project.properties new file mode 100644 index 0000000..c040ed8 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter09/async/mch_03/nbproject/project.properties @@ -0,0 +1,72 @@ +annotation.processing.enabled=true +annotation.processing.enabled.in.editor=false +annotation.processing.run.all.processors=true +annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output +application.title=mch_03 +application.vendor=Leo +build.classes.dir=${build.dir}/classes +build.classes.excludes=**/*.java,**/*.form +# This directory is removed when the project is cleaned: +build.dir=build +build.generated.dir=${build.dir}/generated +build.generated.sources.dir=${build.dir}/generated-sources +# Only compile against the classpath explicitly listed here: +build.sysclasspath=ignore +build.test.classes.dir=${build.dir}/test/classes +build.test.results.dir=${build.dir}/test/results +# Uncomment to specify the preferred debugger connection transport: +#debug.transport=dt_socket +debug.classpath=\ + ${run.classpath} +debug.test.classpath=\ + ${run.test.classpath} +# This directory is removed when the project is cleaned: +dist.dir=dist +dist.jar=${dist.dir}/mch_03.jar +dist.javadoc.dir=${dist.dir}/javadoc +endorsed.classpath= +excludes= +includes=** +jar.compress=false +javac.classpath= +# Space-separated list of extra javac options +javac.compilerargs= +javac.deprecation=false +javac.processorpath=\ + ${javac.classpath} +javac.source=1.7 +javac.target=1.7 +javac.test.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +javac.test.processorpath=\ + ${javac.test.classpath} +javadoc.additionalparam= +javadoc.author=false +javadoc.encoding=${source.encoding} +javadoc.noindex=false +javadoc.nonavbar=false +javadoc.notree=false +javadoc.private=false +javadoc.splitindex=true +javadoc.use=true +javadoc.version=false +javadoc.windowtitle= +main.class=mch_03.Main +manifest.file=manifest.mf +meta.inf.dir=${src.dir}/META-INF +mkdist.disabled=false +platform.active=default_platform +run.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +# Space-separated list of JVM arguments used when running the project +# (you may also define separate properties like run-sys-prop.name=value instead of -Dname=value +# or test-sys-prop.name=value to set system properties for unit tests): +run.jvmargs= +run.test.classpath=\ + ${javac.test.classpath}:\ + ${build.test.classes.dir} +source.encoding=UTF-8 +src.dir=src +test.src.dir=test diff --git a/Pro Java 7 NIO.2/Chapter09/async/mch_03/nbproject/project.xml b/Pro Java 7 NIO.2/Chapter09/async/mch_03/nbproject/project.xml new file mode 100644 index 0000000..f612f77 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter09/async/mch_03/nbproject/project.xml @@ -0,0 +1,15 @@ + + + org.netbeans.modules.java.j2seproject + + + mch_03 + + + + + + + + + diff --git a/Pro Java 7 NIO.2/Chapter09/async/mch_03/src/mch_03/Main.java b/Pro Java 7 NIO.2/Chapter09/async/mch_03/src/mch_03/Main.java new file mode 100644 index 0000000..f919d59 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter09/async/mch_03/src/mch_03/Main.java @@ -0,0 +1,90 @@ +package mch_03; + +import java.nio.ByteBuffer; +import java.nio.channels.AsynchronousFileChannel; +import java.nio.charset.Charset; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.nio.file.StandardOpenOption; +import java.util.ArrayList; +import java.util.List; +import java.util.Set; +import java.util.TreeSet; +import java.util.concurrent.Callable; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.Future; +import java.util.concurrent.ThreadLocalRandom; + +/** + * + * @author Apress + */ + +public class Main { + + private static Set withOptions() { + final Set options = new TreeSet<>(); + options.add(StandardOpenOption.READ); + return options; + } + + public static void main(String[] args) { + + final int THREADS = 5; + ExecutorService taskExecutor = Executors.newFixedThreadPool(THREADS); + + String encoding = System.getProperty("file.encoding"); + List> list = new ArrayList<>(); + int sheeps = 0; + + Path path = Paths.get("C:/rafaelnadal/grandslam/RolandGarros", "story.txt"); + + try (AsynchronousFileChannel asynchronousFileChannel = AsynchronousFileChannel.open(path, withOptions(), taskExecutor)) { + + for (int i = 0; i < 50; i++) { + Callable worker = new Callable() { + + @Override + public ByteBuffer call() throws Exception { + ByteBuffer buffer = ByteBuffer.allocateDirect(ThreadLocalRandom.current().nextInt(100, 200)); + //if is too fast, de-comment this + //Thread.sleep(1000 + new Random().nextInt(10000)); + asynchronousFileChannel.read(buffer, ThreadLocalRandom.current().nextInt(0, 100)); + + return buffer; + } + }; + + Future future = taskExecutor.submit(worker); + + list.add(future); + } + + //this will make the executor accept no new threads + // and finish all existing threads in the queue + taskExecutor.shutdown(); + + //wait until all threads are finish + while (!taskExecutor.isTerminated()) { + //do something else while the buffers are prepared + System.out.println("Counting sheeps while fill up some buffers! So far I counted: " + (sheeps += 1)); + } + + System.out.println("\nDone! Here are the buffers:\n"); + for (Future future : list) { + + ByteBuffer buffer = future.get(); + + System.out.println("\n\n"+ buffer); + System.out.println("______________________________________________________"); + buffer.flip(); + System.out.print(Charset.forName(encoding).decode(buffer)); + buffer.clear(); + } + + } catch (Exception ex) { + System.err.println(ex); + } + } +} diff --git a/Pro Java 7 NIO.2/Chapter09/async/mch_04/build.xml b/Pro Java 7 NIO.2/Chapter09/async/mch_04/build.xml new file mode 100644 index 0000000..096eeaa --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter09/async/mch_04/build.xml @@ -0,0 +1,74 @@ + + + + + + + + + + + Builds, tests, and runs the project mch_04. + + + diff --git a/Pro Java 7 NIO.2/Chapter09/async/mch_04/build/built-jar.properties b/Pro Java 7 NIO.2/Chapter09/async/mch_04/build/built-jar.properties new file mode 100644 index 0000000..9ff0071 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter09/async/mch_04/build/built-jar.properties @@ -0,0 +1,4 @@ +#Thu, 03 Nov 2011 06:56:31 +0200 + + +C\:\\NIO\\async\\mch_04= diff --git a/Pro Java 7 NIO.2/Chapter09/async/mch_04/build/classes/mch_04/Main.class b/Pro Java 7 NIO.2/Chapter09/async/mch_04/build/classes/mch_04/Main.class new file mode 100644 index 0000000..539f3dc Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter09/async/mch_04/build/classes/mch_04/Main.class differ diff --git a/Pro Java 7 NIO.2/Chapter09/async/mch_04/dist/README.TXT b/Pro Java 7 NIO.2/Chapter09/async/mch_04/dist/README.TXT new file mode 100644 index 0000000..70f4ee4 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter09/async/mch_04/dist/README.TXT @@ -0,0 +1,32 @@ +======================== +BUILD OUTPUT DESCRIPTION +======================== + +When you build an Java application project that has a main class, the IDE +automatically copies all of the JAR +files on the projects classpath to your projects dist/lib folder. The IDE +also adds each of the JAR files to the Class-Path element in the application +JAR files manifest file (MANIFEST.MF). + +To run the project from the command line, go to the dist folder and +type the following: + +java -jar "mch_04.jar" + +To distribute this project, zip up the dist folder (including the lib folder) +and distribute the ZIP file. + +Notes: + +* If two JAR files on the project classpath have the same name, only the first +JAR file is copied to the lib folder. +* Only JAR files are copied to the lib folder. +If the classpath contains other types of files or folders, these files (folders) +are not copied. +* If a library on the projects classpath also has a Class-Path element +specified in the manifest,the content of the Class-Path element has to be on +the projects runtime path. +* To set a main class in a standard Java project, right-click the project node +in the Projects window and choose Properties. Then click Run and enter the +class name in the Main Class field. Alternatively, you can manually type the +class name in the manifest Main-Class element. diff --git a/Pro Java 7 NIO.2/Chapter09/async/mch_04/dist/mch_04.jar b/Pro Java 7 NIO.2/Chapter09/async/mch_04/dist/mch_04.jar new file mode 100644 index 0000000..d75d5e4 Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter09/async/mch_04/dist/mch_04.jar differ diff --git a/Pro Java 7 NIO.2/Chapter09/async/mch_04/manifest.mf b/Pro Java 7 NIO.2/Chapter09/async/mch_04/manifest.mf new file mode 100644 index 0000000..328e8e5 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter09/async/mch_04/manifest.mf @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +X-COMMENT: Main-Class will be added automatically by build + diff --git a/Pro Java 7 NIO.2/Chapter09/async/mch_04/nbproject/build-impl.xml b/Pro Java 7 NIO.2/Chapter09/async/mch_04/nbproject/build-impl.xml new file mode 100644 index 0000000..a8367ba --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter09/async/mch_04/nbproject/build-impl.xml @@ -0,0 +1,1041 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set src.dir + Must set test.src.dir + Must set build.dir + Must set dist.dir + Must set build.classes.dir + Must set dist.javadoc.dir + Must set build.test.classes.dir + Must set build.test.results.dir + Must set build.classes.excludes + Must set dist.jar + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set JVM to use for profiling in profiler.info.jvm + Must set profiler agent JVM arguments in profiler.info.jvmargs.agent + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + + + + + + java -cp "${run.classpath.with.dist.jar}" ${main.class} + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + java -jar "${dist.jar.resolved}" + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set run.class + + + + Must select one file in the IDE or set run.class + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set debug.class + + + + + Must select one file in the IDE or set debug.class + + + + + Must set fix.includes + + + + + + + + + + + + + + + + + Must select one file in the IDE or set profile.class + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + Some tests failed; see details above. + + + + + + + + + Must select some files in the IDE or set test.includes + + + + Some tests failed; see details above. + + + + + Must select one file in the IDE or set test.class + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Pro Java 7 NIO.2/Chapter09/async/mch_04/nbproject/genfiles.properties b/Pro Java 7 NIO.2/Chapter09/async/mch_04/nbproject/genfiles.properties new file mode 100644 index 0000000..aff475c --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter09/async/mch_04/nbproject/genfiles.properties @@ -0,0 +1,8 @@ +build.xml.data.CRC32=41bee063 +build.xml.script.CRC32=91456c26 +build.xml.stylesheet.CRC32=28e38971@1.43.1.45 +# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. +# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. +nbproject/build-impl.xml.data.CRC32=41bee063 +nbproject/build-impl.xml.script.CRC32=7087addd +nbproject/build-impl.xml.stylesheet.CRC32=0c01fd8e@1.43.1.45 diff --git a/Pro Java 7 NIO.2/Chapter09/async/mch_04/nbproject/private/config.properties b/Pro Java 7 NIO.2/Chapter09/async/mch_04/nbproject/private/config.properties new file mode 100644 index 0000000..e69de29 diff --git a/Pro Java 7 NIO.2/Chapter09/async/mch_04/nbproject/private/private.properties b/Pro Java 7 NIO.2/Chapter09/async/mch_04/nbproject/private/private.properties new file mode 100644 index 0000000..a5ab360 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter09/async/mch_04/nbproject/private/private.properties @@ -0,0 +1,6 @@ +compile.on.save=true +do.depend=false +do.jar=true +javac.debug=true +javadoc.preview=true +user.properties.file=C:\\Users\\Leo\\.netbeans\\7.0\\build.properties diff --git a/Pro Java 7 NIO.2/Chapter09/async/mch_04/nbproject/private/private.xml b/Pro Java 7 NIO.2/Chapter09/async/mch_04/nbproject/private/private.xml new file mode 100644 index 0000000..c1f155a --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter09/async/mch_04/nbproject/private/private.xml @@ -0,0 +1,4 @@ + + + + diff --git a/Pro Java 7 NIO.2/Chapter09/async/mch_04/nbproject/project.properties b/Pro Java 7 NIO.2/Chapter09/async/mch_04/nbproject/project.properties new file mode 100644 index 0000000..421d450 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter09/async/mch_04/nbproject/project.properties @@ -0,0 +1,72 @@ +annotation.processing.enabled=true +annotation.processing.enabled.in.editor=false +annotation.processing.run.all.processors=true +annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output +application.title=mch_04 +application.vendor=Leo +build.classes.dir=${build.dir}/classes +build.classes.excludes=**/*.java,**/*.form +# This directory is removed when the project is cleaned: +build.dir=build +build.generated.dir=${build.dir}/generated +build.generated.sources.dir=${build.dir}/generated-sources +# Only compile against the classpath explicitly listed here: +build.sysclasspath=ignore +build.test.classes.dir=${build.dir}/test/classes +build.test.results.dir=${build.dir}/test/results +# Uncomment to specify the preferred debugger connection transport: +#debug.transport=dt_socket +debug.classpath=\ + ${run.classpath} +debug.test.classpath=\ + ${run.test.classpath} +# This directory is removed when the project is cleaned: +dist.dir=dist +dist.jar=${dist.dir}/mch_04.jar +dist.javadoc.dir=${dist.dir}/javadoc +endorsed.classpath= +excludes= +includes=** +jar.compress=false +javac.classpath= +# Space-separated list of extra javac options +javac.compilerargs= +javac.deprecation=false +javac.processorpath=\ + ${javac.classpath} +javac.source=1.7 +javac.target=1.7 +javac.test.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +javac.test.processorpath=\ + ${javac.test.classpath} +javadoc.additionalparam= +javadoc.author=false +javadoc.encoding=${source.encoding} +javadoc.noindex=false +javadoc.nonavbar=false +javadoc.notree=false +javadoc.private=false +javadoc.splitindex=true +javadoc.use=true +javadoc.version=false +javadoc.windowtitle= +main.class=mch_04.Main +manifest.file=manifest.mf +meta.inf.dir=${src.dir}/META-INF +mkdist.disabled=false +platform.active=default_platform +run.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +# Space-separated list of JVM arguments used when running the project +# (you may also define separate properties like run-sys-prop.name=value instead of -Dname=value +# or test-sys-prop.name=value to set system properties for unit tests): +run.jvmargs= +run.test.classpath=\ + ${javac.test.classpath}:\ + ${build.test.classes.dir} +source.encoding=UTF-8 +src.dir=src +test.src.dir=test diff --git a/Pro Java 7 NIO.2/Chapter09/async/mch_04/nbproject/project.xml b/Pro Java 7 NIO.2/Chapter09/async/mch_04/nbproject/project.xml new file mode 100644 index 0000000..eafe2dd --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter09/async/mch_04/nbproject/project.xml @@ -0,0 +1,15 @@ + + + org.netbeans.modules.java.j2seproject + + + mch_04 + + + + + + + + + diff --git a/Pro Java 7 NIO.2/Chapter09/async/mch_04/src/mch_04/Main.java b/Pro Java 7 NIO.2/Chapter09/async/mch_04/src/mch_04/Main.java new file mode 100644 index 0000000..f309b85 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter09/async/mch_04/src/mch_04/Main.java @@ -0,0 +1,43 @@ +package mch_04; + +import java.nio.ByteBuffer; +import java.nio.channels.AsynchronousFileChannel; +import java.nio.charset.Charset; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.nio.file.StandardOpenOption; +import java.util.concurrent.Future; + +/** + * + * @author Apress + */ +public class Main { + + public static void main(String[] args) { + + ByteBuffer buffer = ByteBuffer.allocate(100); + String encoding = System.getProperty("file.encoding"); + + Path path = Paths.get("C:/rafaelnadal/grandslam/RolandGarros", "story.txt"); + try (AsynchronousFileChannel asynchronousFileChannel = AsynchronousFileChannel.open(path, StandardOpenOption.READ)) { + + Future result = asynchronousFileChannel.read(buffer, 0); + + while (!result.isDone()) { + System.out.println("Do something else while reading ..."); + } + + System.out.println("Read done: " + result.isDone()); + System.out.println("Bytes read: " + result.get()); + + } catch (Exception ex) { + System.err.println(ex); + } + + buffer.flip(); + System.out.print(Charset.forName(encoding).decode(buffer)); + buffer.clear(); + + } +} diff --git a/Pro Java 7 NIO.2/Chapter09/async/mch_05/build.xml b/Pro Java 7 NIO.2/Chapter09/async/mch_05/build.xml new file mode 100644 index 0000000..f20a702 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter09/async/mch_05/build.xml @@ -0,0 +1,74 @@ + + + + + + + + + + + Builds, tests, and runs the project mch_05. + + + diff --git a/Pro Java 7 NIO.2/Chapter09/async/mch_05/build/built-jar.properties b/Pro Java 7 NIO.2/Chapter09/async/mch_05/build/built-jar.properties new file mode 100644 index 0000000..3ddf0f8 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter09/async/mch_05/build/built-jar.properties @@ -0,0 +1,4 @@ +#Thu, 03 Nov 2011 06:58:38 +0200 + + +C\:\\NIO\\async\\mch_05= diff --git a/Pro Java 7 NIO.2/Chapter09/async/mch_05/build/classes/mch_05/Main.class b/Pro Java 7 NIO.2/Chapter09/async/mch_05/build/classes/mch_05/Main.class new file mode 100644 index 0000000..5af0e27 Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter09/async/mch_05/build/classes/mch_05/Main.class differ diff --git a/Pro Java 7 NIO.2/Chapter09/async/mch_05/dist/README.TXT b/Pro Java 7 NIO.2/Chapter09/async/mch_05/dist/README.TXT new file mode 100644 index 0000000..a90f8ff --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter09/async/mch_05/dist/README.TXT @@ -0,0 +1,32 @@ +======================== +BUILD OUTPUT DESCRIPTION +======================== + +When you build an Java application project that has a main class, the IDE +automatically copies all of the JAR +files on the projects classpath to your projects dist/lib folder. The IDE +also adds each of the JAR files to the Class-Path element in the application +JAR files manifest file (MANIFEST.MF). + +To run the project from the command line, go to the dist folder and +type the following: + +java -jar "mch_05.jar" + +To distribute this project, zip up the dist folder (including the lib folder) +and distribute the ZIP file. + +Notes: + +* If two JAR files on the project classpath have the same name, only the first +JAR file is copied to the lib folder. +* Only JAR files are copied to the lib folder. +If the classpath contains other types of files or folders, these files (folders) +are not copied. +* If a library on the projects classpath also has a Class-Path element +specified in the manifest,the content of the Class-Path element has to be on +the projects runtime path. +* To set a main class in a standard Java project, right-click the project node +in the Projects window and choose Properties. Then click Run and enter the +class name in the Main Class field. Alternatively, you can manually type the +class name in the manifest Main-Class element. diff --git a/Pro Java 7 NIO.2/Chapter09/async/mch_05/dist/mch_05.jar b/Pro Java 7 NIO.2/Chapter09/async/mch_05/dist/mch_05.jar new file mode 100644 index 0000000..dfcc5d3 Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter09/async/mch_05/dist/mch_05.jar differ diff --git a/Pro Java 7 NIO.2/Chapter09/async/mch_05/manifest.mf b/Pro Java 7 NIO.2/Chapter09/async/mch_05/manifest.mf new file mode 100644 index 0000000..328e8e5 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter09/async/mch_05/manifest.mf @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +X-COMMENT: Main-Class will be added automatically by build + diff --git a/Pro Java 7 NIO.2/Chapter09/async/mch_05/nbproject/build-impl.xml b/Pro Java 7 NIO.2/Chapter09/async/mch_05/nbproject/build-impl.xml new file mode 100644 index 0000000..8f46684 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter09/async/mch_05/nbproject/build-impl.xml @@ -0,0 +1,1041 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set src.dir + Must set test.src.dir + Must set build.dir + Must set dist.dir + Must set build.classes.dir + Must set dist.javadoc.dir + Must set build.test.classes.dir + Must set build.test.results.dir + Must set build.classes.excludes + Must set dist.jar + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set JVM to use for profiling in profiler.info.jvm + Must set profiler agent JVM arguments in profiler.info.jvmargs.agent + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + + + + + + java -cp "${run.classpath.with.dist.jar}" ${main.class} + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + java -jar "${dist.jar.resolved}" + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set run.class + + + + Must select one file in the IDE or set run.class + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set debug.class + + + + + Must select one file in the IDE or set debug.class + + + + + Must set fix.includes + + + + + + + + + + + + + + + + + Must select one file in the IDE or set profile.class + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + Some tests failed; see details above. + + + + + + + + + Must select some files in the IDE or set test.includes + + + + Some tests failed; see details above. + + + + + Must select one file in the IDE or set test.class + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Pro Java 7 NIO.2/Chapter09/async/mch_05/nbproject/genfiles.properties b/Pro Java 7 NIO.2/Chapter09/async/mch_05/nbproject/genfiles.properties new file mode 100644 index 0000000..f188985 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter09/async/mch_05/nbproject/genfiles.properties @@ -0,0 +1,8 @@ +build.xml.data.CRC32=49ad6c45 +build.xml.script.CRC32=e73d2b3b +build.xml.stylesheet.CRC32=28e38971@1.43.1.45 +# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. +# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. +nbproject/build-impl.xml.data.CRC32=49ad6c45 +nbproject/build-impl.xml.script.CRC32=44348bf5 +nbproject/build-impl.xml.stylesheet.CRC32=0c01fd8e@1.43.1.45 diff --git a/Pro Java 7 NIO.2/Chapter09/async/mch_05/nbproject/private/config.properties b/Pro Java 7 NIO.2/Chapter09/async/mch_05/nbproject/private/config.properties new file mode 100644 index 0000000..e69de29 diff --git a/Pro Java 7 NIO.2/Chapter09/async/mch_05/nbproject/private/private.properties b/Pro Java 7 NIO.2/Chapter09/async/mch_05/nbproject/private/private.properties new file mode 100644 index 0000000..a5ab360 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter09/async/mch_05/nbproject/private/private.properties @@ -0,0 +1,6 @@ +compile.on.save=true +do.depend=false +do.jar=true +javac.debug=true +javadoc.preview=true +user.properties.file=C:\\Users\\Leo\\.netbeans\\7.0\\build.properties diff --git a/Pro Java 7 NIO.2/Chapter09/async/mch_05/nbproject/private/private.xml b/Pro Java 7 NIO.2/Chapter09/async/mch_05/nbproject/private/private.xml new file mode 100644 index 0000000..c1f155a --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter09/async/mch_05/nbproject/private/private.xml @@ -0,0 +1,4 @@ + + + + diff --git a/Pro Java 7 NIO.2/Chapter09/async/mch_05/nbproject/project.properties b/Pro Java 7 NIO.2/Chapter09/async/mch_05/nbproject/project.properties new file mode 100644 index 0000000..68d0374 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter09/async/mch_05/nbproject/project.properties @@ -0,0 +1,72 @@ +annotation.processing.enabled=true +annotation.processing.enabled.in.editor=false +annotation.processing.run.all.processors=true +annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output +application.title=mch_05 +application.vendor=Leo +build.classes.dir=${build.dir}/classes +build.classes.excludes=**/*.java,**/*.form +# This directory is removed when the project is cleaned: +build.dir=build +build.generated.dir=${build.dir}/generated +build.generated.sources.dir=${build.dir}/generated-sources +# Only compile against the classpath explicitly listed here: +build.sysclasspath=ignore +build.test.classes.dir=${build.dir}/test/classes +build.test.results.dir=${build.dir}/test/results +# Uncomment to specify the preferred debugger connection transport: +#debug.transport=dt_socket +debug.classpath=\ + ${run.classpath} +debug.test.classpath=\ + ${run.test.classpath} +# This directory is removed when the project is cleaned: +dist.dir=dist +dist.jar=${dist.dir}/mch_05.jar +dist.javadoc.dir=${dist.dir}/javadoc +endorsed.classpath= +excludes= +includes=** +jar.compress=false +javac.classpath= +# Space-separated list of extra javac options +javac.compilerargs= +javac.deprecation=false +javac.processorpath=\ + ${javac.classpath} +javac.source=1.7 +javac.target=1.7 +javac.test.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +javac.test.processorpath=\ + ${javac.test.classpath} +javadoc.additionalparam= +javadoc.author=false +javadoc.encoding=${source.encoding} +javadoc.noindex=false +javadoc.nonavbar=false +javadoc.notree=false +javadoc.private=false +javadoc.splitindex=true +javadoc.use=true +javadoc.version=false +javadoc.windowtitle= +main.class=mch_05.Main +manifest.file=manifest.mf +meta.inf.dir=${src.dir}/META-INF +mkdist.disabled=false +platform.active=default_platform +run.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +# Space-separated list of JVM arguments used when running the project +# (you may also define separate properties like run-sys-prop.name=value instead of -Dname=value +# or test-sys-prop.name=value to set system properties for unit tests): +run.jvmargs= +run.test.classpath=\ + ${javac.test.classpath}:\ + ${build.test.classes.dir} +source.encoding=UTF-8 +src.dir=src +test.src.dir=test diff --git a/Pro Java 7 NIO.2/Chapter09/async/mch_05/nbproject/project.xml b/Pro Java 7 NIO.2/Chapter09/async/mch_05/nbproject/project.xml new file mode 100644 index 0000000..0b1d9b7 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter09/async/mch_05/nbproject/project.xml @@ -0,0 +1,15 @@ + + + org.netbeans.modules.java.j2seproject + + + mch_05 + + + + + + + + + diff --git a/Pro Java 7 NIO.2/Chapter09/async/mch_05/src/mch_05/Main.java b/Pro Java 7 NIO.2/Chapter09/async/mch_05/src/mch_05/Main.java new file mode 100644 index 0000000..bd1c881 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter09/async/mch_05/src/mch_05/Main.java @@ -0,0 +1,37 @@ +package mch_05; + +import java.nio.ByteBuffer; +import java.nio.channels.AsynchronousFileChannel; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.nio.file.StandardOpenOption; +import java.util.concurrent.Future; + +/** + * + * @author Apress + */ +public class Main { + + public static void main(String[] args) { + + ByteBuffer buffer = ByteBuffer.wrap("The win keeps Nadal at the top of the heap in men's tennis, at least for a few more weeks. The world No2, Novak Djokovic, dumped out here in the semi-finals by a resurgent Federer, will come hard at them again at Wimbledon but there is much to come from two rivals who, for seven years, have held all pretenders at bay.".getBytes()); + + Path path = Paths.get("C:/rafaelnadal/grandslam/RolandGarros", "story.txt"); + try (AsynchronousFileChannel asynchronousFileChannel = AsynchronousFileChannel.open(path, StandardOpenOption.WRITE)) { + + Future result = asynchronousFileChannel.write(buffer, 100); + + while (!result.isDone()) { + System.out.println("Do something else while writing ..."); + } + + System.out.println("Written done: " + result.isDone()); + System.out.println("Bytes written: " + result.get()); + + } catch (Exception ex) { + System.err.println(ex); + } + + } +} diff --git a/Pro Java 7 NIO.2/Chapter09/async/mch_06/build.xml b/Pro Java 7 NIO.2/Chapter09/async/mch_06/build.xml new file mode 100644 index 0000000..d1f819d --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter09/async/mch_06/build.xml @@ -0,0 +1,74 @@ + + + + + + + + + + + Builds, tests, and runs the project mch_06. + + + diff --git a/Pro Java 7 NIO.2/Chapter09/async/mch_06/build/built-jar.properties b/Pro Java 7 NIO.2/Chapter09/async/mch_06/build/built-jar.properties new file mode 100644 index 0000000..a17ee47 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter09/async/mch_06/build/built-jar.properties @@ -0,0 +1,4 @@ +#Thu, 03 Nov 2011 06:58:46 +0200 + + +C\:\\NIO\\async\\mch_06= diff --git a/Pro Java 7 NIO.2/Chapter09/async/mch_06/build/classes/.netbeans_automatic_build b/Pro Java 7 NIO.2/Chapter09/async/mch_06/build/classes/.netbeans_automatic_build new file mode 100644 index 0000000..e69de29 diff --git a/Pro Java 7 NIO.2/Chapter09/async/mch_06/build/classes/mch_06/Main.class b/Pro Java 7 NIO.2/Chapter09/async/mch_06/build/classes/mch_06/Main.class new file mode 100644 index 0000000..0d2ff3f Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter09/async/mch_06/build/classes/mch_06/Main.class differ diff --git a/Pro Java 7 NIO.2/Chapter09/async/mch_06/dist/README.TXT b/Pro Java 7 NIO.2/Chapter09/async/mch_06/dist/README.TXT new file mode 100644 index 0000000..65ef477 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter09/async/mch_06/dist/README.TXT @@ -0,0 +1,32 @@ +======================== +BUILD OUTPUT DESCRIPTION +======================== + +When you build an Java application project that has a main class, the IDE +automatically copies all of the JAR +files on the projects classpath to your projects dist/lib folder. The IDE +also adds each of the JAR files to the Class-Path element in the application +JAR files manifest file (MANIFEST.MF). + +To run the project from the command line, go to the dist folder and +type the following: + +java -jar "mch_06.jar" + +To distribute this project, zip up the dist folder (including the lib folder) +and distribute the ZIP file. + +Notes: + +* If two JAR files on the project classpath have the same name, only the first +JAR file is copied to the lib folder. +* Only JAR files are copied to the lib folder. +If the classpath contains other types of files or folders, these files (folders) +are not copied. +* If a library on the projects classpath also has a Class-Path element +specified in the manifest,the content of the Class-Path element has to be on +the projects runtime path. +* To set a main class in a standard Java project, right-click the project node +in the Projects window and choose Properties. Then click Run and enter the +class name in the Main Class field. Alternatively, you can manually type the +class name in the manifest Main-Class element. diff --git a/Pro Java 7 NIO.2/Chapter09/async/mch_06/dist/mch_06.jar b/Pro Java 7 NIO.2/Chapter09/async/mch_06/dist/mch_06.jar new file mode 100644 index 0000000..e1fd8f8 Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter09/async/mch_06/dist/mch_06.jar differ diff --git a/Pro Java 7 NIO.2/Chapter09/async/mch_06/manifest.mf b/Pro Java 7 NIO.2/Chapter09/async/mch_06/manifest.mf new file mode 100644 index 0000000..328e8e5 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter09/async/mch_06/manifest.mf @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +X-COMMENT: Main-Class will be added automatically by build + diff --git a/Pro Java 7 NIO.2/Chapter09/async/mch_06/nbproject/build-impl.xml b/Pro Java 7 NIO.2/Chapter09/async/mch_06/nbproject/build-impl.xml new file mode 100644 index 0000000..57dcb4d --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter09/async/mch_06/nbproject/build-impl.xml @@ -0,0 +1,1041 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set src.dir + Must set test.src.dir + Must set build.dir + Must set dist.dir + Must set build.classes.dir + Must set dist.javadoc.dir + Must set build.test.classes.dir + Must set build.test.results.dir + Must set build.classes.excludes + Must set dist.jar + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set JVM to use for profiling in profiler.info.jvm + Must set profiler agent JVM arguments in profiler.info.jvmargs.agent + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + + + + + + java -cp "${run.classpath.with.dist.jar}" ${main.class} + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + java -jar "${dist.jar.resolved}" + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set run.class + + + + Must select one file in the IDE or set run.class + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set debug.class + + + + + Must select one file in the IDE or set debug.class + + + + + Must set fix.includes + + + + + + + + + + + + + + + + + Must select one file in the IDE or set profile.class + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + Some tests failed; see details above. + + + + + + + + + Must select some files in the IDE or set test.includes + + + + Some tests failed; see details above. + + + + + Must select one file in the IDE or set test.class + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Pro Java 7 NIO.2/Chapter09/async/mch_06/nbproject/genfiles.properties b/Pro Java 7 NIO.2/Chapter09/async/mch_06/nbproject/genfiles.properties new file mode 100644 index 0000000..bb96594 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter09/async/mch_06/nbproject/genfiles.properties @@ -0,0 +1,8 @@ +build.xml.data.CRC32=5199f82f +build.xml.script.CRC32=7db5e21c +build.xml.stylesheet.CRC32=28e38971@1.43.1.45 +# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. +# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. +nbproject/build-impl.xml.data.CRC32=5199f82f +nbproject/build-impl.xml.script.CRC32=19e1e18d +nbproject/build-impl.xml.stylesheet.CRC32=0c01fd8e@1.43.1.45 diff --git a/Pro Java 7 NIO.2/Chapter09/async/mch_06/nbproject/private/config.properties b/Pro Java 7 NIO.2/Chapter09/async/mch_06/nbproject/private/config.properties new file mode 100644 index 0000000..e69de29 diff --git a/Pro Java 7 NIO.2/Chapter09/async/mch_06/nbproject/private/private.properties b/Pro Java 7 NIO.2/Chapter09/async/mch_06/nbproject/private/private.properties new file mode 100644 index 0000000..a5ab360 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter09/async/mch_06/nbproject/private/private.properties @@ -0,0 +1,6 @@ +compile.on.save=true +do.depend=false +do.jar=true +javac.debug=true +javadoc.preview=true +user.properties.file=C:\\Users\\Leo\\.netbeans\\7.0\\build.properties diff --git a/Pro Java 7 NIO.2/Chapter09/async/mch_06/nbproject/private/private.xml b/Pro Java 7 NIO.2/Chapter09/async/mch_06/nbproject/private/private.xml new file mode 100644 index 0000000..c1f155a --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter09/async/mch_06/nbproject/private/private.xml @@ -0,0 +1,4 @@ + + + + diff --git a/Pro Java 7 NIO.2/Chapter09/async/mch_06/nbproject/project.properties b/Pro Java 7 NIO.2/Chapter09/async/mch_06/nbproject/project.properties new file mode 100644 index 0000000..c135e5c --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter09/async/mch_06/nbproject/project.properties @@ -0,0 +1,72 @@ +annotation.processing.enabled=true +annotation.processing.enabled.in.editor=false +annotation.processing.run.all.processors=true +annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output +application.title=mch_06 +application.vendor=Leo +build.classes.dir=${build.dir}/classes +build.classes.excludes=**/*.java,**/*.form +# This directory is removed when the project is cleaned: +build.dir=build +build.generated.dir=${build.dir}/generated +build.generated.sources.dir=${build.dir}/generated-sources +# Only compile against the classpath explicitly listed here: +build.sysclasspath=ignore +build.test.classes.dir=${build.dir}/test/classes +build.test.results.dir=${build.dir}/test/results +# Uncomment to specify the preferred debugger connection transport: +#debug.transport=dt_socket +debug.classpath=\ + ${run.classpath} +debug.test.classpath=\ + ${run.test.classpath} +# This directory is removed when the project is cleaned: +dist.dir=dist +dist.jar=${dist.dir}/mch_06.jar +dist.javadoc.dir=${dist.dir}/javadoc +endorsed.classpath= +excludes= +includes=** +jar.compress=false +javac.classpath= +# Space-separated list of extra javac options +javac.compilerargs= +javac.deprecation=false +javac.processorpath=\ + ${javac.classpath} +javac.source=1.7 +javac.target=1.7 +javac.test.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +javac.test.processorpath=\ + ${javac.test.classpath} +javadoc.additionalparam= +javadoc.author=false +javadoc.encoding=${source.encoding} +javadoc.noindex=false +javadoc.nonavbar=false +javadoc.notree=false +javadoc.private=false +javadoc.splitindex=true +javadoc.use=true +javadoc.version=false +javadoc.windowtitle= +main.class=mch_06.Main +manifest.file=manifest.mf +meta.inf.dir=${src.dir}/META-INF +mkdist.disabled=false +platform.active=default_platform +run.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +# Space-separated list of JVM arguments used when running the project +# (you may also define separate properties like run-sys-prop.name=value instead of -Dname=value +# or test-sys-prop.name=value to set system properties for unit tests): +run.jvmargs= +run.test.classpath=\ + ${javac.test.classpath}:\ + ${build.test.classes.dir} +source.encoding=UTF-8 +src.dir=src +test.src.dir=test diff --git a/Pro Java 7 NIO.2/Chapter09/async/mch_06/nbproject/project.xml b/Pro Java 7 NIO.2/Chapter09/async/mch_06/nbproject/project.xml new file mode 100644 index 0000000..c5ded1d --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter09/async/mch_06/nbproject/project.xml @@ -0,0 +1,15 @@ + + + org.netbeans.modules.java.j2seproject + + + mch_06 + + + + + + + + + diff --git a/Pro Java 7 NIO.2/Chapter09/async/mch_06/src/mch_06/Main.java b/Pro Java 7 NIO.2/Chapter09/async/mch_06/src/mch_06/Main.java new file mode 100644 index 0000000..0ac9d14 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter09/async/mch_06/src/mch_06/Main.java @@ -0,0 +1,50 @@ +package mch_06; + +import java.nio.ByteBuffer; +import java.nio.channels.AsynchronousFileChannel; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.nio.file.StandardOpenOption; +import java.util.concurrent.Future; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.TimeoutException; + +/** + * + * @author Apress + */ +public class Main { + + public static void main(String[] args) { + + ByteBuffer buffer = ByteBuffer.allocate(100); + int bytesRead = 0; + Future result = null; + + Path path = Paths.get("C:/rafaelnadal/grandslam/RolandGarros", "story.txt"); + + try (AsynchronousFileChannel asynchronousFileChannel = AsynchronousFileChannel.open(path, StandardOpenOption.READ)) { + + result = asynchronousFileChannel.read(buffer, 0); + + bytesRead = result.get(1, TimeUnit.NANOSECONDS); + + if (result.isDone()) { + System.out.println("The result is available!"); + System.out.println("Read bytes: " + bytesRead); + } + + } catch (Exception ex) { + if (ex instanceof TimeoutException) { + if (result != null) { + result.cancel(true); + } + System.out.println("The result is not available!"); + System.out.println("The read task was cancelled ? " + result.isCancelled()); + System.out.println("Read bytes: " + bytesRead); + } else { + System.err.println(ex); + } + } + } +} diff --git a/Pro Java 7 NIO.2/Chapter09/async/mch_07/build.xml b/Pro Java 7 NIO.2/Chapter09/async/mch_07/build.xml new file mode 100644 index 0000000..d38566e --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter09/async/mch_07/build.xml @@ -0,0 +1,74 @@ + + + + + + + + + + + Builds, tests, and runs the project mch_07. + + + diff --git a/Pro Java 7 NIO.2/Chapter09/async/mch_07/build/built-jar.properties b/Pro Java 7 NIO.2/Chapter09/async/mch_07/build/built-jar.properties new file mode 100644 index 0000000..908164d --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter09/async/mch_07/build/built-jar.properties @@ -0,0 +1,4 @@ +#Thu, 03 Nov 2011 06:59:58 +0200 + + +C\:\\NIO\\async\\mch_07= diff --git a/Pro Java 7 NIO.2/Chapter09/async/mch_07/build/classes/mch_07/Main$1.class b/Pro Java 7 NIO.2/Chapter09/async/mch_07/build/classes/mch_07/Main$1.class new file mode 100644 index 0000000..1fb8c59 Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter09/async/mch_07/build/classes/mch_07/Main$1.class differ diff --git a/Pro Java 7 NIO.2/Chapter09/async/mch_07/build/classes/mch_07/Main.class b/Pro Java 7 NIO.2/Chapter09/async/mch_07/build/classes/mch_07/Main.class new file mode 100644 index 0000000..9dc6cca Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter09/async/mch_07/build/classes/mch_07/Main.class differ diff --git a/Pro Java 7 NIO.2/Chapter09/async/mch_07/dist/README.TXT b/Pro Java 7 NIO.2/Chapter09/async/mch_07/dist/README.TXT new file mode 100644 index 0000000..eb962ee --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter09/async/mch_07/dist/README.TXT @@ -0,0 +1,32 @@ +======================== +BUILD OUTPUT DESCRIPTION +======================== + +When you build an Java application project that has a main class, the IDE +automatically copies all of the JAR +files on the projects classpath to your projects dist/lib folder. The IDE +also adds each of the JAR files to the Class-Path element in the application +JAR files manifest file (MANIFEST.MF). + +To run the project from the command line, go to the dist folder and +type the following: + +java -jar "mch_07.jar" + +To distribute this project, zip up the dist folder (including the lib folder) +and distribute the ZIP file. + +Notes: + +* If two JAR files on the project classpath have the same name, only the first +JAR file is copied to the lib folder. +* Only JAR files are copied to the lib folder. +If the classpath contains other types of files or folders, these files (folders) +are not copied. +* If a library on the projects classpath also has a Class-Path element +specified in the manifest,the content of the Class-Path element has to be on +the projects runtime path. +* To set a main class in a standard Java project, right-click the project node +in the Projects window and choose Properties. Then click Run and enter the +class name in the Main Class field. Alternatively, you can manually type the +class name in the manifest Main-Class element. diff --git a/Pro Java 7 NIO.2/Chapter09/async/mch_07/dist/mch_07.jar b/Pro Java 7 NIO.2/Chapter09/async/mch_07/dist/mch_07.jar new file mode 100644 index 0000000..c576839 Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter09/async/mch_07/dist/mch_07.jar differ diff --git a/Pro Java 7 NIO.2/Chapter09/async/mch_07/manifest.mf b/Pro Java 7 NIO.2/Chapter09/async/mch_07/manifest.mf new file mode 100644 index 0000000..328e8e5 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter09/async/mch_07/manifest.mf @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +X-COMMENT: Main-Class will be added automatically by build + diff --git a/Pro Java 7 NIO.2/Chapter09/async/mch_07/nbproject/build-impl.xml b/Pro Java 7 NIO.2/Chapter09/async/mch_07/nbproject/build-impl.xml new file mode 100644 index 0000000..0f4a69f --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter09/async/mch_07/nbproject/build-impl.xml @@ -0,0 +1,1041 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set src.dir + Must set test.src.dir + Must set build.dir + Must set dist.dir + Must set build.classes.dir + Must set dist.javadoc.dir + Must set build.test.classes.dir + Must set build.test.results.dir + Must set build.classes.excludes + Must set dist.jar + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set JVM to use for profiling in profiler.info.jvm + Must set profiler agent JVM arguments in profiler.info.jvmargs.agent + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + + + + + + java -cp "${run.classpath.with.dist.jar}" ${main.class} + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + java -jar "${dist.jar.resolved}" + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set run.class + + + + Must select one file in the IDE or set run.class + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set debug.class + + + + + Must select one file in the IDE or set debug.class + + + + + Must set fix.includes + + + + + + + + + + + + + + + + + Must select one file in the IDE or set profile.class + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + Some tests failed; see details above. + + + + + + + + + Must select some files in the IDE or set test.includes + + + + Some tests failed; see details above. + + + + + Must select one file in the IDE or set test.class + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Pro Java 7 NIO.2/Chapter09/async/mch_07/nbproject/genfiles.properties b/Pro Java 7 NIO.2/Chapter09/async/mch_07/nbproject/genfiles.properties new file mode 100644 index 0000000..d8fbb60 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter09/async/mch_07/nbproject/genfiles.properties @@ -0,0 +1,8 @@ +build.xml.data.CRC32=598a7409 +build.xml.script.CRC32=0bcda501 +build.xml.stylesheet.CRC32=28e38971@1.43.1.45 +# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. +# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. +nbproject/build-impl.xml.data.CRC32=598a7409 +nbproject/build-impl.xml.script.CRC32=2d52c7a5 +nbproject/build-impl.xml.stylesheet.CRC32=0c01fd8e@1.43.1.45 diff --git a/Pro Java 7 NIO.2/Chapter09/async/mch_07/nbproject/private/config.properties b/Pro Java 7 NIO.2/Chapter09/async/mch_07/nbproject/private/config.properties new file mode 100644 index 0000000..e69de29 diff --git a/Pro Java 7 NIO.2/Chapter09/async/mch_07/nbproject/private/private.properties b/Pro Java 7 NIO.2/Chapter09/async/mch_07/nbproject/private/private.properties new file mode 100644 index 0000000..a5ab360 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter09/async/mch_07/nbproject/private/private.properties @@ -0,0 +1,6 @@ +compile.on.save=true +do.depend=false +do.jar=true +javac.debug=true +javadoc.preview=true +user.properties.file=C:\\Users\\Leo\\.netbeans\\7.0\\build.properties diff --git a/Pro Java 7 NIO.2/Chapter09/async/mch_07/nbproject/private/private.xml b/Pro Java 7 NIO.2/Chapter09/async/mch_07/nbproject/private/private.xml new file mode 100644 index 0000000..c1f155a --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter09/async/mch_07/nbproject/private/private.xml @@ -0,0 +1,4 @@ + + + + diff --git a/Pro Java 7 NIO.2/Chapter09/async/mch_07/nbproject/project.properties b/Pro Java 7 NIO.2/Chapter09/async/mch_07/nbproject/project.properties new file mode 100644 index 0000000..2d0ad34 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter09/async/mch_07/nbproject/project.properties @@ -0,0 +1,72 @@ +annotation.processing.enabled=true +annotation.processing.enabled.in.editor=false +annotation.processing.run.all.processors=true +annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output +application.title=mch_07 +application.vendor=Leo +build.classes.dir=${build.dir}/classes +build.classes.excludes=**/*.java,**/*.form +# This directory is removed when the project is cleaned: +build.dir=build +build.generated.dir=${build.dir}/generated +build.generated.sources.dir=${build.dir}/generated-sources +# Only compile against the classpath explicitly listed here: +build.sysclasspath=ignore +build.test.classes.dir=${build.dir}/test/classes +build.test.results.dir=${build.dir}/test/results +# Uncomment to specify the preferred debugger connection transport: +#debug.transport=dt_socket +debug.classpath=\ + ${run.classpath} +debug.test.classpath=\ + ${run.test.classpath} +# This directory is removed when the project is cleaned: +dist.dir=dist +dist.jar=${dist.dir}/mch_07.jar +dist.javadoc.dir=${dist.dir}/javadoc +endorsed.classpath= +excludes= +includes=** +jar.compress=false +javac.classpath= +# Space-separated list of extra javac options +javac.compilerargs= +javac.deprecation=false +javac.processorpath=\ + ${javac.classpath} +javac.source=1.7 +javac.target=1.7 +javac.test.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +javac.test.processorpath=\ + ${javac.test.classpath} +javadoc.additionalparam= +javadoc.author=false +javadoc.encoding=${source.encoding} +javadoc.noindex=false +javadoc.nonavbar=false +javadoc.notree=false +javadoc.private=false +javadoc.splitindex=true +javadoc.use=true +javadoc.version=false +javadoc.windowtitle= +main.class=mch_07.Main +manifest.file=manifest.mf +meta.inf.dir=${src.dir}/META-INF +mkdist.disabled=false +platform.active=default_platform +run.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +# Space-separated list of JVM arguments used when running the project +# (you may also define separate properties like run-sys-prop.name=value instead of -Dname=value +# or test-sys-prop.name=value to set system properties for unit tests): +run.jvmargs= +run.test.classpath=\ + ${javac.test.classpath}:\ + ${build.test.classes.dir} +source.encoding=UTF-8 +src.dir=src +test.src.dir=test diff --git a/Pro Java 7 NIO.2/Chapter09/async/mch_07/nbproject/project.xml b/Pro Java 7 NIO.2/Chapter09/async/mch_07/nbproject/project.xml new file mode 100644 index 0000000..7904efc --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter09/async/mch_07/nbproject/project.xml @@ -0,0 +1,15 @@ + + + org.netbeans.modules.java.j2seproject + + + mch_07 + + + + + + + + + diff --git a/Pro Java 7 NIO.2/Chapter09/async/mch_07/src/mch_07/Main.java b/Pro Java 7 NIO.2/Chapter09/async/mch_07/src/mch_07/Main.java new file mode 100644 index 0000000..5564ab5 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter09/async/mch_07/src/mch_07/Main.java @@ -0,0 +1,56 @@ +package mch_07; + +import java.nio.ByteBuffer; +import java.nio.channels.AsynchronousFileChannel; +import java.nio.channels.CompletionHandler; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.nio.file.StandardOpenOption; + +/** + * + * @author Apress + */ +public class Main { + + static Thread current; + + public static void main(String[] args) { + + ByteBuffer buffer = ByteBuffer.allocate(100); + Path path = Paths.get("C:/rafaelnadal/grandslam/RolandGarros", "story.txt"); + + try (AsynchronousFileChannel asynchronousFileChannel = AsynchronousFileChannel.open(path, StandardOpenOption.READ)) { + + current = Thread.currentThread(); + asynchronousFileChannel.read(buffer, 0, "Read operation status ...", new CompletionHandler() { + + @Override + public void completed(Integer result, Object attachment) { + System.out.println(attachment); + System.out.print("Read bytes: " + result); + current.interrupt(); + } + + @Override + public void failed(Throwable exc, Object attachment) { + System.out.println(attachment); + System.out.println("Error:" + exc); + current.interrupt(); + } + }); + + System.out.println("\nWaiting for reading operation to end ...\n"); + try { + current.join(); + } catch (InterruptedException e) { + } + + //now the buffer contains the read bytes + System.out.println("\n\nClosing everything and leave! Bye, bye ..."); + + } catch (Exception ex) { + System.err.println(ex); + } + } +} diff --git a/Pro Java 7 NIO.2/Chapter09/async/mch_08/build.xml b/Pro Java 7 NIO.2/Chapter09/async/mch_08/build.xml new file mode 100644 index 0000000..6048425 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter09/async/mch_08/build.xml @@ -0,0 +1,74 @@ + + + + + + + + + + + Builds, tests, and runs the project mch_08. + + + diff --git a/Pro Java 7 NIO.2/Chapter09/async/mch_08/build/built-jar.properties b/Pro Java 7 NIO.2/Chapter09/async/mch_08/build/built-jar.properties new file mode 100644 index 0000000..6719169 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter09/async/mch_08/build/built-jar.properties @@ -0,0 +1,4 @@ +#Thu, 03 Nov 2011 07:00:44 +0200 + + +C\:\\NIO\\async\\mch_08= diff --git a/Pro Java 7 NIO.2/Chapter09/async/mch_08/build/classes/.netbeans_automatic_build b/Pro Java 7 NIO.2/Chapter09/async/mch_08/build/classes/.netbeans_automatic_build new file mode 100644 index 0000000..e69de29 diff --git a/Pro Java 7 NIO.2/Chapter09/async/mch_08/build/classes/mch_08/Main$1.class b/Pro Java 7 NIO.2/Chapter09/async/mch_08/build/classes/mch_08/Main$1.class new file mode 100644 index 0000000..7660d41 Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter09/async/mch_08/build/classes/mch_08/Main$1.class differ diff --git a/Pro Java 7 NIO.2/Chapter09/async/mch_08/build/classes/mch_08/Main.class b/Pro Java 7 NIO.2/Chapter09/async/mch_08/build/classes/mch_08/Main.class new file mode 100644 index 0000000..14d0b63 Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter09/async/mch_08/build/classes/mch_08/Main.class differ diff --git a/Pro Java 7 NIO.2/Chapter09/async/mch_08/dist/README.TXT b/Pro Java 7 NIO.2/Chapter09/async/mch_08/dist/README.TXT new file mode 100644 index 0000000..58f1834 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter09/async/mch_08/dist/README.TXT @@ -0,0 +1,32 @@ +======================== +BUILD OUTPUT DESCRIPTION +======================== + +When you build an Java application project that has a main class, the IDE +automatically copies all of the JAR +files on the projects classpath to your projects dist/lib folder. The IDE +also adds each of the JAR files to the Class-Path element in the application +JAR files manifest file (MANIFEST.MF). + +To run the project from the command line, go to the dist folder and +type the following: + +java -jar "mch_08.jar" + +To distribute this project, zip up the dist folder (including the lib folder) +and distribute the ZIP file. + +Notes: + +* If two JAR files on the project classpath have the same name, only the first +JAR file is copied to the lib folder. +* Only JAR files are copied to the lib folder. +If the classpath contains other types of files or folders, these files (folders) +are not copied. +* If a library on the projects classpath also has a Class-Path element +specified in the manifest,the content of the Class-Path element has to be on +the projects runtime path. +* To set a main class in a standard Java project, right-click the project node +in the Projects window and choose Properties. Then click Run and enter the +class name in the Main Class field. Alternatively, you can manually type the +class name in the manifest Main-Class element. diff --git a/Pro Java 7 NIO.2/Chapter09/async/mch_08/dist/mch_08.jar b/Pro Java 7 NIO.2/Chapter09/async/mch_08/dist/mch_08.jar new file mode 100644 index 0000000..b9f25a7 Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter09/async/mch_08/dist/mch_08.jar differ diff --git a/Pro Java 7 NIO.2/Chapter09/async/mch_08/manifest.mf b/Pro Java 7 NIO.2/Chapter09/async/mch_08/manifest.mf new file mode 100644 index 0000000..328e8e5 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter09/async/mch_08/manifest.mf @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +X-COMMENT: Main-Class will be added automatically by build + diff --git a/Pro Java 7 NIO.2/Chapter09/async/mch_08/nbproject/build-impl.xml b/Pro Java 7 NIO.2/Chapter09/async/mch_08/nbproject/build-impl.xml new file mode 100644 index 0000000..2eed0e6 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter09/async/mch_08/nbproject/build-impl.xml @@ -0,0 +1,1041 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set src.dir + Must set test.src.dir + Must set build.dir + Must set dist.dir + Must set build.classes.dir + Must set dist.javadoc.dir + Must set build.test.classes.dir + Must set build.test.results.dir + Must set build.classes.excludes + Must set dist.jar + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set JVM to use for profiling in profiler.info.jvm + Must set profiler agent JVM arguments in profiler.info.jvmargs.agent + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + + + + + + java -cp "${run.classpath.with.dist.jar}" ${main.class} + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + java -jar "${dist.jar.resolved}" + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set run.class + + + + Must select one file in the IDE or set run.class + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set debug.class + + + + + Must select one file in the IDE or set debug.class + + + + + Must set fix.includes + + + + + + + + + + + + + + + + + Must select one file in the IDE or set profile.class + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + Some tests failed; see details above. + + + + + + + + + Must select some files in the IDE or set test.includes + + + + Some tests failed; see details above. + + + + + Must select one file in the IDE or set test.class + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Pro Java 7 NIO.2/Chapter09/async/mch_08/nbproject/genfiles.properties b/Pro Java 7 NIO.2/Chapter09/async/mch_08/nbproject/genfiles.properties new file mode 100644 index 0000000..7854d43 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter09/async/mch_08/nbproject/genfiles.properties @@ -0,0 +1,8 @@ +build.xml.data.CRC32=216cb1cb +build.xml.script.CRC32=96f54279 +build.xml.stylesheet.CRC32=28e38971@1.43.1.45 +# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. +# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. +nbproject/build-impl.xml.data.CRC32=216cb1cb +nbproject/build-impl.xml.script.CRC32=dca3027c +nbproject/build-impl.xml.stylesheet.CRC32=0c01fd8e@1.43.1.45 diff --git a/Pro Java 7 NIO.2/Chapter09/async/mch_08/nbproject/private/config.properties b/Pro Java 7 NIO.2/Chapter09/async/mch_08/nbproject/private/config.properties new file mode 100644 index 0000000..e69de29 diff --git a/Pro Java 7 NIO.2/Chapter09/async/mch_08/nbproject/private/private.properties b/Pro Java 7 NIO.2/Chapter09/async/mch_08/nbproject/private/private.properties new file mode 100644 index 0000000..a5ab360 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter09/async/mch_08/nbproject/private/private.properties @@ -0,0 +1,6 @@ +compile.on.save=true +do.depend=false +do.jar=true +javac.debug=true +javadoc.preview=true +user.properties.file=C:\\Users\\Leo\\.netbeans\\7.0\\build.properties diff --git a/Pro Java 7 NIO.2/Chapter09/async/mch_08/nbproject/private/private.xml b/Pro Java 7 NIO.2/Chapter09/async/mch_08/nbproject/private/private.xml new file mode 100644 index 0000000..c1f155a --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter09/async/mch_08/nbproject/private/private.xml @@ -0,0 +1,4 @@ + + + + diff --git a/Pro Java 7 NIO.2/Chapter09/async/mch_08/nbproject/project.properties b/Pro Java 7 NIO.2/Chapter09/async/mch_08/nbproject/project.properties new file mode 100644 index 0000000..629aa83 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter09/async/mch_08/nbproject/project.properties @@ -0,0 +1,72 @@ +annotation.processing.enabled=true +annotation.processing.enabled.in.editor=false +annotation.processing.run.all.processors=true +annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output +application.title=mch_08 +application.vendor=Leo +build.classes.dir=${build.dir}/classes +build.classes.excludes=**/*.java,**/*.form +# This directory is removed when the project is cleaned: +build.dir=build +build.generated.dir=${build.dir}/generated +build.generated.sources.dir=${build.dir}/generated-sources +# Only compile against the classpath explicitly listed here: +build.sysclasspath=ignore +build.test.classes.dir=${build.dir}/test/classes +build.test.results.dir=${build.dir}/test/results +# Uncomment to specify the preferred debugger connection transport: +#debug.transport=dt_socket +debug.classpath=\ + ${run.classpath} +debug.test.classpath=\ + ${run.test.classpath} +# This directory is removed when the project is cleaned: +dist.dir=dist +dist.jar=${dist.dir}/mch_08.jar +dist.javadoc.dir=${dist.dir}/javadoc +endorsed.classpath= +excludes= +includes=** +jar.compress=false +javac.classpath= +# Space-separated list of extra javac options +javac.compilerargs= +javac.deprecation=false +javac.processorpath=\ + ${javac.classpath} +javac.source=1.7 +javac.target=1.7 +javac.test.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +javac.test.processorpath=\ + ${javac.test.classpath} +javadoc.additionalparam= +javadoc.author=false +javadoc.encoding=${source.encoding} +javadoc.noindex=false +javadoc.nonavbar=false +javadoc.notree=false +javadoc.private=false +javadoc.splitindex=true +javadoc.use=true +javadoc.version=false +javadoc.windowtitle= +main.class=mch_08.Main +manifest.file=manifest.mf +meta.inf.dir=${src.dir}/META-INF +mkdist.disabled=false +platform.active=default_platform +run.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +# Space-separated list of JVM arguments used when running the project +# (you may also define separate properties like run-sys-prop.name=value instead of -Dname=value +# or test-sys-prop.name=value to set system properties for unit tests): +run.jvmargs= +run.test.classpath=\ + ${javac.test.classpath}:\ + ${build.test.classes.dir} +source.encoding=UTF-8 +src.dir=src +test.src.dir=test diff --git a/Pro Java 7 NIO.2/Chapter09/async/mch_08/nbproject/project.xml b/Pro Java 7 NIO.2/Chapter09/async/mch_08/nbproject/project.xml new file mode 100644 index 0000000..e64bcc4 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter09/async/mch_08/nbproject/project.xml @@ -0,0 +1,15 @@ + + + org.netbeans.modules.java.j2seproject + + + mch_08 + + + + + + + + + diff --git a/Pro Java 7 NIO.2/Chapter09/async/mch_08/src/mch_08/Main.java b/Pro Java 7 NIO.2/Chapter09/async/mch_08/src/mch_08/Main.java new file mode 100644 index 0000000..4793529 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter09/async/mch_08/src/mch_08/Main.java @@ -0,0 +1,62 @@ +package mch_08; + +import java.nio.ByteBuffer; +import java.nio.channels.AsynchronousFileChannel; +import java.nio.channels.CompletionHandler; +import java.nio.charset.Charset; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.nio.file.StandardOpenOption; + +/** + * + * @author Apress + */ +public class Main { + + static Thread current; + static final Path path = Paths.get("C:/rafaelnadal/grandslam/RolandGarros", "story.txt"); + + public static void main(String[] args) { + + CompletionHandler handler = new CompletionHandler() { + + String encoding = System.getProperty("file.encoding"); + + @Override + public void completed(Integer result, ByteBuffer attachment) { + System.out.println("Read bytes: " + result); + attachment.flip(); + System.out.print(Charset.forName(encoding).decode(attachment)); + attachment.clear(); + current.interrupt(); + } + + @Override + public void failed(Throwable exc, ByteBuffer attachment) { + System.out.println(attachment); + System.out.println("Error:" + exc); + current.interrupt(); + } + }; + + try (AsynchronousFileChannel asynchronousFileChannel = AsynchronousFileChannel.open(path, StandardOpenOption.READ)) { + + current = Thread.currentThread(); + ByteBuffer buffer = ByteBuffer.allocate(100); + asynchronousFileChannel.read(buffer, 0, buffer, handler); + + System.out.println("\nWaiting for reading operation to end ...\n"); + try { + current.join(); + } catch (InterruptedException e) { + } + + //the buffer was passed as attachment + System.out.println("\n\nClosing everything and leave! Bye, bye ..."); + + } catch (Exception ex) { + System.err.println(ex); + } + } +} diff --git a/Pro Java 7 NIO.2/Chapter09/async/mch_09_client/build.xml b/Pro Java 7 NIO.2/Chapter09/async/mch_09_client/build.xml new file mode 100644 index 0000000..f7f911e --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter09/async/mch_09_client/build.xml @@ -0,0 +1,74 @@ + + + + + + + + + + + Builds, tests, and runs the project mch_09_client. + + + diff --git a/Pro Java 7 NIO.2/Chapter09/async/mch_09_client/build/built-jar.properties b/Pro Java 7 NIO.2/Chapter09/async/mch_09_client/build/built-jar.properties new file mode 100644 index 0000000..fb95bc1 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter09/async/mch_09_client/build/built-jar.properties @@ -0,0 +1,4 @@ +#Thu, 03 Nov 2011 07:20:05 +0200 + + +C\:\\NIO\\async\\mch_09_client= diff --git a/Pro Java 7 NIO.2/Chapter09/async/mch_09_client/build/classes/.netbeans_automatic_build b/Pro Java 7 NIO.2/Chapter09/async/mch_09_client/build/classes/.netbeans_automatic_build new file mode 100644 index 0000000..e69de29 diff --git a/Pro Java 7 NIO.2/Chapter09/async/mch_09_client/build/classes/mch_09_client/Main.class b/Pro Java 7 NIO.2/Chapter09/async/mch_09_client/build/classes/mch_09_client/Main.class new file mode 100644 index 0000000..178d6f6 Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter09/async/mch_09_client/build/classes/mch_09_client/Main.class differ diff --git a/Pro Java 7 NIO.2/Chapter09/async/mch_09_client/dist/README.TXT b/Pro Java 7 NIO.2/Chapter09/async/mch_09_client/dist/README.TXT new file mode 100644 index 0000000..5d8d533 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter09/async/mch_09_client/dist/README.TXT @@ -0,0 +1,32 @@ +======================== +BUILD OUTPUT DESCRIPTION +======================== + +When you build an Java application project that has a main class, the IDE +automatically copies all of the JAR +files on the projects classpath to your projects dist/lib folder. The IDE +also adds each of the JAR files to the Class-Path element in the application +JAR files manifest file (MANIFEST.MF). + +To run the project from the command line, go to the dist folder and +type the following: + +java -jar "mch_09_client.jar" + +To distribute this project, zip up the dist folder (including the lib folder) +and distribute the ZIP file. + +Notes: + +* If two JAR files on the project classpath have the same name, only the first +JAR file is copied to the lib folder. +* Only JAR files are copied to the lib folder. +If the classpath contains other types of files or folders, these files (folders) +are not copied. +* If a library on the projects classpath also has a Class-Path element +specified in the manifest,the content of the Class-Path element has to be on +the projects runtime path. +* To set a main class in a standard Java project, right-click the project node +in the Projects window and choose Properties. Then click Run and enter the +class name in the Main Class field. Alternatively, you can manually type the +class name in the manifest Main-Class element. diff --git a/Pro Java 7 NIO.2/Chapter09/async/mch_09_client/dist/mch_09_client.jar b/Pro Java 7 NIO.2/Chapter09/async/mch_09_client/dist/mch_09_client.jar new file mode 100644 index 0000000..652572e Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter09/async/mch_09_client/dist/mch_09_client.jar differ diff --git a/Pro Java 7 NIO.2/Chapter09/async/mch_09_client/manifest.mf b/Pro Java 7 NIO.2/Chapter09/async/mch_09_client/manifest.mf new file mode 100644 index 0000000..328e8e5 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter09/async/mch_09_client/manifest.mf @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +X-COMMENT: Main-Class will be added automatically by build + diff --git a/Pro Java 7 NIO.2/Chapter09/async/mch_09_client/nbproject/build-impl.xml b/Pro Java 7 NIO.2/Chapter09/async/mch_09_client/nbproject/build-impl.xml new file mode 100644 index 0000000..dad19df --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter09/async/mch_09_client/nbproject/build-impl.xml @@ -0,0 +1,1041 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set src.dir + Must set test.src.dir + Must set build.dir + Must set dist.dir + Must set build.classes.dir + Must set dist.javadoc.dir + Must set build.test.classes.dir + Must set build.test.results.dir + Must set build.classes.excludes + Must set dist.jar + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set JVM to use for profiling in profiler.info.jvm + Must set profiler agent JVM arguments in profiler.info.jvmargs.agent + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + + + + + + java -cp "${run.classpath.with.dist.jar}" ${main.class} + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + java -jar "${dist.jar.resolved}" + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set run.class + + + + Must select one file in the IDE or set run.class + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set debug.class + + + + + Must select one file in the IDE or set debug.class + + + + + Must set fix.includes + + + + + + + + + + + + + + + + + Must select one file in the IDE or set profile.class + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + Some tests failed; see details above. + + + + + + + + + Must select some files in the IDE or set test.includes + + + + Some tests failed; see details above. + + + + + Must select one file in the IDE or set test.class + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Pro Java 7 NIO.2/Chapter09/async/mch_09_client/nbproject/genfiles.properties b/Pro Java 7 NIO.2/Chapter09/async/mch_09_client/nbproject/genfiles.properties new file mode 100644 index 0000000..f172b00 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter09/async/mch_09_client/nbproject/genfiles.properties @@ -0,0 +1,8 @@ +build.xml.data.CRC32=f3fd69d4 +build.xml.script.CRC32=f3b9a128 +build.xml.stylesheet.CRC32=28e38971@1.43.1.45 +# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. +# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. +nbproject/build-impl.xml.data.CRC32=f3fd69d4 +nbproject/build-impl.xml.script.CRC32=9654bcfc +nbproject/build-impl.xml.stylesheet.CRC32=0c01fd8e@1.43.1.45 diff --git a/Pro Java 7 NIO.2/Chapter09/async/mch_09_client/nbproject/private/config.properties b/Pro Java 7 NIO.2/Chapter09/async/mch_09_client/nbproject/private/config.properties new file mode 100644 index 0000000..e69de29 diff --git a/Pro Java 7 NIO.2/Chapter09/async/mch_09_client/nbproject/private/private.properties b/Pro Java 7 NIO.2/Chapter09/async/mch_09_client/nbproject/private/private.properties new file mode 100644 index 0000000..a5ab360 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter09/async/mch_09_client/nbproject/private/private.properties @@ -0,0 +1,6 @@ +compile.on.save=true +do.depend=false +do.jar=true +javac.debug=true +javadoc.preview=true +user.properties.file=C:\\Users\\Leo\\.netbeans\\7.0\\build.properties diff --git a/Pro Java 7 NIO.2/Chapter09/async/mch_09_client/nbproject/private/private.xml b/Pro Java 7 NIO.2/Chapter09/async/mch_09_client/nbproject/private/private.xml new file mode 100644 index 0000000..c1f155a --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter09/async/mch_09_client/nbproject/private/private.xml @@ -0,0 +1,4 @@ + + + + diff --git a/Pro Java 7 NIO.2/Chapter09/async/mch_09_client/nbproject/project.properties b/Pro Java 7 NIO.2/Chapter09/async/mch_09_client/nbproject/project.properties new file mode 100644 index 0000000..e93f049 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter09/async/mch_09_client/nbproject/project.properties @@ -0,0 +1,72 @@ +annotation.processing.enabled=true +annotation.processing.enabled.in.editor=false +annotation.processing.run.all.processors=true +annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output +application.title=mch_09_client +application.vendor=Leo +build.classes.dir=${build.dir}/classes +build.classes.excludes=**/*.java,**/*.form +# This directory is removed when the project is cleaned: +build.dir=build +build.generated.dir=${build.dir}/generated +build.generated.sources.dir=${build.dir}/generated-sources +# Only compile against the classpath explicitly listed here: +build.sysclasspath=ignore +build.test.classes.dir=${build.dir}/test/classes +build.test.results.dir=${build.dir}/test/results +# Uncomment to specify the preferred debugger connection transport: +#debug.transport=dt_socket +debug.classpath=\ + ${run.classpath} +debug.test.classpath=\ + ${run.test.classpath} +# This directory is removed when the project is cleaned: +dist.dir=dist +dist.jar=${dist.dir}/mch_09_client.jar +dist.javadoc.dir=${dist.dir}/javadoc +endorsed.classpath= +excludes= +includes=** +jar.compress=false +javac.classpath= +# Space-separated list of extra javac options +javac.compilerargs= +javac.deprecation=false +javac.processorpath=\ + ${javac.classpath} +javac.source=1.7 +javac.target=1.7 +javac.test.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +javac.test.processorpath=\ + ${javac.test.classpath} +javadoc.additionalparam= +javadoc.author=false +javadoc.encoding=${source.encoding} +javadoc.noindex=false +javadoc.nonavbar=false +javadoc.notree=false +javadoc.private=false +javadoc.splitindex=true +javadoc.use=true +javadoc.version=false +javadoc.windowtitle= +main.class=mch_09_client.Main +manifest.file=manifest.mf +meta.inf.dir=${src.dir}/META-INF +mkdist.disabled=false +platform.active=default_platform +run.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +# Space-separated list of JVM arguments used when running the project +# (you may also define separate properties like run-sys-prop.name=value instead of -Dname=value +# or test-sys-prop.name=value to set system properties for unit tests): +run.jvmargs= +run.test.classpath=\ + ${javac.test.classpath}:\ + ${build.test.classes.dir} +source.encoding=UTF-8 +src.dir=src +test.src.dir=test diff --git a/Pro Java 7 NIO.2/Chapter09/async/mch_09_client/nbproject/project.xml b/Pro Java 7 NIO.2/Chapter09/async/mch_09_client/nbproject/project.xml new file mode 100644 index 0000000..14808c5 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter09/async/mch_09_client/nbproject/project.xml @@ -0,0 +1,15 @@ + + + org.netbeans.modules.java.j2seproject + + + mch_09_client + + + + + + + + + diff --git a/Pro Java 7 NIO.2/Chapter09/async/mch_09_client/src/mch_09_client/Main.java b/Pro Java 7 NIO.2/Chapter09/async/mch_09_client/src/mch_09_client/Main.java new file mode 100644 index 0000000..d1a8eb6 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter09/async/mch_09_client/src/mch_09_client/Main.java @@ -0,0 +1,85 @@ +package mch_09_client; + +import java.io.IOException; +import java.net.InetSocketAddress; +import java.net.StandardSocketOptions; +import java.nio.ByteBuffer; +import java.nio.CharBuffer; +import java.nio.channels.AsynchronousSocketChannel; +import java.nio.charset.Charset; +import java.nio.charset.CharsetDecoder; +import java.util.Random; +import java.util.concurrent.ExecutionException; + +/** + * + * @author Apress + */ +public class Main { + + public static void main(String[] args) { + + final int DEFAULT_PORT = 5555; + final String IP = "127.0.0.1"; + ByteBuffer buffer = ByteBuffer.allocateDirect(1024); + ByteBuffer helloBuffer = ByteBuffer.wrap("Hello !".getBytes()); + ByteBuffer randomBuffer; + CharBuffer charBuffer; + Charset charset = Charset.defaultCharset(); + CharsetDecoder decoder = charset.newDecoder(); + + //create asynchronous socket channel bound to the default group + try (AsynchronousSocketChannel asynchronousSocketChannel = AsynchronousSocketChannel.open()) { + + if (asynchronousSocketChannel.isOpen()) { + + //set some options + asynchronousSocketChannel.setOption(StandardSocketOptions.SO_RCVBUF, 128 * 1024); + asynchronousSocketChannel.setOption(StandardSocketOptions.SO_SNDBUF, 128 * 1024); + asynchronousSocketChannel.setOption(StandardSocketOptions.SO_KEEPALIVE, true); + //connect this channel's socket + Void connect = asynchronousSocketChannel.connect(new InetSocketAddress(IP, DEFAULT_PORT)).get(); + + if (connect == null) { + + System.out.println("Local address: " + asynchronousSocketChannel.getLocalAddress()); + + //transmitting data + asynchronousSocketChannel.write(helloBuffer).get(); + + while (asynchronousSocketChannel.read(buffer).get() != -1) { + + buffer.flip(); + + charBuffer = decoder.decode(buffer); + System.out.println(charBuffer.toString()); + + if (buffer.hasRemaining()) { + buffer.compact(); + } else { + buffer.clear(); + } + + int r = new Random().nextInt(100); + if (r == 50) { + System.out.println("50 was generated! Close the asynchronous socket channel!"); + break; + } else { + randomBuffer = ByteBuffer.wrap("Random number:".concat(String.valueOf(r)).getBytes()); + asynchronousSocketChannel.write(randomBuffer).get(); + } + } + + } else { + System.out.println("The connection cannot be established!"); + } + + } else { + System.out.println("The asynchronous socket channel cannot be opened!"); + } + + } catch (IOException | InterruptedException | ExecutionException ex) { + System.err.println(ex); + } + } +} diff --git a/Pro Java 7 NIO.2/Chapter09/async/mch_09_server/build.xml b/Pro Java 7 NIO.2/Chapter09/async/mch_09_server/build.xml new file mode 100644 index 0000000..92dda4d --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter09/async/mch_09_server/build.xml @@ -0,0 +1,74 @@ + + + + + + + + + + + Builds, tests, and runs the project mch_09_server. + + + diff --git a/Pro Java 7 NIO.2/Chapter09/async/mch_09_server/build/built-jar.properties b/Pro Java 7 NIO.2/Chapter09/async/mch_09_server/build/built-jar.properties new file mode 100644 index 0000000..21253a0 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter09/async/mch_09_server/build/built-jar.properties @@ -0,0 +1,4 @@ +#Thu, 03 Nov 2011 07:18:22 +0200 + + +C\:\\NIO\\async\\mch_09_server= diff --git a/Pro Java 7 NIO.2/Chapter09/async/mch_09_server/build/classes/.netbeans_automatic_build b/Pro Java 7 NIO.2/Chapter09/async/mch_09_server/build/classes/.netbeans_automatic_build new file mode 100644 index 0000000..e69de29 diff --git a/Pro Java 7 NIO.2/Chapter09/async/mch_09_server/build/classes/mch_09_server/Main.class b/Pro Java 7 NIO.2/Chapter09/async/mch_09_server/build/classes/mch_09_server/Main.class new file mode 100644 index 0000000..e2cc8dc Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter09/async/mch_09_server/build/classes/mch_09_server/Main.class differ diff --git a/Pro Java 7 NIO.2/Chapter09/async/mch_09_server/dist/README.TXT b/Pro Java 7 NIO.2/Chapter09/async/mch_09_server/dist/README.TXT new file mode 100644 index 0000000..19c587a --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter09/async/mch_09_server/dist/README.TXT @@ -0,0 +1,32 @@ +======================== +BUILD OUTPUT DESCRIPTION +======================== + +When you build an Java application project that has a main class, the IDE +automatically copies all of the JAR +files on the projects classpath to your projects dist/lib folder. The IDE +also adds each of the JAR files to the Class-Path element in the application +JAR files manifest file (MANIFEST.MF). + +To run the project from the command line, go to the dist folder and +type the following: + +java -jar "mch_09_server.jar" + +To distribute this project, zip up the dist folder (including the lib folder) +and distribute the ZIP file. + +Notes: + +* If two JAR files on the project classpath have the same name, only the first +JAR file is copied to the lib folder. +* Only JAR files are copied to the lib folder. +If the classpath contains other types of files or folders, these files (folders) +are not copied. +* If a library on the projects classpath also has a Class-Path element +specified in the manifest,the content of the Class-Path element has to be on +the projects runtime path. +* To set a main class in a standard Java project, right-click the project node +in the Projects window and choose Properties. Then click Run and enter the +class name in the Main Class field. Alternatively, you can manually type the +class name in the manifest Main-Class element. diff --git a/Pro Java 7 NIO.2/Chapter09/async/mch_09_server/dist/mch_09_server.jar b/Pro Java 7 NIO.2/Chapter09/async/mch_09_server/dist/mch_09_server.jar new file mode 100644 index 0000000..42c498c Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter09/async/mch_09_server/dist/mch_09_server.jar differ diff --git a/Pro Java 7 NIO.2/Chapter09/async/mch_09_server/manifest.mf b/Pro Java 7 NIO.2/Chapter09/async/mch_09_server/manifest.mf new file mode 100644 index 0000000..328e8e5 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter09/async/mch_09_server/manifest.mf @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +X-COMMENT: Main-Class will be added automatically by build + diff --git a/Pro Java 7 NIO.2/Chapter09/async/mch_09_server/nbproject/build-impl.xml b/Pro Java 7 NIO.2/Chapter09/async/mch_09_server/nbproject/build-impl.xml new file mode 100644 index 0000000..ec8636f --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter09/async/mch_09_server/nbproject/build-impl.xml @@ -0,0 +1,1041 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set src.dir + Must set test.src.dir + Must set build.dir + Must set dist.dir + Must set build.classes.dir + Must set dist.javadoc.dir + Must set build.test.classes.dir + Must set build.test.results.dir + Must set build.classes.excludes + Must set dist.jar + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set JVM to use for profiling in profiler.info.jvm + Must set profiler agent JVM arguments in profiler.info.jvmargs.agent + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + + + + + + java -cp "${run.classpath.with.dist.jar}" ${main.class} + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + java -jar "${dist.jar.resolved}" + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set run.class + + + + Must select one file in the IDE or set run.class + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set debug.class + + + + + Must select one file in the IDE or set debug.class + + + + + Must set fix.includes + + + + + + + + + + + + + + + + + Must select one file in the IDE or set profile.class + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + Some tests failed; see details above. + + + + + + + + + Must select some files in the IDE or set test.includes + + + + Some tests failed; see details above. + + + + + Must select one file in the IDE or set test.class + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Pro Java 7 NIO.2/Chapter09/async/mch_09_server/nbproject/genfiles.properties b/Pro Java 7 NIO.2/Chapter09/async/mch_09_server/nbproject/genfiles.properties new file mode 100644 index 0000000..beb8d2a --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter09/async/mch_09_server/nbproject/genfiles.properties @@ -0,0 +1,8 @@ +build.xml.data.CRC32=24a3cdc3 +build.xml.script.CRC32=acc2dc11 +build.xml.stylesheet.CRC32=28e38971@1.43.1.45 +# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. +# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. +nbproject/build-impl.xml.data.CRC32=24a3cdc3 +nbproject/build-impl.xml.script.CRC32=5e835dff +nbproject/build-impl.xml.stylesheet.CRC32=0c01fd8e@1.43.1.45 diff --git a/Pro Java 7 NIO.2/Chapter09/async/mch_09_server/nbproject/private/config.properties b/Pro Java 7 NIO.2/Chapter09/async/mch_09_server/nbproject/private/config.properties new file mode 100644 index 0000000..e69de29 diff --git a/Pro Java 7 NIO.2/Chapter09/async/mch_09_server/nbproject/private/private.properties b/Pro Java 7 NIO.2/Chapter09/async/mch_09_server/nbproject/private/private.properties new file mode 100644 index 0000000..a5ab360 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter09/async/mch_09_server/nbproject/private/private.properties @@ -0,0 +1,6 @@ +compile.on.save=true +do.depend=false +do.jar=true +javac.debug=true +javadoc.preview=true +user.properties.file=C:\\Users\\Leo\\.netbeans\\7.0\\build.properties diff --git a/Pro Java 7 NIO.2/Chapter09/async/mch_09_server/nbproject/private/private.xml b/Pro Java 7 NIO.2/Chapter09/async/mch_09_server/nbproject/private/private.xml new file mode 100644 index 0000000..c1f155a --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter09/async/mch_09_server/nbproject/private/private.xml @@ -0,0 +1,4 @@ + + + + diff --git a/Pro Java 7 NIO.2/Chapter09/async/mch_09_server/nbproject/project.properties b/Pro Java 7 NIO.2/Chapter09/async/mch_09_server/nbproject/project.properties new file mode 100644 index 0000000..47cc8bf --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter09/async/mch_09_server/nbproject/project.properties @@ -0,0 +1,72 @@ +annotation.processing.enabled=true +annotation.processing.enabled.in.editor=false +annotation.processing.run.all.processors=true +annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output +application.title=mch_09_server +application.vendor=Leo +build.classes.dir=${build.dir}/classes +build.classes.excludes=**/*.java,**/*.form +# This directory is removed when the project is cleaned: +build.dir=build +build.generated.dir=${build.dir}/generated +build.generated.sources.dir=${build.dir}/generated-sources +# Only compile against the classpath explicitly listed here: +build.sysclasspath=ignore +build.test.classes.dir=${build.dir}/test/classes +build.test.results.dir=${build.dir}/test/results +# Uncomment to specify the preferred debugger connection transport: +#debug.transport=dt_socket +debug.classpath=\ + ${run.classpath} +debug.test.classpath=\ + ${run.test.classpath} +# This directory is removed when the project is cleaned: +dist.dir=dist +dist.jar=${dist.dir}/mch_09_server.jar +dist.javadoc.dir=${dist.dir}/javadoc +endorsed.classpath= +excludes= +includes=** +jar.compress=false +javac.classpath= +# Space-separated list of extra javac options +javac.compilerargs= +javac.deprecation=false +javac.processorpath=\ + ${javac.classpath} +javac.source=1.7 +javac.target=1.7 +javac.test.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +javac.test.processorpath=\ + ${javac.test.classpath} +javadoc.additionalparam= +javadoc.author=false +javadoc.encoding=${source.encoding} +javadoc.noindex=false +javadoc.nonavbar=false +javadoc.notree=false +javadoc.private=false +javadoc.splitindex=true +javadoc.use=true +javadoc.version=false +javadoc.windowtitle= +main.class=mch_09_server.Main +manifest.file=manifest.mf +meta.inf.dir=${src.dir}/META-INF +mkdist.disabled=false +platform.active=default_platform +run.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +# Space-separated list of JVM arguments used when running the project +# (you may also define separate properties like run-sys-prop.name=value instead of -Dname=value +# or test-sys-prop.name=value to set system properties for unit tests): +run.jvmargs= +run.test.classpath=\ + ${javac.test.classpath}:\ + ${build.test.classes.dir} +source.encoding=UTF-8 +src.dir=src +test.src.dir=test diff --git a/Pro Java 7 NIO.2/Chapter09/async/mch_09_server/nbproject/project.xml b/Pro Java 7 NIO.2/Chapter09/async/mch_09_server/nbproject/project.xml new file mode 100644 index 0000000..3755931 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter09/async/mch_09_server/nbproject/project.xml @@ -0,0 +1,15 @@ + + + org.netbeans.modules.java.j2seproject + + + mch_09_server + + + + + + + + + diff --git a/Pro Java 7 NIO.2/Chapter09/async/mch_09_server/src/mch_09_server/Main.java b/Pro Java 7 NIO.2/Chapter09/async/mch_09_server/src/mch_09_server/Main.java new file mode 100644 index 0000000..7e3fe8d --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter09/async/mch_09_server/src/mch_09_server/Main.java @@ -0,0 +1,74 @@ +package mch_09_server; + +import java.io.IOException; +import java.net.InetSocketAddress; +import java.net.StandardSocketOptions; +import java.nio.ByteBuffer; +import java.nio.channels.AsynchronousServerSocketChannel; +import java.nio.channels.AsynchronousSocketChannel; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.Future; + +/** + * + * @author Apress + */ +public class Main { + + public static void main(String[] args) { + + final int DEFAULT_PORT = 5555; + final String IP = "127.0.0.1"; + + //create asynchronous server-socket channel bound to the default group + try (AsynchronousServerSocketChannel asynchronousServerSocketChannel = AsynchronousServerSocketChannel.open()) { + + if (asynchronousServerSocketChannel.isOpen()) { + + //set some options + asynchronousServerSocketChannel.setOption(StandardSocketOptions.SO_RCVBUF, 4 * 1024); + asynchronousServerSocketChannel.setOption(StandardSocketOptions.SO_REUSEADDR, true); + //bind the server-socket channel to local address + asynchronousServerSocketChannel.bind(new InetSocketAddress(IP, DEFAULT_PORT)); + + //display a waiting message while ... waiting clients + System.out.println("Waiting for connections ..."); + while (true) { + Future asynchronousSocketChannelFuture = asynchronousServerSocketChannel.accept(); + + try (AsynchronousSocketChannel asynchronousSocketChannel = asynchronousSocketChannelFuture.get()) { + + System.out.println("Incoming connection from: " + asynchronousSocketChannel.getRemoteAddress()); + + final ByteBuffer buffer = ByteBuffer.allocateDirect(1024); + + //transmitting data + while (asynchronousSocketChannel.read(buffer).get() != -1) { + + buffer.flip(); + + asynchronousSocketChannel.write(buffer).get(); + + if (buffer.hasRemaining()) { + buffer.compact(); + } else { + buffer.clear(); + } + } + + System.out.println(asynchronousSocketChannel.getRemoteAddress() + " was successfully served!"); + + } catch (IOException | InterruptedException | ExecutionException ex) { + System.err.println(ex); + } + } + } else { + System.out.println("The asynchronous server-socket channel cannot be opened!"); + } + + } catch (IOException ex) { + System.err.println(ex); + } + + } +} diff --git a/Pro Java 7 NIO.2/Chapter09/async/mch_09_server_2/build.xml b/Pro Java 7 NIO.2/Chapter09/async/mch_09_server_2/build.xml new file mode 100644 index 0000000..5f8a9a7 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter09/async/mch_09_server_2/build.xml @@ -0,0 +1,74 @@ + + + + + + + + + + + Builds, tests, and runs the project mch_09_server_2. + + + diff --git a/Pro Java 7 NIO.2/Chapter09/async/mch_09_server_2/build/built-jar.properties b/Pro Java 7 NIO.2/Chapter09/async/mch_09_server_2/build/built-jar.properties new file mode 100644 index 0000000..f3c97cc --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter09/async/mch_09_server_2/build/built-jar.properties @@ -0,0 +1,4 @@ +#Thu, 03 Nov 2011 07:21:14 +0200 + + +C\:\\NIO\\async\\mch_09_server_2= diff --git a/Pro Java 7 NIO.2/Chapter09/async/mch_09_server_2/build/classes/.netbeans_automatic_build b/Pro Java 7 NIO.2/Chapter09/async/mch_09_server_2/build/classes/.netbeans_automatic_build new file mode 100644 index 0000000..e69de29 diff --git a/Pro Java 7 NIO.2/Chapter09/async/mch_09_server_2/build/classes/mch_09_server_2/Main$1.class b/Pro Java 7 NIO.2/Chapter09/async/mch_09_server_2/build/classes/mch_09_server_2/Main$1.class new file mode 100644 index 0000000..9456d5c Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter09/async/mch_09_server_2/build/classes/mch_09_server_2/Main$1.class differ diff --git a/Pro Java 7 NIO.2/Chapter09/async/mch_09_server_2/build/classes/mch_09_server_2/Main.class b/Pro Java 7 NIO.2/Chapter09/async/mch_09_server_2/build/classes/mch_09_server_2/Main.class new file mode 100644 index 0000000..90812f9 Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter09/async/mch_09_server_2/build/classes/mch_09_server_2/Main.class differ diff --git a/Pro Java 7 NIO.2/Chapter09/async/mch_09_server_2/dist/README.TXT b/Pro Java 7 NIO.2/Chapter09/async/mch_09_server_2/dist/README.TXT new file mode 100644 index 0000000..736d672 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter09/async/mch_09_server_2/dist/README.TXT @@ -0,0 +1,32 @@ +======================== +BUILD OUTPUT DESCRIPTION +======================== + +When you build an Java application project that has a main class, the IDE +automatically copies all of the JAR +files on the projects classpath to your projects dist/lib folder. The IDE +also adds each of the JAR files to the Class-Path element in the application +JAR files manifest file (MANIFEST.MF). + +To run the project from the command line, go to the dist folder and +type the following: + +java -jar "mch_09_server_2.jar" + +To distribute this project, zip up the dist folder (including the lib folder) +and distribute the ZIP file. + +Notes: + +* If two JAR files on the project classpath have the same name, only the first +JAR file is copied to the lib folder. +* Only JAR files are copied to the lib folder. +If the classpath contains other types of files or folders, these files (folders) +are not copied. +* If a library on the projects classpath also has a Class-Path element +specified in the manifest,the content of the Class-Path element has to be on +the projects runtime path. +* To set a main class in a standard Java project, right-click the project node +in the Projects window and choose Properties. Then click Run and enter the +class name in the Main Class field. Alternatively, you can manually type the +class name in the manifest Main-Class element. diff --git a/Pro Java 7 NIO.2/Chapter09/async/mch_09_server_2/dist/mch_09_server_2.jar b/Pro Java 7 NIO.2/Chapter09/async/mch_09_server_2/dist/mch_09_server_2.jar new file mode 100644 index 0000000..cc891b8 Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter09/async/mch_09_server_2/dist/mch_09_server_2.jar differ diff --git a/Pro Java 7 NIO.2/Chapter09/async/mch_09_server_2/manifest.mf b/Pro Java 7 NIO.2/Chapter09/async/mch_09_server_2/manifest.mf new file mode 100644 index 0000000..328e8e5 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter09/async/mch_09_server_2/manifest.mf @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +X-COMMENT: Main-Class will be added automatically by build + diff --git a/Pro Java 7 NIO.2/Chapter09/async/mch_09_server_2/nbproject/build-impl.xml b/Pro Java 7 NIO.2/Chapter09/async/mch_09_server_2/nbproject/build-impl.xml new file mode 100644 index 0000000..0ed459f --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter09/async/mch_09_server_2/nbproject/build-impl.xml @@ -0,0 +1,1041 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set src.dir + Must set test.src.dir + Must set build.dir + Must set dist.dir + Must set build.classes.dir + Must set dist.javadoc.dir + Must set build.test.classes.dir + Must set build.test.results.dir + Must set build.classes.excludes + Must set dist.jar + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set JVM to use for profiling in profiler.info.jvm + Must set profiler agent JVM arguments in profiler.info.jvmargs.agent + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + + + + + + java -cp "${run.classpath.with.dist.jar}" ${main.class} + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + java -jar "${dist.jar.resolved}" + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set run.class + + + + Must select one file in the IDE or set run.class + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set debug.class + + + + + Must select one file in the IDE or set debug.class + + + + + Must set fix.includes + + + + + + + + + + + + + + + + + Must select one file in the IDE or set profile.class + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + Some tests failed; see details above. + + + + + + + + + Must select some files in the IDE or set test.includes + + + + Some tests failed; see details above. + + + + + Must select one file in the IDE or set test.class + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Pro Java 7 NIO.2/Chapter09/async/mch_09_server_2/nbproject/genfiles.properties b/Pro Java 7 NIO.2/Chapter09/async/mch_09_server_2/nbproject/genfiles.properties new file mode 100644 index 0000000..90f83be --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter09/async/mch_09_server_2/nbproject/genfiles.properties @@ -0,0 +1,8 @@ +build.xml.data.CRC32=7aa6c529 +build.xml.script.CRC32=98c4e71e +build.xml.stylesheet.CRC32=28e38971@1.43.1.45 +# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. +# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. +nbproject/build-impl.xml.data.CRC32=7aa6c529 +nbproject/build-impl.xml.script.CRC32=4d1df893 +nbproject/build-impl.xml.stylesheet.CRC32=0c01fd8e@1.43.1.45 diff --git a/Pro Java 7 NIO.2/Chapter09/async/mch_09_server_2/nbproject/private/config.properties b/Pro Java 7 NIO.2/Chapter09/async/mch_09_server_2/nbproject/private/config.properties new file mode 100644 index 0000000..e69de29 diff --git a/Pro Java 7 NIO.2/Chapter09/async/mch_09_server_2/nbproject/private/private.properties b/Pro Java 7 NIO.2/Chapter09/async/mch_09_server_2/nbproject/private/private.properties new file mode 100644 index 0000000..a5ab360 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter09/async/mch_09_server_2/nbproject/private/private.properties @@ -0,0 +1,6 @@ +compile.on.save=true +do.depend=false +do.jar=true +javac.debug=true +javadoc.preview=true +user.properties.file=C:\\Users\\Leo\\.netbeans\\7.0\\build.properties diff --git a/Pro Java 7 NIO.2/Chapter09/async/mch_09_server_2/nbproject/private/private.xml b/Pro Java 7 NIO.2/Chapter09/async/mch_09_server_2/nbproject/private/private.xml new file mode 100644 index 0000000..c1f155a --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter09/async/mch_09_server_2/nbproject/private/private.xml @@ -0,0 +1,4 @@ + + + + diff --git a/Pro Java 7 NIO.2/Chapter09/async/mch_09_server_2/nbproject/project.properties b/Pro Java 7 NIO.2/Chapter09/async/mch_09_server_2/nbproject/project.properties new file mode 100644 index 0000000..0a9e94b --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter09/async/mch_09_server_2/nbproject/project.properties @@ -0,0 +1,72 @@ +annotation.processing.enabled=true +annotation.processing.enabled.in.editor=false +annotation.processing.run.all.processors=true +annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output +application.title=mch_09_server_2 +application.vendor=Leo +build.classes.dir=${build.dir}/classes +build.classes.excludes=**/*.java,**/*.form +# This directory is removed when the project is cleaned: +build.dir=build +build.generated.dir=${build.dir}/generated +build.generated.sources.dir=${build.dir}/generated-sources +# Only compile against the classpath explicitly listed here: +build.sysclasspath=ignore +build.test.classes.dir=${build.dir}/test/classes +build.test.results.dir=${build.dir}/test/results +# Uncomment to specify the preferred debugger connection transport: +#debug.transport=dt_socket +debug.classpath=\ + ${run.classpath} +debug.test.classpath=\ + ${run.test.classpath} +# This directory is removed when the project is cleaned: +dist.dir=dist +dist.jar=${dist.dir}/mch_09_server_2.jar +dist.javadoc.dir=${dist.dir}/javadoc +endorsed.classpath= +excludes= +includes=** +jar.compress=false +javac.classpath= +# Space-separated list of extra javac options +javac.compilerargs= +javac.deprecation=false +javac.processorpath=\ + ${javac.classpath} +javac.source=1.7 +javac.target=1.7 +javac.test.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +javac.test.processorpath=\ + ${javac.test.classpath} +javadoc.additionalparam= +javadoc.author=false +javadoc.encoding=${source.encoding} +javadoc.noindex=false +javadoc.nonavbar=false +javadoc.notree=false +javadoc.private=false +javadoc.splitindex=true +javadoc.use=true +javadoc.version=false +javadoc.windowtitle= +main.class=mch_09_server_2.Main +manifest.file=manifest.mf +meta.inf.dir=${src.dir}/META-INF +mkdist.disabled=false +platform.active=default_platform +run.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +# Space-separated list of JVM arguments used when running the project +# (you may also define separate properties like run-sys-prop.name=value instead of -Dname=value +# or test-sys-prop.name=value to set system properties for unit tests): +run.jvmargs= +run.test.classpath=\ + ${javac.test.classpath}:\ + ${build.test.classes.dir} +source.encoding=UTF-8 +src.dir=src +test.src.dir=test diff --git a/Pro Java 7 NIO.2/Chapter09/async/mch_09_server_2/nbproject/project.xml b/Pro Java 7 NIO.2/Chapter09/async/mch_09_server_2/nbproject/project.xml new file mode 100644 index 0000000..1a9f2b7 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter09/async/mch_09_server_2/nbproject/project.xml @@ -0,0 +1,15 @@ + + + org.netbeans.modules.java.j2seproject + + + mch_09_server_2 + + + + + + + + + diff --git a/Pro Java 7 NIO.2/Chapter09/async/mch_09_server_2/src/mch_09_server_2/Main.java b/Pro Java 7 NIO.2/Chapter09/async/mch_09_server_2/src/mch_09_server_2/Main.java new file mode 100644 index 0000000..61c2a21 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter09/async/mch_09_server_2/src/mch_09_server_2/Main.java @@ -0,0 +1,103 @@ +package mch_09_server_2; + +import java.io.IOException; +import java.net.InetSocketAddress; +import java.net.StandardSocketOptions; +import java.nio.ByteBuffer; +import java.nio.channels.AsynchronousServerSocketChannel; +import java.nio.channels.AsynchronousSocketChannel; +import java.util.concurrent.Callable; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.Future; + +/** + * + * @author Apress + */ +public class Main { + + public static void main(String[] args) { + + final int DEFAULT_PORT = 5555; + final String IP = "127.0.0.1"; + ExecutorService taskExecutor = Executors.newCachedThreadPool(Executors.defaultThreadFactory()); + + //create asynchronous server-socket channel bound to the default group + try (AsynchronousServerSocketChannel asynchronousServerSocketChannel = AsynchronousServerSocketChannel.open()) { + + if (asynchronousServerSocketChannel.isOpen()) { + + //set some options + asynchronousServerSocketChannel.setOption(StandardSocketOptions.SO_RCVBUF, 4 * 1024); + asynchronousServerSocketChannel.setOption(StandardSocketOptions.SO_REUSEADDR, true); + //bind the server-socket channel to local address + asynchronousServerSocketChannel.bind(new InetSocketAddress(IP, DEFAULT_PORT)); + + //display a waiting message while ... waiting clients + System.out.println("Waiting for connections ..."); + + while (true) { + Future asynchronousSocketChannelFuture = asynchronousServerSocketChannel.accept(); + + try { + final AsynchronousSocketChannel asynchronousSocketChannel = asynchronousSocketChannelFuture.get(); + Callable worker = new Callable() { + + @Override + public String call() throws Exception { + + String host = asynchronousSocketChannel.getRemoteAddress().toString(); + System.out.println("Incoming connection from: " + host); + + final ByteBuffer buffer = ByteBuffer.allocateDirect(1024); + + //transmitting data + while (asynchronousSocketChannel.read(buffer).get() != -1) { + + buffer.flip(); + + asynchronousSocketChannel.write(buffer).get(); + + if (buffer.hasRemaining()) { + buffer.compact(); + } else { + buffer.clear(); + } + } + + asynchronousSocketChannel.close(); + System.out.println(host + " was successfully served!"); + return host; + } + }; + + taskExecutor.submit(worker); + + } catch (InterruptedException | ExecutionException ex) { + System.err.println(ex); + + System.err.println("\n Server is shutting down ..."); + + //this will make the executor accept no new threads + // and finish all existing threads in the queue + taskExecutor.shutdown(); + + //wait until all threads are finish + while (!taskExecutor.isTerminated()) { + } + + break; + } + } + } else { + System.out.println("The asynchronous server-socket channel cannot be opened!"); + } + + } catch (IOException ex) { + System.err.println(ex); + } + + } +} diff --git a/Pro Java 7 NIO.2/Chapter09/async/mch_10_client/build.xml b/Pro Java 7 NIO.2/Chapter09/async/mch_10_client/build.xml new file mode 100644 index 0000000..c71def8 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter09/async/mch_10_client/build.xml @@ -0,0 +1,74 @@ + + + + + + + + + + + Builds, tests, and runs the project mch_10_client. + + + diff --git a/Pro Java 7 NIO.2/Chapter09/async/mch_10_client/build/built-jar.properties b/Pro Java 7 NIO.2/Chapter09/async/mch_10_client/build/built-jar.properties new file mode 100644 index 0000000..36a67ee --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter09/async/mch_10_client/build/built-jar.properties @@ -0,0 +1,4 @@ +#Thu, 03 Nov 2011 07:22:55 +0200 + + +C\:\\NIO\\async\\mch_10_client= diff --git a/Pro Java 7 NIO.2/Chapter09/async/mch_10_client/build/classes/.netbeans_automatic_build b/Pro Java 7 NIO.2/Chapter09/async/mch_10_client/build/classes/.netbeans_automatic_build new file mode 100644 index 0000000..e69de29 diff --git a/Pro Java 7 NIO.2/Chapter09/async/mch_10_client/build/classes/mch_10_client/Main$1.class b/Pro Java 7 NIO.2/Chapter09/async/mch_10_client/build/classes/mch_10_client/Main$1.class new file mode 100644 index 0000000..1bbdf23 Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter09/async/mch_10_client/build/classes/mch_10_client/Main$1.class differ diff --git a/Pro Java 7 NIO.2/Chapter09/async/mch_10_client/build/classes/mch_10_client/Main.class b/Pro Java 7 NIO.2/Chapter09/async/mch_10_client/build/classes/mch_10_client/Main.class new file mode 100644 index 0000000..536dd34 Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter09/async/mch_10_client/build/classes/mch_10_client/Main.class differ diff --git a/Pro Java 7 NIO.2/Chapter09/async/mch_10_client/dist/README.TXT b/Pro Java 7 NIO.2/Chapter09/async/mch_10_client/dist/README.TXT new file mode 100644 index 0000000..2141ece --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter09/async/mch_10_client/dist/README.TXT @@ -0,0 +1,32 @@ +======================== +BUILD OUTPUT DESCRIPTION +======================== + +When you build an Java application project that has a main class, the IDE +automatically copies all of the JAR +files on the projects classpath to your projects dist/lib folder. The IDE +also adds each of the JAR files to the Class-Path element in the application +JAR files manifest file (MANIFEST.MF). + +To run the project from the command line, go to the dist folder and +type the following: + +java -jar "mch_10_client.jar" + +To distribute this project, zip up the dist folder (including the lib folder) +and distribute the ZIP file. + +Notes: + +* If two JAR files on the project classpath have the same name, only the first +JAR file is copied to the lib folder. +* Only JAR files are copied to the lib folder. +If the classpath contains other types of files or folders, these files (folders) +are not copied. +* If a library on the projects classpath also has a Class-Path element +specified in the manifest,the content of the Class-Path element has to be on +the projects runtime path. +* To set a main class in a standard Java project, right-click the project node +in the Projects window and choose Properties. Then click Run and enter the +class name in the Main Class field. Alternatively, you can manually type the +class name in the manifest Main-Class element. diff --git a/Pro Java 7 NIO.2/Chapter09/async/mch_10_client/dist/mch_10_client.jar b/Pro Java 7 NIO.2/Chapter09/async/mch_10_client/dist/mch_10_client.jar new file mode 100644 index 0000000..ac59fcd Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter09/async/mch_10_client/dist/mch_10_client.jar differ diff --git a/Pro Java 7 NIO.2/Chapter09/async/mch_10_client/manifest.mf b/Pro Java 7 NIO.2/Chapter09/async/mch_10_client/manifest.mf new file mode 100644 index 0000000..328e8e5 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter09/async/mch_10_client/manifest.mf @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +X-COMMENT: Main-Class will be added automatically by build + diff --git a/Pro Java 7 NIO.2/Chapter09/async/mch_10_client/nbproject/build-impl.xml b/Pro Java 7 NIO.2/Chapter09/async/mch_10_client/nbproject/build-impl.xml new file mode 100644 index 0000000..a5ce280 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter09/async/mch_10_client/nbproject/build-impl.xml @@ -0,0 +1,1041 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set src.dir + Must set test.src.dir + Must set build.dir + Must set dist.dir + Must set build.classes.dir + Must set dist.javadoc.dir + Must set build.test.classes.dir + Must set build.test.results.dir + Must set build.classes.excludes + Must set dist.jar + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set JVM to use for profiling in profiler.info.jvm + Must set profiler agent JVM arguments in profiler.info.jvmargs.agent + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + + + + + + java -cp "${run.classpath.with.dist.jar}" ${main.class} + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + java -jar "${dist.jar.resolved}" + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set run.class + + + + Must select one file in the IDE or set run.class + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set debug.class + + + + + Must select one file in the IDE or set debug.class + + + + + Must set fix.includes + + + + + + + + + + + + + + + + + Must select one file in the IDE or set profile.class + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + Some tests failed; see details above. + + + + + + + + + Must select some files in the IDE or set test.includes + + + + Some tests failed; see details above. + + + + + Must select one file in the IDE or set test.class + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Pro Java 7 NIO.2/Chapter09/async/mch_10_client/nbproject/genfiles.properties b/Pro Java 7 NIO.2/Chapter09/async/mch_10_client/nbproject/genfiles.properties new file mode 100644 index 0000000..250d443 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter09/async/mch_10_client/nbproject/genfiles.properties @@ -0,0 +1,8 @@ +build.xml.data.CRC32=f5a24f4e +build.xml.script.CRC32=2abb5e80 +build.xml.stylesheet.CRC32=28e38971@1.43.1.45 +# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. +# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. +nbproject/build-impl.xml.data.CRC32=f5a24f4e +nbproject/build-impl.xml.script.CRC32=9f992a21 +nbproject/build-impl.xml.stylesheet.CRC32=0c01fd8e@1.43.1.45 diff --git a/Pro Java 7 NIO.2/Chapter09/async/mch_10_client/nbproject/private/config.properties b/Pro Java 7 NIO.2/Chapter09/async/mch_10_client/nbproject/private/config.properties new file mode 100644 index 0000000..e69de29 diff --git a/Pro Java 7 NIO.2/Chapter09/async/mch_10_client/nbproject/private/private.properties b/Pro Java 7 NIO.2/Chapter09/async/mch_10_client/nbproject/private/private.properties new file mode 100644 index 0000000..a5ab360 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter09/async/mch_10_client/nbproject/private/private.properties @@ -0,0 +1,6 @@ +compile.on.save=true +do.depend=false +do.jar=true +javac.debug=true +javadoc.preview=true +user.properties.file=C:\\Users\\Leo\\.netbeans\\7.0\\build.properties diff --git a/Pro Java 7 NIO.2/Chapter09/async/mch_10_client/nbproject/private/private.xml b/Pro Java 7 NIO.2/Chapter09/async/mch_10_client/nbproject/private/private.xml new file mode 100644 index 0000000..c1f155a --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter09/async/mch_10_client/nbproject/private/private.xml @@ -0,0 +1,4 @@ + + + + diff --git a/Pro Java 7 NIO.2/Chapter09/async/mch_10_client/nbproject/project.properties b/Pro Java 7 NIO.2/Chapter09/async/mch_10_client/nbproject/project.properties new file mode 100644 index 0000000..41f8dfe --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter09/async/mch_10_client/nbproject/project.properties @@ -0,0 +1,72 @@ +annotation.processing.enabled=true +annotation.processing.enabled.in.editor=false +annotation.processing.run.all.processors=true +annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output +application.title=mch_10_client +application.vendor=Leo +build.classes.dir=${build.dir}/classes +build.classes.excludes=**/*.java,**/*.form +# This directory is removed when the project is cleaned: +build.dir=build +build.generated.dir=${build.dir}/generated +build.generated.sources.dir=${build.dir}/generated-sources +# Only compile against the classpath explicitly listed here: +build.sysclasspath=ignore +build.test.classes.dir=${build.dir}/test/classes +build.test.results.dir=${build.dir}/test/results +# Uncomment to specify the preferred debugger connection transport: +#debug.transport=dt_socket +debug.classpath=\ + ${run.classpath} +debug.test.classpath=\ + ${run.test.classpath} +# This directory is removed when the project is cleaned: +dist.dir=dist +dist.jar=${dist.dir}/mch_10_client.jar +dist.javadoc.dir=${dist.dir}/javadoc +endorsed.classpath= +excludes= +includes=** +jar.compress=false +javac.classpath= +# Space-separated list of extra javac options +javac.compilerargs= +javac.deprecation=false +javac.processorpath=\ + ${javac.classpath} +javac.source=1.7 +javac.target=1.7 +javac.test.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +javac.test.processorpath=\ + ${javac.test.classpath} +javadoc.additionalparam= +javadoc.author=false +javadoc.encoding=${source.encoding} +javadoc.noindex=false +javadoc.nonavbar=false +javadoc.notree=false +javadoc.private=false +javadoc.splitindex=true +javadoc.use=true +javadoc.version=false +javadoc.windowtitle= +main.class=mch_10_client.Main +manifest.file=manifest.mf +meta.inf.dir=${src.dir}/META-INF +mkdist.disabled=false +platform.active=default_platform +run.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +# Space-separated list of JVM arguments used when running the project +# (you may also define separate properties like run-sys-prop.name=value instead of -Dname=value +# or test-sys-prop.name=value to set system properties for unit tests): +run.jvmargs= +run.test.classpath=\ + ${javac.test.classpath}:\ + ${build.test.classes.dir} +source.encoding=UTF-8 +src.dir=src +test.src.dir=test diff --git a/Pro Java 7 NIO.2/Chapter09/async/mch_10_client/nbproject/project.xml b/Pro Java 7 NIO.2/Chapter09/async/mch_10_client/nbproject/project.xml new file mode 100644 index 0000000..c585658 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter09/async/mch_10_client/nbproject/project.xml @@ -0,0 +1,15 @@ + + + org.netbeans.modules.java.j2seproject + + + mch_10_client + + + + + + + + + diff --git a/Pro Java 7 NIO.2/Chapter09/async/mch_10_client/src/mch_10_client/Main.java b/Pro Java 7 NIO.2/Chapter09/async/mch_10_client/src/mch_10_client/Main.java new file mode 100644 index 0000000..92218bd --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter09/async/mch_10_client/src/mch_10_client/Main.java @@ -0,0 +1,103 @@ +package mch_10_client; + +import java.io.IOException; +import java.net.InetSocketAddress; +import java.net.StandardSocketOptions; +import java.nio.ByteBuffer; +import java.nio.CharBuffer; +import java.nio.channels.AsynchronousSocketChannel; +import java.nio.channels.CompletionHandler; +import java.nio.charset.Charset; +import java.nio.charset.CharsetDecoder; +import java.util.Random; +import java.util.concurrent.ExecutionException; + +/** + * + * @author Apress + */ +public class Main { + + public static void main(String[] args) { + + final int DEFAULT_PORT = 5555; + final String IP = "127.0.0.1"; + + //create asynchronous socket channel bound to the default group + try (AsynchronousSocketChannel asynchronousSocketChannel = AsynchronousSocketChannel.open()) { + + if (asynchronousSocketChannel.isOpen()) { + + //set some options + asynchronousSocketChannel.setOption(StandardSocketOptions.SO_RCVBUF, 128 * 1024); + asynchronousSocketChannel.setOption(StandardSocketOptions.SO_SNDBUF, 128 * 1024); + asynchronousSocketChannel.setOption(StandardSocketOptions.SO_KEEPALIVE, true); + + //connect this channel's socket + asynchronousSocketChannel.connect(new InetSocketAddress(IP, DEFAULT_PORT), null, new CompletionHandler() { + + final ByteBuffer helloBuffer = ByteBuffer.wrap("Hello !".getBytes()); + final ByteBuffer buffer = ByteBuffer.allocateDirect(1024); + CharBuffer charBuffer = null; + ByteBuffer randomBuffer; + final Charset charset = Charset.defaultCharset(); + final CharsetDecoder decoder = charset.newDecoder(); + + @Override + public void completed(Void result, Void attachment) { + try { + System.out.println("Successfully connected at: " + asynchronousSocketChannel.getRemoteAddress()); + + //transmitting data + asynchronousSocketChannel.write(helloBuffer).get(); + + while (asynchronousSocketChannel.read(buffer).get() != -1) { + + buffer.flip(); + + charBuffer = decoder.decode(buffer); + System.out.println(charBuffer.toString()); + + if (buffer.hasRemaining()) { + buffer.compact(); + } else { + buffer.clear(); + } + + int r = new Random().nextInt(100); + if (r == 50) { + System.out.println("50 was generated! Close the asynchronous socket channel!"); + break; + } else { + randomBuffer = ByteBuffer.wrap("Random number:".concat(String.valueOf(r)).getBytes()); + asynchronousSocketChannel.write(randomBuffer).get(); + } + } + } catch (IOException | InterruptedException | ExecutionException ex) { + System.err.println(ex); + } finally { + try { + asynchronousSocketChannel.close(); + } catch (IOException ex) { + System.err.println(ex); + } + } + } + + @Override + public void failed(Throwable exc, Void attachment) { + throw new UnsupportedOperationException("Connection cannot be established!"); + } + }); + + System.in.read(); + + } else { + System.out.println("The asynchronous socket channel cannot be opened!"); + } + + } catch (IOException ex) { + System.err.println(ex); + } + } +} diff --git a/Pro Java 7 NIO.2/Chapter09/async/mch_10_server/build.xml b/Pro Java 7 NIO.2/Chapter09/async/mch_10_server/build.xml new file mode 100644 index 0000000..ad599ff --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter09/async/mch_10_server/build.xml @@ -0,0 +1,74 @@ + + + + + + + + + + + Builds, tests, and runs the project mch_10_server. + + + diff --git a/Pro Java 7 NIO.2/Chapter09/async/mch_10_server/build/built-jar.properties b/Pro Java 7 NIO.2/Chapter09/async/mch_10_server/build/built-jar.properties new file mode 100644 index 0000000..c53700f --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter09/async/mch_10_server/build/built-jar.properties @@ -0,0 +1,4 @@ +#Thu, 03 Nov 2011 07:22:46 +0200 + + +C\:\\NIO\\async\\mch_10_server= diff --git a/Pro Java 7 NIO.2/Chapter09/async/mch_10_server/build/classes/.netbeans_automatic_build b/Pro Java 7 NIO.2/Chapter09/async/mch_10_server/build/classes/.netbeans_automatic_build new file mode 100644 index 0000000..e69de29 diff --git a/Pro Java 7 NIO.2/Chapter09/async/mch_10_server/build/classes/mch_10_server/Main$1.class b/Pro Java 7 NIO.2/Chapter09/async/mch_10_server/build/classes/mch_10_server/Main$1.class new file mode 100644 index 0000000..a75c2b9 Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter09/async/mch_10_server/build/classes/mch_10_server/Main$1.class differ diff --git a/Pro Java 7 NIO.2/Chapter09/async/mch_10_server/build/classes/mch_10_server/Main.class b/Pro Java 7 NIO.2/Chapter09/async/mch_10_server/build/classes/mch_10_server/Main.class new file mode 100644 index 0000000..1f2a9ec Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter09/async/mch_10_server/build/classes/mch_10_server/Main.class differ diff --git a/Pro Java 7 NIO.2/Chapter09/async/mch_10_server/dist/README.TXT b/Pro Java 7 NIO.2/Chapter09/async/mch_10_server/dist/README.TXT new file mode 100644 index 0000000..d7127c5 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter09/async/mch_10_server/dist/README.TXT @@ -0,0 +1,32 @@ +======================== +BUILD OUTPUT DESCRIPTION +======================== + +When you build an Java application project that has a main class, the IDE +automatically copies all of the JAR +files on the projects classpath to your projects dist/lib folder. The IDE +also adds each of the JAR files to the Class-Path element in the application +JAR files manifest file (MANIFEST.MF). + +To run the project from the command line, go to the dist folder and +type the following: + +java -jar "mch_10_server.jar" + +To distribute this project, zip up the dist folder (including the lib folder) +and distribute the ZIP file. + +Notes: + +* If two JAR files on the project classpath have the same name, only the first +JAR file is copied to the lib folder. +* Only JAR files are copied to the lib folder. +If the classpath contains other types of files or folders, these files (folders) +are not copied. +* If a library on the projects classpath also has a Class-Path element +specified in the manifest,the content of the Class-Path element has to be on +the projects runtime path. +* To set a main class in a standard Java project, right-click the project node +in the Projects window and choose Properties. Then click Run and enter the +class name in the Main Class field. Alternatively, you can manually type the +class name in the manifest Main-Class element. diff --git a/Pro Java 7 NIO.2/Chapter09/async/mch_10_server/dist/mch_10_server.jar b/Pro Java 7 NIO.2/Chapter09/async/mch_10_server/dist/mch_10_server.jar new file mode 100644 index 0000000..c8194bf Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter09/async/mch_10_server/dist/mch_10_server.jar differ diff --git a/Pro Java 7 NIO.2/Chapter09/async/mch_10_server/manifest.mf b/Pro Java 7 NIO.2/Chapter09/async/mch_10_server/manifest.mf new file mode 100644 index 0000000..328e8e5 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter09/async/mch_10_server/manifest.mf @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +X-COMMENT: Main-Class will be added automatically by build + diff --git a/Pro Java 7 NIO.2/Chapter09/async/mch_10_server/nbproject/build-impl.xml b/Pro Java 7 NIO.2/Chapter09/async/mch_10_server/nbproject/build-impl.xml new file mode 100644 index 0000000..1ec1e7c --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter09/async/mch_10_server/nbproject/build-impl.xml @@ -0,0 +1,1041 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set src.dir + Must set test.src.dir + Must set build.dir + Must set dist.dir + Must set build.classes.dir + Must set dist.javadoc.dir + Must set build.test.classes.dir + Must set build.test.results.dir + Must set build.classes.excludes + Must set dist.jar + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set JVM to use for profiling in profiler.info.jvm + Must set profiler agent JVM arguments in profiler.info.jvmargs.agent + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + + + + + + java -cp "${run.classpath.with.dist.jar}" ${main.class} + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + java -jar "${dist.jar.resolved}" + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set run.class + + + + Must select one file in the IDE or set run.class + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set debug.class + + + + + Must select one file in the IDE or set debug.class + + + + + Must set fix.includes + + + + + + + + + + + + + + + + + Must select one file in the IDE or set profile.class + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + Some tests failed; see details above. + + + + + + + + + Must select some files in the IDE or set test.includes + + + + Some tests failed; see details above. + + + + + Must select one file in the IDE or set test.class + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Pro Java 7 NIO.2/Chapter09/async/mch_10_server/nbproject/genfiles.properties b/Pro Java 7 NIO.2/Chapter09/async/mch_10_server/nbproject/genfiles.properties new file mode 100644 index 0000000..29b7a21 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter09/async/mch_10_server/nbproject/genfiles.properties @@ -0,0 +1,8 @@ +build.xml.data.CRC32=22fceb59 +build.xml.script.CRC32=75c023b9 +build.xml.stylesheet.CRC32=28e38971@1.43.1.45 +# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. +# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. +nbproject/build-impl.xml.data.CRC32=22fceb59 +nbproject/build-impl.xml.script.CRC32=574ecb22 +nbproject/build-impl.xml.stylesheet.CRC32=0c01fd8e@1.43.1.45 diff --git a/Pro Java 7 NIO.2/Chapter09/async/mch_10_server/nbproject/private/config.properties b/Pro Java 7 NIO.2/Chapter09/async/mch_10_server/nbproject/private/config.properties new file mode 100644 index 0000000..e69de29 diff --git a/Pro Java 7 NIO.2/Chapter09/async/mch_10_server/nbproject/private/private.properties b/Pro Java 7 NIO.2/Chapter09/async/mch_10_server/nbproject/private/private.properties new file mode 100644 index 0000000..a5ab360 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter09/async/mch_10_server/nbproject/private/private.properties @@ -0,0 +1,6 @@ +compile.on.save=true +do.depend=false +do.jar=true +javac.debug=true +javadoc.preview=true +user.properties.file=C:\\Users\\Leo\\.netbeans\\7.0\\build.properties diff --git a/Pro Java 7 NIO.2/Chapter09/async/mch_10_server/nbproject/private/private.xml b/Pro Java 7 NIO.2/Chapter09/async/mch_10_server/nbproject/private/private.xml new file mode 100644 index 0000000..c1f155a --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter09/async/mch_10_server/nbproject/private/private.xml @@ -0,0 +1,4 @@ + + + + diff --git a/Pro Java 7 NIO.2/Chapter09/async/mch_10_server/nbproject/project.properties b/Pro Java 7 NIO.2/Chapter09/async/mch_10_server/nbproject/project.properties new file mode 100644 index 0000000..c1e5197 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter09/async/mch_10_server/nbproject/project.properties @@ -0,0 +1,72 @@ +annotation.processing.enabled=true +annotation.processing.enabled.in.editor=false +annotation.processing.run.all.processors=true +annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output +application.title=mch_10_server +application.vendor=Leo +build.classes.dir=${build.dir}/classes +build.classes.excludes=**/*.java,**/*.form +# This directory is removed when the project is cleaned: +build.dir=build +build.generated.dir=${build.dir}/generated +build.generated.sources.dir=${build.dir}/generated-sources +# Only compile against the classpath explicitly listed here: +build.sysclasspath=ignore +build.test.classes.dir=${build.dir}/test/classes +build.test.results.dir=${build.dir}/test/results +# Uncomment to specify the preferred debugger connection transport: +#debug.transport=dt_socket +debug.classpath=\ + ${run.classpath} +debug.test.classpath=\ + ${run.test.classpath} +# This directory is removed when the project is cleaned: +dist.dir=dist +dist.jar=${dist.dir}/mch_10_server.jar +dist.javadoc.dir=${dist.dir}/javadoc +endorsed.classpath= +excludes= +includes=** +jar.compress=false +javac.classpath= +# Space-separated list of extra javac options +javac.compilerargs= +javac.deprecation=false +javac.processorpath=\ + ${javac.classpath} +javac.source=1.7 +javac.target=1.7 +javac.test.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +javac.test.processorpath=\ + ${javac.test.classpath} +javadoc.additionalparam= +javadoc.author=false +javadoc.encoding=${source.encoding} +javadoc.noindex=false +javadoc.nonavbar=false +javadoc.notree=false +javadoc.private=false +javadoc.splitindex=true +javadoc.use=true +javadoc.version=false +javadoc.windowtitle= +main.class=mch_10_server.Main +manifest.file=manifest.mf +meta.inf.dir=${src.dir}/META-INF +mkdist.disabled=false +platform.active=default_platform +run.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +# Space-separated list of JVM arguments used when running the project +# (you may also define separate properties like run-sys-prop.name=value instead of -Dname=value +# or test-sys-prop.name=value to set system properties for unit tests): +run.jvmargs= +run.test.classpath=\ + ${javac.test.classpath}:\ + ${build.test.classes.dir} +source.encoding=UTF-8 +src.dir=src +test.src.dir=test diff --git a/Pro Java 7 NIO.2/Chapter09/async/mch_10_server/nbproject/project.xml b/Pro Java 7 NIO.2/Chapter09/async/mch_10_server/nbproject/project.xml new file mode 100644 index 0000000..dd7f6d6 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter09/async/mch_10_server/nbproject/project.xml @@ -0,0 +1,15 @@ + + + org.netbeans.modules.java.j2seproject + + + mch_10_server + + + + + + + + + diff --git a/Pro Java 7 NIO.2/Chapter09/async/mch_10_server/src/mch_10_server/Main.java b/Pro Java 7 NIO.2/Chapter09/async/mch_10_server/src/mch_10_server/Main.java new file mode 100644 index 0000000..0d4657e --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter09/async/mch_10_server/src/mch_10_server/Main.java @@ -0,0 +1,91 @@ +package mch_10_server; + +import java.io.IOException; +import java.net.InetSocketAddress; +import java.net.StandardSocketOptions; +import java.nio.ByteBuffer; +import java.nio.channels.AsynchronousServerSocketChannel; +import java.nio.channels.AsynchronousSocketChannel; +import java.nio.channels.CompletionHandler; +import java.util.concurrent.ExecutionException; + +/** + * + * @author Apress + */ +public class Main { + + public static void main(String[] args) { + + final int DEFAULT_PORT = 5555; + final String IP = "127.0.0.1"; + + //create asynchronous server-socket channel bound to the default group + try (AsynchronousServerSocketChannel asynchronousServerSocketChannel = AsynchronousServerSocketChannel.open()) { + + if (asynchronousServerSocketChannel.isOpen()) { + + //set some options + asynchronousServerSocketChannel.setOption(StandardSocketOptions.SO_RCVBUF, 4 * 1024); + asynchronousServerSocketChannel.setOption(StandardSocketOptions.SO_REUSEADDR, true); + //bind the server-socket channel to local address + asynchronousServerSocketChannel.bind(new InetSocketAddress(IP, DEFAULT_PORT)); + + //display a waiting message while ... waiting clients + System.out.println("Waiting for connections ..."); + + asynchronousServerSocketChannel.accept(null, new CompletionHandler() { + + final ByteBuffer buffer = ByteBuffer.allocateDirect(1024); + + @Override + public void completed(AsynchronousSocketChannel result, Void attachment) { + + asynchronousServerSocketChannel.accept(null, this); + + try { + System.out.println("Incoming connection from: " + result.getRemoteAddress()); + + //transmitting data + while (result.read(buffer).get() != -1) { + + buffer.flip(); + + result.write(buffer).get(); + + if (buffer.hasRemaining()) { + buffer.compact(); + } else { + buffer.clear(); + } + } + } catch (IOException | InterruptedException | ExecutionException ex) { + System.err.println(ex); + } finally { + try { + result.close(); + } catch (IOException e) { + System.err.println(e); + } + } + } + + @Override + public void failed(Throwable exc, Void attachment) { + asynchronousServerSocketChannel.accept(null, this); + throw new UnsupportedOperationException("Cannot accept cponnections!"); + } + }); + + // Wait + System.in.read(); + + } else { + System.out.println("The asynchronous server-socket channel cannot be opened!"); + } + + } catch (IOException ex) { + System.err.println(ex); + } + } +} diff --git a/Pro Java 7 NIO.2/Chapter09/async/mch_11_server/build.xml b/Pro Java 7 NIO.2/Chapter09/async/mch_11_server/build.xml new file mode 100644 index 0000000..7c6365d --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter09/async/mch_11_server/build.xml @@ -0,0 +1,74 @@ + + + + + + + + + + + Builds, tests, and runs the project mch_11_server. + + + diff --git a/Pro Java 7 NIO.2/Chapter09/async/mch_11_server/build/built-jar.properties b/Pro Java 7 NIO.2/Chapter09/async/mch_11_server/build/built-jar.properties new file mode 100644 index 0000000..57cdf69 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter09/async/mch_11_server/build/built-jar.properties @@ -0,0 +1,4 @@ +#Thu, 03 Nov 2011 07:24:06 +0200 + + +C\:\\NIO\\async\\mch_11_server= diff --git a/Pro Java 7 NIO.2/Chapter09/async/mch_11_server/build/classes/.netbeans_automatic_build b/Pro Java 7 NIO.2/Chapter09/async/mch_11_server/build/classes/.netbeans_automatic_build new file mode 100644 index 0000000..e69de29 diff --git a/Pro Java 7 NIO.2/Chapter09/async/mch_11_server/build/classes/mch_11_server/Main$1.class b/Pro Java 7 NIO.2/Chapter09/async/mch_11_server/build/classes/mch_11_server/Main$1.class new file mode 100644 index 0000000..430125b Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter09/async/mch_11_server/build/classes/mch_11_server/Main$1.class differ diff --git a/Pro Java 7 NIO.2/Chapter09/async/mch_11_server/build/classes/mch_11_server/Main.class b/Pro Java 7 NIO.2/Chapter09/async/mch_11_server/build/classes/mch_11_server/Main.class new file mode 100644 index 0000000..8b3c773 Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter09/async/mch_11_server/build/classes/mch_11_server/Main.class differ diff --git a/Pro Java 7 NIO.2/Chapter09/async/mch_11_server/dist/README.TXT b/Pro Java 7 NIO.2/Chapter09/async/mch_11_server/dist/README.TXT new file mode 100644 index 0000000..631a9c3 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter09/async/mch_11_server/dist/README.TXT @@ -0,0 +1,32 @@ +======================== +BUILD OUTPUT DESCRIPTION +======================== + +When you build an Java application project that has a main class, the IDE +automatically copies all of the JAR +files on the projects classpath to your projects dist/lib folder. The IDE +also adds each of the JAR files to the Class-Path element in the application +JAR files manifest file (MANIFEST.MF). + +To run the project from the command line, go to the dist folder and +type the following: + +java -jar "mch_11_server.jar" + +To distribute this project, zip up the dist folder (including the lib folder) +and distribute the ZIP file. + +Notes: + +* If two JAR files on the project classpath have the same name, only the first +JAR file is copied to the lib folder. +* Only JAR files are copied to the lib folder. +If the classpath contains other types of files or folders, these files (folders) +are not copied. +* If a library on the projects classpath also has a Class-Path element +specified in the manifest,the content of the Class-Path element has to be on +the projects runtime path. +* To set a main class in a standard Java project, right-click the project node +in the Projects window and choose Properties. Then click Run and enter the +class name in the Main Class field. Alternatively, you can manually type the +class name in the manifest Main-Class element. diff --git a/Pro Java 7 NIO.2/Chapter09/async/mch_11_server/dist/mch_11_server.jar b/Pro Java 7 NIO.2/Chapter09/async/mch_11_server/dist/mch_11_server.jar new file mode 100644 index 0000000..f486806 Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter09/async/mch_11_server/dist/mch_11_server.jar differ diff --git a/Pro Java 7 NIO.2/Chapter09/async/mch_11_server/manifest.mf b/Pro Java 7 NIO.2/Chapter09/async/mch_11_server/manifest.mf new file mode 100644 index 0000000..328e8e5 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter09/async/mch_11_server/manifest.mf @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +X-COMMENT: Main-Class will be added automatically by build + diff --git a/Pro Java 7 NIO.2/Chapter09/async/mch_11_server/nbproject/build-impl.xml b/Pro Java 7 NIO.2/Chapter09/async/mch_11_server/nbproject/build-impl.xml new file mode 100644 index 0000000..6666071 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter09/async/mch_11_server/nbproject/build-impl.xml @@ -0,0 +1,1041 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set src.dir + Must set test.src.dir + Must set build.dir + Must set dist.dir + Must set build.classes.dir + Must set dist.javadoc.dir + Must set build.test.classes.dir + Must set build.test.results.dir + Must set build.classes.excludes + Must set dist.jar + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set JVM to use for profiling in profiler.info.jvm + Must set profiler agent JVM arguments in profiler.info.jvmargs.agent + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + + + + + + java -cp "${run.classpath.with.dist.jar}" ${main.class} + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + java -jar "${dist.jar.resolved}" + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set run.class + + + + Must select one file in the IDE or set run.class + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set debug.class + + + + + Must select one file in the IDE or set debug.class + + + + + Must set fix.includes + + + + + + + + + + + + + + + + + Must select one file in the IDE or set profile.class + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + Some tests failed; see details above. + + + + + + + + + Must select some files in the IDE or set test.includes + + + + Some tests failed; see details above. + + + + + Must select one file in the IDE or set test.class + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Pro Java 7 NIO.2/Chapter09/async/mch_11_server/nbproject/genfiles.properties b/Pro Java 7 NIO.2/Chapter09/async/mch_11_server/nbproject/genfiles.properties new file mode 100644 index 0000000..dcafe73 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter09/async/mch_11_server/nbproject/genfiles.properties @@ -0,0 +1,8 @@ +build.xml.data.CRC32=0517f6e1 +build.xml.script.CRC32=4d8c9664 +build.xml.stylesheet.CRC32=28e38971@1.43.1.45 +# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. +# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. +nbproject/build-impl.xml.data.CRC32=0517f6e1 +nbproject/build-impl.xml.script.CRC32=a03f741a +nbproject/build-impl.xml.stylesheet.CRC32=0c01fd8e@1.43.1.45 diff --git a/Pro Java 7 NIO.2/Chapter09/async/mch_11_server/nbproject/private/config.properties b/Pro Java 7 NIO.2/Chapter09/async/mch_11_server/nbproject/private/config.properties new file mode 100644 index 0000000..e69de29 diff --git a/Pro Java 7 NIO.2/Chapter09/async/mch_11_server/nbproject/private/private.properties b/Pro Java 7 NIO.2/Chapter09/async/mch_11_server/nbproject/private/private.properties new file mode 100644 index 0000000..a5ab360 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter09/async/mch_11_server/nbproject/private/private.properties @@ -0,0 +1,6 @@ +compile.on.save=true +do.depend=false +do.jar=true +javac.debug=true +javadoc.preview=true +user.properties.file=C:\\Users\\Leo\\.netbeans\\7.0\\build.properties diff --git a/Pro Java 7 NIO.2/Chapter09/async/mch_11_server/nbproject/private/private.xml b/Pro Java 7 NIO.2/Chapter09/async/mch_11_server/nbproject/private/private.xml new file mode 100644 index 0000000..c1f155a --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter09/async/mch_11_server/nbproject/private/private.xml @@ -0,0 +1,4 @@ + + + + diff --git a/Pro Java 7 NIO.2/Chapter09/async/mch_11_server/nbproject/project.properties b/Pro Java 7 NIO.2/Chapter09/async/mch_11_server/nbproject/project.properties new file mode 100644 index 0000000..33acd82 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter09/async/mch_11_server/nbproject/project.properties @@ -0,0 +1,72 @@ +annotation.processing.enabled=true +annotation.processing.enabled.in.editor=false +annotation.processing.run.all.processors=true +annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output +application.title=mch_11_server +application.vendor=Leo +build.classes.dir=${build.dir}/classes +build.classes.excludes=**/*.java,**/*.form +# This directory is removed when the project is cleaned: +build.dir=build +build.generated.dir=${build.dir}/generated +build.generated.sources.dir=${build.dir}/generated-sources +# Only compile against the classpath explicitly listed here: +build.sysclasspath=ignore +build.test.classes.dir=${build.dir}/test/classes +build.test.results.dir=${build.dir}/test/results +# Uncomment to specify the preferred debugger connection transport: +#debug.transport=dt_socket +debug.classpath=\ + ${run.classpath} +debug.test.classpath=\ + ${run.test.classpath} +# This directory is removed when the project is cleaned: +dist.dir=dist +dist.jar=${dist.dir}/mch_11_server.jar +dist.javadoc.dir=${dist.dir}/javadoc +endorsed.classpath= +excludes= +includes=** +jar.compress=false +javac.classpath= +# Space-separated list of extra javac options +javac.compilerargs= +javac.deprecation=false +javac.processorpath=\ + ${javac.classpath} +javac.source=1.7 +javac.target=1.7 +javac.test.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +javac.test.processorpath=\ + ${javac.test.classpath} +javadoc.additionalparam= +javadoc.author=false +javadoc.encoding=${source.encoding} +javadoc.noindex=false +javadoc.nonavbar=false +javadoc.notree=false +javadoc.private=false +javadoc.splitindex=true +javadoc.use=true +javadoc.version=false +javadoc.windowtitle= +main.class=mch_11_server.Main +manifest.file=manifest.mf +meta.inf.dir=${src.dir}/META-INF +mkdist.disabled=false +platform.active=default_platform +run.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +# Space-separated list of JVM arguments used when running the project +# (you may also define separate properties like run-sys-prop.name=value instead of -Dname=value +# or test-sys-prop.name=value to set system properties for unit tests): +run.jvmargs= +run.test.classpath=\ + ${javac.test.classpath}:\ + ${build.test.classes.dir} +source.encoding=UTF-8 +src.dir=src +test.src.dir=test diff --git a/Pro Java 7 NIO.2/Chapter09/async/mch_11_server/nbproject/project.xml b/Pro Java 7 NIO.2/Chapter09/async/mch_11_server/nbproject/project.xml new file mode 100644 index 0000000..873a0e2 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter09/async/mch_11_server/nbproject/project.xml @@ -0,0 +1,15 @@ + + + org.netbeans.modules.java.j2seproject + + + mch_11_server + + + + + + + + + diff --git a/Pro Java 7 NIO.2/Chapter09/async/mch_11_server/src/mch_11_server/Main.java b/Pro Java 7 NIO.2/Chapter09/async/mch_11_server/src/mch_11_server/Main.java new file mode 100644 index 0000000..4a6d714 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter09/async/mch_11_server/src/mch_11_server/Main.java @@ -0,0 +1,103 @@ +package mch_11_server; + +import java.io.IOException; +import java.net.InetSocketAddress; +import java.net.StandardSocketOptions; +import java.nio.ByteBuffer; +import java.nio.channels.AsynchronousChannelGroup; +import java.nio.channels.AsynchronousServerSocketChannel; +import java.nio.channels.AsynchronousSocketChannel; +import java.nio.channels.CompletionHandler; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; + +/** + * + * @author Apress + */ +public class Main { + + public static void main(String[] args) { + + final int DEFAULT_PORT = 5555; + final String IP = "127.0.0.1"; + AsynchronousChannelGroup threadGroup = null; + + ExecutorService executorService = Executors.newCachedThreadPool(Executors.defaultThreadFactory()); + try { + threadGroup = AsynchronousChannelGroup.withCachedThreadPool(executorService, 1); + } catch (IOException ex) { + System.err.println(ex); + } + + //create asynchronous server-socket channel bound to the default group + try (AsynchronousServerSocketChannel asynchronousServerSocketChannel = AsynchronousServerSocketChannel.open(threadGroup)) { + + if (asynchronousServerSocketChannel.isOpen()) { + + //set some options + asynchronousServerSocketChannel.setOption(StandardSocketOptions.SO_RCVBUF, 4 * 1024); + asynchronousServerSocketChannel.setOption(StandardSocketOptions.SO_REUSEADDR, true); + //bind the server-socket channel to local address + asynchronousServerSocketChannel.bind(new InetSocketAddress(IP, DEFAULT_PORT)); + + //display a waiting message while ... waiting clients + System.out.println("Waiting for connections ..."); + + asynchronousServerSocketChannel.accept(null, new CompletionHandler() { + + final ByteBuffer buffer = ByteBuffer.allocateDirect(1024); + + @Override + public void completed(AsynchronousSocketChannel result, Void attachment) { + + asynchronousServerSocketChannel.accept(null, this); + + try { + System.out.println("Incoming connection from: " + result.getRemoteAddress()); + + //transmitting data + while (result.read(buffer).get() != -1) { + + buffer.flip(); + + result.write(buffer).get(); + + if (buffer.hasRemaining()) { + buffer.compact(); + } else { + buffer.clear(); + } + } + } catch (IOException | InterruptedException | ExecutionException ex) { + System.err.println(ex); + } finally { + try { + result.close(); + } catch (IOException e) { + System.err.println(e); + } + } + } + + @Override + public void failed(Throwable exc, Void attachment) { + asynchronousServerSocketChannel.accept(null, this); + throw new UnsupportedOperationException("Cannot accept cponnections!"); + } + }); + + // Wait + System.in.read(); + + } else { + System.out.println("The asynchronous server-socket channel cannot be opened!"); + } + + } catch (IOException ex) { + System.err.println(ex); + } + + } +} diff --git a/Pro Java 7 NIO.2/Chapter10/other/oth_01/build.xml b/Pro Java 7 NIO.2/Chapter10/other/oth_01/build.xml new file mode 100644 index 0000000..dc0510f --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter10/other/oth_01/build.xml @@ -0,0 +1,74 @@ + + + + + + + + + + + Builds, tests, and runs the project oth_01. + + + diff --git a/Pro Java 7 NIO.2/Chapter10/other/oth_01/build/built-jar.properties b/Pro Java 7 NIO.2/Chapter10/other/oth_01/build/built-jar.properties new file mode 100644 index 0000000..fe1607e --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter10/other/oth_01/build/built-jar.properties @@ -0,0 +1,4 @@ +#Fri, 04 Nov 2011 07:07:10 +0200 + + +C\:\\NIO\\other\\oth_01= diff --git a/Pro Java 7 NIO.2/Chapter10/other/oth_01/build/classes/.netbeans_automatic_build b/Pro Java 7 NIO.2/Chapter10/other/oth_01/build/classes/.netbeans_automatic_build new file mode 100644 index 0000000..e69de29 diff --git a/Pro Java 7 NIO.2/Chapter10/other/oth_01/build/classes/oth_01/Main.class b/Pro Java 7 NIO.2/Chapter10/other/oth_01/build/classes/oth_01/Main.class new file mode 100644 index 0000000..48cd774 Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter10/other/oth_01/build/classes/oth_01/Main.class differ diff --git a/Pro Java 7 NIO.2/Chapter10/other/oth_01/dist/README.TXT b/Pro Java 7 NIO.2/Chapter10/other/oth_01/dist/README.TXT new file mode 100644 index 0000000..bbc6469 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter10/other/oth_01/dist/README.TXT @@ -0,0 +1,32 @@ +======================== +BUILD OUTPUT DESCRIPTION +======================== + +When you build an Java application project that has a main class, the IDE +automatically copies all of the JAR +files on the projects classpath to your projects dist/lib folder. The IDE +also adds each of the JAR files to the Class-Path element in the application +JAR files manifest file (MANIFEST.MF). + +To run the project from the command line, go to the dist folder and +type the following: + +java -jar "oth_01.jar" + +To distribute this project, zip up the dist folder (including the lib folder) +and distribute the ZIP file. + +Notes: + +* If two JAR files on the project classpath have the same name, only the first +JAR file is copied to the lib folder. +* Only JAR files are copied to the lib folder. +If the classpath contains other types of files or folders, these files (folders) +are not copied. +* If a library on the projects classpath also has a Class-Path element +specified in the manifest,the content of the Class-Path element has to be on +the projects runtime path. +* To set a main class in a standard Java project, right-click the project node +in the Projects window and choose Properties. Then click Run and enter the +class name in the Main Class field. Alternatively, you can manually type the +class name in the manifest Main-Class element. diff --git a/Pro Java 7 NIO.2/Chapter10/other/oth_01/dist/oth_01.jar b/Pro Java 7 NIO.2/Chapter10/other/oth_01/dist/oth_01.jar new file mode 100644 index 0000000..1c79f81 Binary files /dev/null and b/Pro Java 7 NIO.2/Chapter10/other/oth_01/dist/oth_01.jar differ diff --git a/Pro Java 7 NIO.2/Chapter10/other/oth_01/manifest.mf b/Pro Java 7 NIO.2/Chapter10/other/oth_01/manifest.mf new file mode 100644 index 0000000..328e8e5 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter10/other/oth_01/manifest.mf @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +X-COMMENT: Main-Class will be added automatically by build + diff --git a/Pro Java 7 NIO.2/Chapter10/other/oth_01/nbproject/build-impl.xml b/Pro Java 7 NIO.2/Chapter10/other/oth_01/nbproject/build-impl.xml new file mode 100644 index 0000000..2c93df7 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter10/other/oth_01/nbproject/build-impl.xml @@ -0,0 +1,1041 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set src.dir + Must set test.src.dir + Must set build.dir + Must set dist.dir + Must set build.classes.dir + Must set dist.javadoc.dir + Must set build.test.classes.dir + Must set build.test.results.dir + Must set build.classes.excludes + Must set dist.jar + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set JVM to use for profiling in profiler.info.jvm + Must set profiler agent JVM arguments in profiler.info.jvmargs.agent + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + + + + + + java -cp "${run.classpath.with.dist.jar}" ${main.class} + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + java -jar "${dist.jar.resolved}" + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set run.class + + + + Must select one file in the IDE or set run.class + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set debug.class + + + + + Must select one file in the IDE or set debug.class + + + + + Must set fix.includes + + + + + + + + + + + + + + + + + Must select one file in the IDE or set profile.class + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + Some tests failed; see details above. + + + + + + + + + Must select some files in the IDE or set test.includes + + + + Some tests failed; see details above. + + + + + Must select one file in the IDE or set test.class + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Pro Java 7 NIO.2/Chapter10/other/oth_01/nbproject/genfiles.properties b/Pro Java 7 NIO.2/Chapter10/other/oth_01/nbproject/genfiles.properties new file mode 100644 index 0000000..362aa96 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter10/other/oth_01/nbproject/genfiles.properties @@ -0,0 +1,8 @@ +build.xml.data.CRC32=3d6c6cc3 +build.xml.script.CRC32=b2fb1a0e +build.xml.stylesheet.CRC32=28e38971@1.43.1.45 +# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. +# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. +nbproject/build-impl.xml.data.CRC32=3d6c6cc3 +nbproject/build-impl.xml.script.CRC32=9e9f3819 +nbproject/build-impl.xml.stylesheet.CRC32=0c01fd8e@1.43.1.45 diff --git a/Pro Java 7 NIO.2/Chapter10/other/oth_01/nbproject/private/config.properties b/Pro Java 7 NIO.2/Chapter10/other/oth_01/nbproject/private/config.properties new file mode 100644 index 0000000..e69de29 diff --git a/Pro Java 7 NIO.2/Chapter10/other/oth_01/nbproject/private/private.properties b/Pro Java 7 NIO.2/Chapter10/other/oth_01/nbproject/private/private.properties new file mode 100644 index 0000000..a5ab360 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter10/other/oth_01/nbproject/private/private.properties @@ -0,0 +1,6 @@ +compile.on.save=true +do.depend=false +do.jar=true +javac.debug=true +javadoc.preview=true +user.properties.file=C:\\Users\\Leo\\.netbeans\\7.0\\build.properties diff --git a/Pro Java 7 NIO.2/Chapter10/other/oth_01/nbproject/private/private.xml b/Pro Java 7 NIO.2/Chapter10/other/oth_01/nbproject/private/private.xml new file mode 100644 index 0000000..c1f155a --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter10/other/oth_01/nbproject/private/private.xml @@ -0,0 +1,4 @@ + + + + diff --git a/Pro Java 7 NIO.2/Chapter10/other/oth_01/nbproject/project.properties b/Pro Java 7 NIO.2/Chapter10/other/oth_01/nbproject/project.properties new file mode 100644 index 0000000..a8e6be6 --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter10/other/oth_01/nbproject/project.properties @@ -0,0 +1,72 @@ +annotation.processing.enabled=true +annotation.processing.enabled.in.editor=false +annotation.processing.run.all.processors=true +annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output +application.title=oth_01 +application.vendor=Leo +build.classes.dir=${build.dir}/classes +build.classes.excludes=**/*.java,**/*.form +# This directory is removed when the project is cleaned: +build.dir=build +build.generated.dir=${build.dir}/generated +build.generated.sources.dir=${build.dir}/generated-sources +# Only compile against the classpath explicitly listed here: +build.sysclasspath=ignore +build.test.classes.dir=${build.dir}/test/classes +build.test.results.dir=${build.dir}/test/results +# Uncomment to specify the preferred debugger connection transport: +#debug.transport=dt_socket +debug.classpath=\ + ${run.classpath} +debug.test.classpath=\ + ${run.test.classpath} +# This directory is removed when the project is cleaned: +dist.dir=dist +dist.jar=${dist.dir}/oth_01.jar +dist.javadoc.dir=${dist.dir}/javadoc +endorsed.classpath= +excludes= +includes=** +jar.compress=false +javac.classpath= +# Space-separated list of extra javac options +javac.compilerargs= +javac.deprecation=false +javac.processorpath=\ + ${javac.classpath} +javac.source=1.7 +javac.target=1.7 +javac.test.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +javac.test.processorpath=\ + ${javac.test.classpath} +javadoc.additionalparam= +javadoc.author=false +javadoc.encoding=${source.encoding} +javadoc.noindex=false +javadoc.nonavbar=false +javadoc.notree=false +javadoc.private=false +javadoc.splitindex=true +javadoc.use=true +javadoc.version=false +javadoc.windowtitle= +main.class=oth_01.Main +manifest.file=manifest.mf +meta.inf.dir=${src.dir}/META-INF +mkdist.disabled=false +platform.active=default_platform +run.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +# Space-separated list of JVM arguments used when running the project +# (you may also define separate properties like run-sys-prop.name=value instead of -Dname=value +# or test-sys-prop.name=value to set system properties for unit tests): +run.jvmargs= +run.test.classpath=\ + ${javac.test.classpath}:\ + ${build.test.classes.dir} +source.encoding=UTF-8 +src.dir=src +test.src.dir=test diff --git a/Pro Java 7 NIO.2/Chapter10/other/oth_01/nbproject/project.xml b/Pro Java 7 NIO.2/Chapter10/other/oth_01/nbproject/project.xml new file mode 100644 index 0000000..4d8663e --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter10/other/oth_01/nbproject/project.xml @@ -0,0 +1,15 @@ + + + org.netbeans.modules.java.j2seproject + + + oth_01 + + + + + + + + + diff --git a/Pro Java 7 NIO.2/Chapter10/other/oth_01/src/oth_01/Main.java b/Pro Java 7 NIO.2/Chapter10/other/oth_01/src/oth_01/Main.java new file mode 100644 index 0000000..b17f65e --- /dev/null +++ b/Pro Java 7 NIO.2/Chapter10/other/oth_01/src/oth_01/Main.java @@ -0,0 +1,39 @@ +package oth_01; + +import java.io.IOException; +import java.net.URI; +import java.nio.file.FileSystem; +import java.nio.file.FileSystems; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.HashMap; +import java.util.Map; + +/** + * + * @author Apress + */ +public class Main { + + public static void main(String[] args) throws IOException { + + //set zip file system properties + Map env = new HashMap<>(); + env.put("create", "false"); + env.put("encoding", "ISO-8859-1"); + + // locate file system with java.net.JarURLConnection + URI uri = URI.create("jar:file:/C:/rafaelnadal/tournaments/2009/Tickets.zip"); + + try (FileSystem ZipFS = FileSystems.newFileSystem(uri, env)) { + Path fileInZip = ZipFS.getPath("/AEGONTickets.png"); + Path fileOutZip = Paths.get("C:/rafaelnadal/tournaments/2009/AEGONTicketsCopy.png"); + + // copy AEGONTickets.png outside the archive + Files.copy(fileInZip, fileOutZip); + + System.out.println("The file was successfully copied!"); + } + } +} diff --git a/Pro Java 7 NIO.2/rafaelnadal/email/vamos.txt b/Pro Java 7 NIO.2/rafaelnadal/email/vamos.txt new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/Pro Java 7 NIO.2/rafaelnadal/email/vamos.txt @@ -0,0 +1 @@ + diff --git a/Pro Java 7 NIO.2/rafaelnadal/equipment/racquet.txt b/Pro Java 7 NIO.2/rafaelnadal/equipment/racquet.txt new file mode 100644 index 0000000..6495dde --- /dev/null +++ b/Pro Java 7 NIO.2/rafaelnadal/equipment/racquet.txt @@ -0,0 +1,2 @@ +Racquet: Babolat AeroPro Drive GT +String: Babolat RPM Blast 16 \ No newline at end of file diff --git a/Pro Java 7 NIO.2/rafaelnadal/grandslam/AustralianOpen/draw_template.txt b/Pro Java 7 NIO.2/rafaelnadal/grandslam/AustralianOpen/draw_template.txt new file mode 100644 index 0000000..99b778d --- /dev/null +++ b/Pro Java 7 NIO.2/rafaelnadal/grandslam/AustralianOpen/draw_template.txt @@ -0,0 +1,5 @@ +Tournament Name: ... + +... +Here generate the draws +... \ No newline at end of file diff --git a/Pro Java 7 NIO.2/rafaelnadal/grandslam/RolandGarros/story.txt b/Pro Java 7 NIO.2/rafaelnadal/grandslam/RolandGarros/story.txt new file mode 100644 index 0000000..db51c9a --- /dev/null +++ b/Pro Java 7 NIO.2/rafaelnadal/grandslam/RolandGarros/story.txt @@ -0,0 +1 @@ +Rafa Nadal produced another masterclass of clay-court tennis to win his fifth French Open title ... diff --git a/Pro Java 7 NIO.2/rafaelnadal/grandslam/USOpen/draw_template.txt b/Pro Java 7 NIO.2/rafaelnadal/grandslam/USOpen/draw_template.txt new file mode 100644 index 0000000..99b778d --- /dev/null +++ b/Pro Java 7 NIO.2/rafaelnadal/grandslam/USOpen/draw_template.txt @@ -0,0 +1,5 @@ +Tournament Name: ... + +... +Here generate the draws +... \ No newline at end of file diff --git a/Pro Java 7 NIO.2/rafaelnadal/grandslam/Wimbledon/draw_template.txt b/Pro Java 7 NIO.2/rafaelnadal/grandslam/Wimbledon/draw_template.txt new file mode 100644 index 0000000..99b778d --- /dev/null +++ b/Pro Java 7 NIO.2/rafaelnadal/grandslam/Wimbledon/draw_template.txt @@ -0,0 +1,5 @@ +Tournament Name: ... + +... +Here generate the draws +... \ No newline at end of file diff --git a/Pro Java 7 NIO.2/rafaelnadal/photos/rafa_1.jpg b/Pro Java 7 NIO.2/rafaelnadal/photos/rafa_1.jpg new file mode 100644 index 0000000..bc3a64a Binary files /dev/null and b/Pro Java 7 NIO.2/rafaelnadal/photos/rafa_1.jpg differ diff --git a/Pro Java 7 NIO.2/rafaelnadal/photos/rafa_winner.jpg b/Pro Java 7 NIO.2/rafaelnadal/photos/rafa_winner.jpg new file mode 100644 index 0000000..c58093a Binary files /dev/null and b/Pro Java 7 NIO.2/rafaelnadal/photos/rafa_winner.jpg differ diff --git a/Pro Java 7 NIO.2/rafaelnadal/rafa_2.jpg b/Pro Java 7 NIO.2/rafaelnadal/rafa_2.jpg new file mode 100644 index 0000000..17152b3 Binary files /dev/null and b/Pro Java 7 NIO.2/rafaelnadal/rafa_2.jpg differ diff --git a/Pro Java 7 NIO.2/rafaelnadal/tournaments/2009/AEGON.txt b/Pro Java 7 NIO.2/rafaelnadal/tournaments/2009/AEGON.txt new file mode 100644 index 0000000..c1b0730 --- /dev/null +++ b/Pro Java 7 NIO.2/rafaelnadal/tournaments/2009/AEGON.txt @@ -0,0 +1 @@ +x \ No newline at end of file diff --git a/Pro Java 7 NIO.2/rafaelnadal/tournaments/2009/BNP.txt b/Pro Java 7 NIO.2/rafaelnadal/tournaments/2009/BNP.txt new file mode 100644 index 0000000..e69de29 diff --git a/Pro Java 7 NIO.2/rafaelnadal/tournaments/2009/BrasilOpen.txt b/Pro Java 7 NIO.2/rafaelnadal/tournaments/2009/BrasilOpen.txt new file mode 100644 index 0000000..1ff2be9 --- /dev/null +++ b/Pro Java 7 NIO.2/rafaelnadal/tournaments/2009/BrasilOpen.txt @@ -0,0 +1,2 @@ +Brasil Open At Forefront Of Green Movement +The Brasil Open, the second stop of the four-tournament Latin American swing, is held in an area renowned for its lush natural beauty and stunning beaches.From this point forward ... diff --git a/Pro Java 7 NIO.2/rafaelnadal/tournaments/2009/CopaClaro.txt b/Pro Java 7 NIO.2/rafaelnadal/tournaments/2009/CopaClaro.txt new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/Pro Java 7 NIO.2/rafaelnadal/tournaments/2009/CopaClaro.txt @@ -0,0 +1 @@ + diff --git a/Pro Java 7 NIO.2/rafaelnadal/tournaments/2009/HeinekenOpen.txt b/Pro Java 7 NIO.2/rafaelnadal/tournaments/2009/HeinekenOpen.txt new file mode 100644 index 0000000..3ea9364 --- /dev/null +++ b/Pro Java 7 NIO.2/rafaelnadal/tournaments/2009/HeinekenOpen.txt @@ -0,0 +1,2 @@ +The Pride Of New Zealand +The Heineken Open is the biggest men’s professional sporting event in New Zealand, held in Auckland since 1956. Played in the week prior to the Australian Open, the ATP World Tour 250 event is a crucial stop in preparation for the year's first Grand Slam tournament. John Isner won the Auckland title in 2010, and went on to reach the Melbourne fourth round for the first time. diff --git a/Pro Java 7 NIO.2/rafaelnadal/tournaments/2009/MovistarOpen.txt b/Pro Java 7 NIO.2/rafaelnadal/tournaments/2009/MovistarOpen.txt new file mode 100644 index 0000000..0a8c273 --- /dev/null +++ b/Pro Java 7 NIO.2/rafaelnadal/tournaments/2009/MovistarOpen.txt @@ -0,0 +1 @@ +The Movistar Open moved to Santiago from Viña del Mar in 2010. It is the first clay-court tournament of the ATP World Tour season and also the opening leg of the four-tournament swing through Latin America, aptly coined the "Golden Swing" in honour of top Chileans and Olympic Gold medalists Fernando Gonsales and Nicolas Massu. Gonzalez is a four-time champion. \ No newline at end of file diff --git a/Pro Java 7 NIO.2/rafaelnadal/tournaments/2009/MutuaMadridOpen.txt b/Pro Java 7 NIO.2/rafaelnadal/tournaments/2009/MutuaMadridOpen.txt new file mode 100644 index 0000000..e69de29 diff --git a/Pro Java 7 NIO.2/rafaelnadal/tournaments/2009/Tickets.zip b/Pro Java 7 NIO.2/rafaelnadal/tournaments/2009/Tickets.zip new file mode 100644 index 0000000..0d3de41 Binary files /dev/null and b/Pro Java 7 NIO.2/rafaelnadal/tournaments/2009/Tickets.zip differ diff --git a/Pro Java 7 NIO.2/rafaelnadal/tournaments/2009/TournamentsCalendar.xls b/Pro Java 7 NIO.2/rafaelnadal/tournaments/2009/TournamentsCalendar.xls new file mode 100644 index 0000000..235b848 Binary files /dev/null and b/Pro Java 7 NIO.2/rafaelnadal/tournaments/2009/TournamentsCalendar.xls differ diff --git a/Pro Java 7 NIO.2/rafaelnadal/tournaments/2009/prices.txt b/Pro Java 7 NIO.2/rafaelnadal/tournaments/2009/prices.txt new file mode 100644 index 0000000..e69de29 diff --git a/Pro Java 7 NIO.2/rafaelnadal/tournaments/2009/supershot.bmp b/Pro Java 7 NIO.2/rafaelnadal/tournaments/2009/supershot.bmp new file mode 100644 index 0000000..545b7d2 Binary files /dev/null and b/Pro Java 7 NIO.2/rafaelnadal/tournaments/2009/supershot.bmp differ diff --git a/Pro Java 7 NIO.2/rafaelnadal/tournaments/2009/videos/Rafa Best Shots.mp4 b/Pro Java 7 NIO.2/rafaelnadal/tournaments/2009/videos/Rafa Best Shots.mp4 new file mode 100644 index 0000000..166777e Binary files /dev/null and b/Pro Java 7 NIO.2/rafaelnadal/tournaments/2009/videos/Rafa Best Shots.mp4 differ diff --git a/Pro Java 7 NIO.2/readme.txt b/Pro Java 7 NIO.2/readme.txt new file mode 100644 index 0000000..1ee0093 --- /dev/null +++ b/Pro Java 7 NIO.2/readme.txt @@ -0,0 +1 @@ +Before testing the applications copy the /rafaelnadal folder into your C:/ root or /home. diff --git a/README.md b/README.md new file mode 100644 index 0000000..dd6acb9 --- /dev/null +++ b/README.md @@ -0,0 +1,15 @@ +#Apress Source Code + +This repository accompanies [*Pro Java 7 NIO.2*](http://www.apress.com/9781430240112) by Anghel Leonard (Apress, 2011). + +![Cover image](9781430240112.jpg) + +Download the files as a zip using the green button, or clone the repository to your machine using Git. + +##Releases + +Release v1.0 corresponds to the code in the published book, without corrections or updates. + +##Contributions + +See the file Contributing.md for more information on how you can contribute to this repository. diff --git a/contributing.md b/contributing.md new file mode 100644 index 0000000..f6005ad --- /dev/null +++ b/contributing.md @@ -0,0 +1,14 @@ +# Contributing to Apress Source Code + +Copyright for Apress source code belongs to the author(s). However, under fair use you are encouraged to fork and contribute minor corrections and updates for the benefit of the author(s) and other readers. + +## How to Contribute + +1. Make sure you have a GitHub account. +2. Fork the repository for the relevant book. +3. Create a new branch on which to make your change, e.g. +`git checkout -b my_code_contribution` +4. Commit your change. Include a commit message describing the correction. Please note that if your commit message is not clear, the correction will not be accepted. +5. Submit a pull request. + +Thank you for your contribution! \ No newline at end of file