1. Project Clover database Sat Feb 2 2019 06:45:20 CET
  2. Package org.xwiki.velocity.tools.nio

File NIOTool.java

 

Coverage histogram

../../../../../img/srcFileCovDistChart1.png
85% of files have more coverage

Code metrics

0
35
15
1
270
114
25
0.71
2.33
15
1.67

Classes

Class Line # Actions
NIOTool 39 35 0% 25 45
0.110%
 

Contributing tests

No tests hitting this source file were found.

Source view

1    /*
2    * See the NOTICE file distributed with this work for additional
3    * information regarding copyright ownership.
4    *
5    * This is free software; you can redistribute it and/or modify it
6    * under the terms of the GNU Lesser General Public License as
7    * published by the Free Software Foundation; either version 2.1 of
8    * the License, or (at your option) any later version.
9    *
10    * This software is distributed in the hope that it will be useful,
11    * but WITHOUT ANY WARRANTY; without even the implied warranty of
12    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13    * Lesser General Public License for more details.
14    *
15    * You should have received a copy of the GNU Lesser General Public
16    * License along with this software; if not, write to the Free
17    * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18    * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
19    */
20    package org.xwiki.velocity.tools.nio;
21   
22    import java.io.BufferedReader;
23    import java.io.IOException;
24    import java.nio.charset.Charset;
25    import java.nio.file.DirectoryStream;
26    import java.nio.file.Files;
27    import java.nio.file.LinkOption;
28    import java.nio.file.Path;
29    import java.nio.file.attribute.FileTime;
30    import java.util.List;
31    import java.util.Map;
32   
33    /**
34    * Provides access to some of the static NIO2 Files methods.
35    *
36    * @version $Id: aa10ac341242c55ae56e0536210639fa47fe823a $
37    * @since 7.4M2
38    */
 
39    public class NIOTool
40    {
41    /**
42    * See {@link Files#newDirectoryStream(Path)}.
43    * <p>
44    * Velocity Example:
45    * <pre>{@code
46    * #set ($dirStream = $niotool.newDirectoryStream("attach:Sandbox.WebHome@vma.txt.zip/"))
47    * #foreach ($entry in $dirStream)
48    * * {{{$entry}}}
49    * #end
50    * }</pre>
51    *
52    * @param dir See {@link Files#newDirectoryStream(Path)}
53    * @return See {@link Files#newDirectoryStream(Path)}
54    */
 
55  2 toggle public DirectoryStream<Path> newDirectoryStream(Path dir)
56    {
57  2 try {
58  2 return new WrappingDirectoryStream(Files.newDirectoryStream(dir));
59    } catch (IOException e) {
60  0 return null;
61    }
62    }
63   
64    /**
65    * See {@link Files#newDirectoryStream(Path, DirectoryStream.Filter)}.
66    *
67    * @param dir See {@link Files#newDirectoryStream(Path, DirectoryStream.Filter)}
68    * @param filter See {@link Files#newDirectoryStream(Path, DirectoryStream.Filter)}
69    * @return See {@link Files#newDirectoryStream(Path, DirectoryStream.Filter)}
70    */
 
71  0 toggle public DirectoryStream<Path> newDirectoryStream(Path dir, DirectoryStream.Filter filter)
72    {
73  0 try {
74  0 return new WrappingDirectoryStream(Files.newDirectoryStream(dir, filter));
75    } catch (IOException e) {
76  0 return null;
77    }
78    }
79   
80    /**
81    * See {@link Files#newDirectoryStream(Path, String)}.
82    *
83    * @param dir See {@link Files#newDirectoryStream(Path, String)}
84    * @param glob See {@link Files#newDirectoryStream(Path, String)}
85    * @return See {@link Files#newDirectoryStream(Path, String)}
86    */
 
87  0 toggle public DirectoryStream<Path> newDirectoryStream(Path dir, String glob)
88    {
89  0 try {
90  0 return new WrappingDirectoryStream(Files.newDirectoryStream(dir, glob));
91    } catch (IOException e) {
92  0 return null;
93    }
94    }
95   
96    /**
97    * See {@link Files#isDirectory(Path, LinkOption...)}.
98    *
99    * @param path See {@link Files#isDirectory(Path, LinkOption...)}
100    * @param options See {@link Files#isDirectory(Path, LinkOption...)}
101    * @return See {@link Files#isDirectory(Path, LinkOption...)}
102    */
 
103  3 toggle public boolean isDirectory(Path path, LinkOption... options)
104    {
105  3 return Files.isDirectory(path, options);
106    }
107   
108    /**
109    * See {@link Files#isRegularFile(Path, LinkOption...)}.
110    *
111    * @param path See {@link Files#isRegularFile(Path, LinkOption...)}
112    * @param options See {@link Files#isRegularFile(Path, LinkOption...)}
113    * @return See {@link Files#isRegularFile(Path, LinkOption...)}
114    */
 
115  0 toggle public boolean isRegularFile(Path path, LinkOption... options)
116    {
117  0 return Files.isRegularFile(path, options);
118    }
119   
120    /**
121    * See {@link Files#isReadable(Path)}.
122    *
123    * @param path See {@link Files#isReadable(Path)}
124    * @return See {@link Files#isReadable(Path)}
125    */
 
126  0 toggle public boolean isReadable(Path path)
127    {
128  0 return Files.isReadable(path);
129    }
130   
131    /**
132    * See {@link Files#isSymbolicLink(Path)}.
133    *
134    * @param path See {@link Files#isSymbolicLink(Path)}
135    * @return See {@link Files#isSymbolicLink(Path)}
136    */
 
137  0 toggle public boolean isSymbolicLink(Path path)
138    {
139  0 return Files.isSymbolicLink(path);
140    }
141   
142    /**
143    * See {@link Files#exists(Path, LinkOption...)}.
144    *
145    * @param path See {@link Files#exists(Path, LinkOption...)}
146    * @param options See {@link Files#exists(Path, LinkOption...)}
147    * @return See {@link Files#exists(Path, LinkOption...)}
148    */
 
149  0 toggle public boolean exists(Path path, LinkOption... options)
150    {
151  0 return Files.exists(path, options);
152    }
153   
154    /**
155    * See {@link Files#readAllBytes(Path)}.
156    * <p>
157    * Velocity Example:
158    * <pre>{@code
159    * $stringtool.toString($niotool.readAllBytes("attach:Sandbox.WebHome@vma.txt.zip/vma.txt"), "utf-8")
160    * }</pre>
161    *
162    * @param path See {@link Files#readAllBytes(Path)}
163    * @return See {@link Files#readAllBytes(Path)}
164    */
 
165  0 toggle public byte[] readAllBytes(Path path)
166    {
167  0 try {
168  0 return Files.readAllBytes(path);
169    } catch (IOException e) {
170  0 return null;
171    }
172    }
173   
174    /**
175    * See {@link Files#readAllLines(Path, Charset)}.
176    *
177    * @param path See {@link Files#readAllLines(Path, Charset)}
178    * @param cs See {@link Files#readAllLines(Path, Charset)}
179    * @return See {@link Files#readAllLines(Path, Charset)}
180    */
 
181  0 toggle public List<String> readAllLines(Path path, Charset cs)
182    {
183  0 try {
184  0 return Files.readAllLines(path, cs);
185    } catch (IOException e) {
186  0 return null;
187    }
188    }
189   
190    /**
191    * See {@link Files#newBufferedReader(Path, Charset)}.
192    *
193    * @param path See {@link Files#newBufferedReader(Path, Charset)}
194    * @param cs See {@link Files#newBufferedReader(Path, Charset)}
195    * @return See {@link Files#newBufferedReader(Path, Charset)}
196    */
 
197  0 toggle public BufferedReader newBufferedReader(Path path, Charset cs)
198    {
199  0 try {
200  0 return Files.newBufferedReader(path, cs);
201    } catch (IOException e) {
202  0 return null;
203    }
204    }
205   
206    /**
207    * See {@link Files#size(Path)}.
208    *
209    * @param path See {@link Files#size(Path)}
210    * @return See {@link Files#size(Path)}
211    */
 
212  0 toggle public long size(Path path)
213    {
214  0 try {
215  0 return Files.size(path);
216    } catch (IOException e) {
217  0 return 0L;
218    }
219    }
220   
221    /**
222    * See {@link Files#getAttribute(Path, String, LinkOption...)}.
223    *
224    * @param path See {@link Files#getAttribute(Path, String, LinkOption...)}
225    * @param attribute See {@link Files#getAttribute(Path, String, LinkOption...)}
226    * @param options See {@link Files#getAttribute(Path, String, LinkOption...)}
227    * @return See {@link Files#getAttribute(Path, String, LinkOption...)}
228    */
 
229  0 toggle public Object getAttribute(Path path, String attribute, LinkOption... options)
230    {
231  0 try {
232  0 return Files.getAttribute(path, attribute, options);
233    } catch (IOException e) {
234  0 return null;
235    }
236    }
237   
238    /**
239    * See {@link Files#readAttributes(Path, String, LinkOption...)}.
240    *
241    * @param path See {@link Files#readAttributes(Path, String, LinkOption...)}
242    * @param attributes See {@link Files#readAttributes(Path, String, LinkOption...)}
243    * @param options See {@link Files#readAttributes(Path, String, LinkOption...)}
244    * @return See {@link Files#readAttributes(Path, String, LinkOption...)}
245    */
 
246  0 toggle public Map<String, Object> readAttributes(Path path, String attributes, LinkOption... options)
247    {
248  0 try {
249  0 return Files.readAttributes(path, attributes, options);
250    } catch (IOException e) {
251  0 return null;
252    }
253    }
254   
255    /**
256    * See {@link Files#getLastModifiedTime(Path, LinkOption...)}.
257    *
258    * @param path See {@link Files#getLastModifiedTime(Path, LinkOption...)}
259    * @param options See {@link Files#getLastModifiedTime(Path, LinkOption...)}
260    * @return See {@link Files#getLastModifiedTime(Path, LinkOption...)}
261    */
 
262  0 toggle public FileTime getLastModifiedTime(Path path, LinkOption... options)
263    {
264  0 try {
265  0 return Files.getLastModifiedTime(path, options);
266    } catch (IOException e) {
267  0 return null;
268    }
269    }
270    }