1 /* 2 * Licensed to the Apache Software Foundation (ASF) under one 3 * or more contributor license agreements. See the NOTICE file 4 * distributed with this work for additional information 5 * regarding copyright ownership. The ASF licenses this file 6 * to you under the Apache License, Version 2.0 (the 7 * "License"); you may not use this file except in compliance 8 * with the License. You may obtain a copy of the License at 9 * 10 * http://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, 13 * software distributed under the License is distributed on an 14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 * KIND, either express or implied. See the License for the 16 * specific language governing permissions and limitations 17 * under the License. 18 */ 19 package org.eclipse.aether.spi.io; 20 21 import java.io.File; 22 import java.io.IOException; 23 import java.io.InputStream; 24 import java.nio.ByteBuffer; 25 26 /** 27 * A utility component to perform file-based operations. 28 * 29 * @deprecated Use {@link PathProcessor} or {@link ChecksumProcessor} instead. 30 */ 31 @Deprecated 32 public interface FileProcessor { 33 34 /** 35 * Creates the directory named by the given abstract pathname, including any necessary but nonexistent parent 36 * directories. Note that if this operation fails it may have succeeded in creating some of the necessary parent 37 * directories. 38 * 39 * @param directory The directory to create, may be {@code null}. 40 * @return {@code true} if and only if the directory was created, along with all necessary parent directories; 41 * {@code false} otherwise 42 */ 43 boolean mkdirs(File directory); 44 45 /** 46 * Writes the given data to a file. UTF-8 is assumed as encoding for the data. Creates the necessary directories for 47 * the target file. In case of an error, the created directories will be left on the file system. 48 * 49 * @param target The file to write to, must not be {@code null}. This file will be overwritten. 50 * @param data The data to write, may be {@code null}. 51 * @throws IOException If an I/O error occurs. 52 */ 53 void write(File target, String data) 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) throws IOException; 64 65 /** 66 * Moves the specified source file to the given target file. If the target file already exists, it is overwritten. 67 * Creates the necessary directories for the target file. In case of an error, the created directories will be left 68 * on the file system. 69 * 70 * @param source The file to move from, must not be {@code null}. 71 * @param target The file to move to, must not be {@code null}. 72 * @throws IOException If an I/O error occurs. 73 */ 74 void move(File source, File target) throws IOException; 75 76 /** 77 * Copies the specified source file to the given target file. Creates the necessary directories for the target file. 78 * In case of an error, the created directories will be left on the file system. 79 * 80 * @param source The file to copy from, must not be {@code null}. 81 * @param target The file to copy to, must not be {@code null}. 82 * @throws IOException If an I/O error occurs. 83 */ 84 void copy(File source, File target) throws IOException; 85 86 /** 87 * Copies the specified source file to the given target file. Creates the necessary directories for the target file. 88 * In case of an error, the created directories will be left on the file system. 89 * 90 * @param source The file to copy from, must not be {@code null}. 91 * @param target The file to copy to, must not be {@code null}. 92 * @param listener The listener to notify about the copy progress, may be {@code null}. 93 * @return The number of copied bytes. 94 * @throws IOException If an I/O error occurs. 95 */ 96 long copy(File source, File target, ProgressListener listener) throws IOException; 97 98 /** 99 * A listener object that is notified for every progress made while copying files. 100 * 101 * @see FileProcessor#copy(File, File, ProgressListener) 102 */ 103 interface ProgressListener extends PathProcessor.ProgressListener { 104 105 void progressed(ByteBuffer buffer) throws IOException; 106 } 107 108 /** 109 * Reads checksum from specified file. 110 * 111 * @throws IOException in case of any IO error. 112 * @since 1.8.0 113 */ 114 String readChecksum(File checksumFile) throws IOException; 115 116 /** 117 * Writes checksum to specified file. 118 * 119 * @throws IOException in case of any IO error. 120 * @since 1.8.0 121 */ 122 void writeChecksum(File checksumFile, String checksum) throws IOException; 123 }