Skip to content

Commit

Permalink
Corrections in chapters 17 and 24
Browse files Browse the repository at this point in the history
  • Loading branch information
Esteban Herrera committed Dec 30, 2016
1 parent b730aba commit d4de3df
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
4 changes: 2 additions & 2 deletions ch17.html
Expand Up @@ -395,8 +395,8 @@ <h2>collect()</h2>
&nbsp; &nbsp; Stream.of(<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>, <span class="hljs-number">4</span>, <span class="hljs-number">5</span>)<br />
&nbsp; &nbsp; &nbsp; &nbsp; .collect(<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;() -&gt; <span class="hljs-keyword">new</span> ArrayList&lt;&gt;(),<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;(l, i) -&gt; l.add(i),<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;(l1, l2) -&gt; l1.addAll(l2)<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;(List&lt;Integer&gt; l, Integer i) -&gt; l.add(i),<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;(List&lt;Integer&gt; l1, List&lt;Integer&gt; l2) -&gt; l1.addAll(l2)<br />
&nbsp; &nbsp; &nbsp; &nbsp; );</code></p>

<p>Or we can also use method references:</p>
Expand Down
12 changes: 6 additions & 6 deletions ch24.html
Expand Up @@ -50,7 +50,7 @@ <h2>NIO.2</h2>

<p>For that reason, Java 1.4 introduced the NIO (Non-blocking Input/Output) API in the package <code>java.nio</code> implementing new functionality like channels, buffering, and new charsets.</p>

<p>However, this API didn't entirely solve the problems with the <code>java.io</code> package, so in Java 7, the NIO.2 API was added in the <code>java.nio.file</code> package (actually, since this is a new package, NIO.2 is not an update to the NIO API, besides, the focus on different things).</p>
<p>However, this API didn't entirely solve the problems with the <code>java.io</code> package, so in Java 7, the NIO.2 API was added in the <code>java.nio.file</code> package (actually, since this is a new package, NIO.2 is not an update to the NIO API, besides, they focus on different things).</p>

<p>NIO.2 provides better support for accessing files and the file system, symbolic links, interoperability, and exceptions among others.</p>

Expand Down Expand Up @@ -297,12 +297,12 @@ <h2>The Path interface</h2>

<p>The <code>equals()</code> implementation is system-dependent (for example, it's case insensitive on Windows systems). However, it returns <code>false</code> if the argument is not a <code>Path</code> or if it belongs to a different file system.</p>

<p>In addition, the methods <code>startsWith()</code> and <code>endsWith()</code> both test whether a path begins or ends with some <code>String</code> or <code>Path</code>. So given:</p>
<p>In addition, the methods <code>startsWith()</code> and <code>endsWith()</code> both test whether a path begins or ends with some <code>String</code> (in this case, the methods return <code>true</code> only if the string represents an actual element) or <code>Path</code>. So given:</p>

<p><code class="java hljs">Path absPath = Paths.get(<span class="hljs-string">"c:\\temp\\dir1\\file.txt"</span>);<br />
Path relPath = Paths.get(<span class="hljs-string">"temp\\dir1\\file.txt"</span>);</code></p>

<p><code class="java hljs"><span class="hljs-keyword">boolean</span> <span class="hljs-title">startsWith</span><span class="hljs-params">(Path other)</span><br />
<p><code class="java hljs"><span class="hljs-function"><span class="hljs-keyword">boolean</span> <span class="hljs-title">startsWith</span><span class="hljs-params">(Path other)</span></span><br />
absPath.<span class="hljs-title">startsWith</span><span class="hljs-params">(Paths.get(<span class="hljs-string">"c:\\temp\\file.txt"</span>)</span>); <span class="hljs-comment">// false</span><br />
absPath.startsWith(Paths.get(<span class="hljs-string">"c:\\temp\\dir1\\img.jpg"</span>)); <span class="hljs-comment">// false</span><br />
absPath.startsWith(Paths.get(<span class="hljs-string">"c:\\temp\\dir1\\"</span>)) <span class="hljs-comment">// true</span><br />
Expand Down Expand Up @@ -357,8 +357,8 @@ <h2>The Files class</h2>

<p>To read a file, we can load the entire file into memory (only useful for small files) with the methods:</p>

<p><code class="java hljs"><span class="hljs-keyword">static</span> <span class="hljs-keyword">byte</span>[] readAllBytes(Path path)<br />
<span class="hljs-function"><span class="hljs-keyword">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; throws</span> IOException<br />
<p><code class="java hljs"><span class="hljs-function"><span class="hljs-keyword">static</span> <span class="hljs-keyword">byte</span>[] <span class="hljs-title">readAllBytes</span><span class="hljs-params">(Path path)</span><br />
<span class="hljs-keyword">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; throws</span> IOException<br />
<span class="hljs-keyword">static</span> List&lt;String&gt; <span class="hljs-title">readAllLines</span><span class="hljs-params">(Path path)</span><br />
<span class="hljs-keyword">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; throws</span> IOException<br />
<span class="hljs-keyword">static</span> List&lt;String&gt; <span class="hljs-title">readAllLines</span><span class="hljs-params">(Path path, Charset cs)</span><br />
Expand Down Expand Up @@ -457,7 +457,7 @@ <h2>The Files class</h2>
<p><code class="java hljs"><span class="hljs-function"><span class="hljs-keyword">static</span> <span class="hljs-keyword">long</span> <span class="hljs-title">copy</span><span class="hljs-params">(InputStream in, Path target,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;CopyOption... options)</span> <span class="hljs-keyword">throws</span> IOException</span></code></p>

<p>Copies all bytes from an input stream to a file. By default, the copy fails if the target already exists or is a symbolic link. If the <code>StandardCopyOption.REPLACE_EXISTING</code> option is specified</p>
<p>Copies all bytes from an input stream to a file. By default, the copy fails if the target already exists or is a symbolic link. If the <code>StandardCopyOption.REPLACE_EXISTING</code> option is specified, and the target file already exists, then it is replaced if it's not a non-empty directory. If the target file exists and is a symbolic link, then the symbolic link is replaced. Actually, in Java 8, the <code>REPLACE_EXISTING</code> option is the only option required to be supported by this method.</p>

<p><code class="java hljs"><span class="hljs-function"><span class="hljs-keyword">static</span> <span class="hljs-keyword">long</span> <span class="hljs-title">copy</span><span class="hljs-params">(Path source,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;OutputStream out)</span> <span class="hljs-keyword">throws</span> IOException</span></code></p>
Expand Down
2 changes: 1 addition & 1 deletion ch24a.html
Expand Up @@ -55,7 +55,7 @@ <h2>Answers</h2>
<p><br /></p>

<p><b>3. The correct answer is C.</b><br />
<code>CopyOption</code> is an enumeration of the values <code>NOFOLLOW_LINKS</code>, <code>REPLACE_EXISTING</code>, <code>COPY_ATTRIBUTES</code>.</p>
<code>CopyOption</code> is an interface implemented by the enumerations <code>StandardCopyOptions</code> (with the values <code>ATOMIC_MOVE</code> (not supported), <code>REPLACE_EXISTING</code>, <code>COPY_ATTRIBUTES</code>) and <code>LinkOption</code> (with the value <code>NOFOLLOW_LINKS</code>).

<p><br /></p>

Expand Down

0 comments on commit d4de3df

Please sign in to comment.