View Javadoc
1   package org.eclipse.aether.spi.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 java.io.File;
23  import java.io.IOException;
24  import java.io.InputStream;
25  import java.nio.ByteBuffer;
26  
27  /**
28   * A utility component to perform file-based operations.
29   */
30  public interface FileProcessor
31  {
32  
33      /**
34       * Creates the directory named by the given abstract pathname, including any necessary but nonexistent parent
35       * directories. Note that if this operation fails it may have succeeded in creating some of the necessary parent
36       * directories.
37       * 
38       * @param directory The directory to create, may be {@code null}.
39       * @return {@code true} if and only if the directory was created, along with all necessary parent directories;
40       *         {@code false} otherwise
41       */
42      boolean mkdirs( File directory );
43  
44      /**
45       * Writes the given data to a file. UTF-8 is assumed as encoding for the data. Creates the necessary directories for
46       * the target file. In case of an error, the created directories will be left on the file system.
47       * 
48       * @param target The file to write to, must not be {@code null}. This file will be overwritten.
49       * @param data The data to write, may be {@code null}.
50       * @throws IOException If an I/O error occurs.
51       */
52      void write( File target, String data )
53          throws IOException;
54  
55      /**
56       * Writes the given stream to a file. Creates the necessary directories for the target file. In case of an error,
57       * the created directories will be left on the file system.
58       * 
59       * @param target The file to write to, must not be {@code null}. This file will be overwritten.
60       * @param source The stream to write to the file, must not be {@code null}.
61       * @throws IOException If an I/O error occurs.
62       */
63      void write( File target, InputStream source )
64          throws IOException;
65  
66      /**
67       * Moves the specified source file to the given target file. If the target file already exists, it is overwritten.
68       * Creates the necessary directories for the target file. In case of an error, the created directories will be left
69       * on the file system.
70       * 
71       * @param source The file to move from, must not be {@code null}.
72       * @param target The file to move to, must not be {@code null}.
73       * @throws IOException If an I/O error occurs.
74       */
75      void move( File source, File target )
76          throws IOException;
77  
78      /**
79       * Copies the specified source file to the given target file. Creates the necessary directories for the target file.
80       * In case of an error, the created directories will be left on the file system.
81       * 
82       * @param source The file to copy from, must not be {@code null}.
83       * @param target The file to copy to, must not be {@code null}.
84       * @throws IOException If an I/O error occurs.
85       */
86      void copy( File source, File target )
87          throws IOException;
88  
89      /**
90       * Copies the specified source file to the given target file. Creates the necessary directories for the target file.
91       * In case of an error, the created directories will be left on the file system.
92       * 
93       * @param source The file to copy from, must not be {@code null}.
94       * @param target The file to copy to, must not be {@code null}.
95       * @param listener The listener to notify about the copy progress, may be {@code null}.
96       * @return The number of copied bytes.
97       * @throws IOException If an I/O error occurs.
98       */
99      long copy( File source, File target, ProgressListener listener )
100         throws IOException;
101 
102     /**
103      * A listener object that is notified for every progress made while copying files.
104      * 
105      * @see FileProcessor#copy(File, File, ProgressListener)
106      */
107     public interface ProgressListener
108     {
109 
110         void progressed( ByteBuffer buffer )
111             throws IOException;
112 
113     }
114 
115 }