View Javadoc
1   package org.apache.maven.shared.utils.io;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import javax.annotation.Nonnull;
23  import java.io.File;
24  import java.io.IOException;
25  import java.nio.file.Files;
26  
27  /**
28   * Java7 feature detection
29   *
30   * @author Kristian Rosenvold
31   *
32   * @deprecated no longer needed, prefer to use {@link java.nio.file.Files} methods directly.
33   */
34  @Deprecated
35  public class Java7Support
36  {
37      /**
38       * @param file The file to check for being a symbolic link.
39       * @return true if the file is a symlink false otherwise.
40       */
41      public static boolean isSymLink( @Nonnull File file )
42      {
43          return Files.isSymbolicLink( file.toPath() );
44      }
45  
46      /**
47       * @param symlink The sym link.
48       * @return The file.
49       * @throws IOException in case of error.
50       */
51      @Nonnull public static File readSymbolicLink( @Nonnull File symlink )
52          throws IOException
53      {
54          return Files.readSymbolicLink( symlink.toPath() ).toFile();
55      }
56  
57      /**
58       * @param file The file to check.
59       * @return true if exist false otherwise.
60       * @throws IOException in case of failure.
61       */
62      public static boolean exists( @Nonnull File file )
63          throws IOException
64      {
65          return Files.exists( file.toPath() );
66      }
67  
68      /**
69       * @param symlink The link name.
70       * @param target The target.
71       * @return The linked file.
72       * @throws IOException in case of an error.
73       */
74      @Nonnull public static File createSymbolicLink( @Nonnull File symlink,  @Nonnull File target )
75          throws IOException
76      {
77          return FileUtils.createSymbolicLink( symlink, target );
78      }
79  
80      /**
81       * Performs a nio delete
82       * @param file the file to delete
83       * @throws IOException in case of error.
84       */
85      public static void delete( @Nonnull File file )
86          throws IOException
87      {
88          Files.delete( file.toPath() );
89      }
90  
91      /**
92       * @return true in case of Java 7.
93       */
94      public static boolean isJava7()
95      {
96          return true;
97      }
98  
99      /**
100      * @return true in case of Java7 or greater.
101      */
102     public static boolean isAtLeastJava7()
103     {
104         return true;
105     }
106 }