001/* 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, 013 * software distributed under the License is distributed on an 014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 015 * KIND, either express or implied. See the License for the 016 * specific language governing permissions and limitations 017 * under the License. 018 */ 019package org.eclipse.aether.spi.io; 020 021import java.io.File; 022import java.io.IOException; 023import java.io.InputStream; 024import java.nio.ByteBuffer; 025 026/** 027 * A utility component to perform file-based operations. 028 * 029 * @deprecated Use {@link PathProcessor} or {@link ChecksumProcessor} instead. 030 */ 031@Deprecated 032public interface FileProcessor { 033 034 /** 035 * Creates the directory named by the given abstract pathname, including any necessary but nonexistent parent 036 * directories. Note that if this operation fails it may have succeeded in creating some of the necessary parent 037 * directories. 038 * 039 * @param directory The directory to create, may be {@code null}. 040 * @return {@code true} if and only if the directory was created, along with all necessary parent directories; 041 * {@code false} otherwise 042 */ 043 boolean mkdirs(File directory); 044 045 /** 046 * Writes the given data to a file. UTF-8 is assumed as encoding for the data. Creates the necessary directories for 047 * the target file. In case of an error, the created directories will be left on the file system. 048 * 049 * @param target The file to write to, must not be {@code null}. This file will be overwritten. 050 * @param data The data to write, may be {@code null}. 051 * @throws IOException If an I/O error occurs. 052 */ 053 void write(File target, String data) throws IOException; 054 055 /** 056 * Writes the given stream to a file. Creates the necessary directories for the target file. In case of an error, 057 * the created directories will be left on the file system. 058 * 059 * @param target The file to write to, must not be {@code null}. This file will be overwritten. 060 * @param source The stream to write to the file, must not be {@code null}. 061 * @throws IOException If an I/O error occurs. 062 */ 063 void write(File target, InputStream source) throws IOException; 064 065 /** 066 * Moves the specified source file to the given target file. If the target file already exists, it is overwritten. 067 * Creates the necessary directories for the target file. In case of an error, the created directories will be left 068 * on the file system. 069 * 070 * @param source The file to move from, must not be {@code null}. 071 * @param target The file to move to, must not be {@code null}. 072 * @throws IOException If an I/O error occurs. 073 */ 074 void move(File source, File target) throws IOException; 075 076 /** 077 * Copies the specified source file to the given target file. Creates the necessary directories for the target file. 078 * In case of an error, the created directories will be left on the file system. 079 * 080 * @param source The file to copy from, must not be {@code null}. 081 * @param target The file to copy to, must not be {@code null}. 082 * @throws IOException If an I/O error occurs. 083 */ 084 void copy(File source, File target) throws IOException; 085 086 /** 087 * Copies the specified source file to the given target file. Creates the necessary directories for the target file. 088 * In case of an error, the created directories will be left on the file system. 089 * 090 * @param source The file to copy from, must not be {@code null}. 091 * @param target The file to copy to, must not be {@code null}. 092 * @param listener The listener to notify about the copy progress, may be {@code null}. 093 * @return The number of copied bytes. 094 * @throws IOException If an I/O error occurs. 095 */ 096 long copy(File source, File target, ProgressListener listener) throws IOException; 097 098 /** 099 * 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}