1 package org.sonatype.aether.spi.io; 2 3 /******************************************************************************* 4 * Copyright (c) 2010-2011 Sonatype, Inc. 5 * All rights reserved. This program and the accompanying materials 6 * are made available under the terms of the Eclipse Public License v1.0 7 * which accompanies this distribution, and is available at 8 * http://www.eclipse.org/legal/epl-v10.html 9 *******************************************************************************/ 10 11 import java.io.File; 12 import java.io.IOException; 13 import java.nio.ByteBuffer; 14 15 /** 16 * A utility component to perform file-based operations. 17 * 18 * @author Benjamin Hanzelmann 19 * @author Benjamin Bentmann 20 */ 21 public interface FileProcessor 22 { 23 24 /** 25 * Creates the directory named by the given abstract pathname, including any necessary but nonexistent parent 26 * directories. Note that if this operation fails it may have succeeded in creating some of the necessary parent 27 * directories. 28 * 29 * @param directory The directory to create, may be {@code null}. 30 * @return {@code true} if and only if the directory was created, along with all necessary parent directories; 31 * {@code false} otherwise 32 */ 33 boolean mkdirs( File directory ); 34 35 /** 36 * Writes the given data to a file. UTF-8 is assumed as encoding for the data. Creates the necessary directories for 37 * the target file. In case of an error, the created directories will be left on the file system. 38 * 39 * @param file The file to write to, must not be {@code null}. This file will be overwritten. 40 * @param data The data to write, may be {@code null}. 41 * @throws IOException If an I/O error occurs. 42 */ 43 void write( File file, String data ) 44 throws IOException; 45 46 /** 47 * Copies the specified source file to the given target file. Creates the necessary directories for the target file. 48 * In case of an error, the created directories will be left on the file system. 49 * 50 * @param source The file to copy from, must not be {@code null}. 51 * @param target The file to copy to, must not be {@code null}. 52 * @param listener The listener to notify about the copy progress, may be {@code null}. 53 * @return The number of copied bytes. 54 * @throws IOException If an I/O error occurs. 55 */ 56 long copy( File source, File target, ProgressListener listener ) 57 throws IOException; 58 59 /** 60 * Moves the specified source file to the given target file. If the target file already exists, it is overwritten. 61 * Creates the necessary directories for the target file. In case of an error, the created directories will be left 62 * on the file system. 63 * 64 * @param source The file to move from, must not be {@code null}. 65 * @param target The file to move to, must not be {@code null}. 66 * @throws IOException If an I/O error occurs. 67 */ 68 void move( File source, File target ) 69 throws IOException; 70 71 /** 72 * A listener object that is notified for every progress made while copying files. 73 * 74 * @author Benjamin Hanzelmann 75 * @see FileProcessor#copy(File, File, ProgressListener) 76 */ 77 public interface ProgressListener 78 { 79 80 void progressed( ByteBuffer buffer ) 81 throws IOException; 82 83 } 84 85 }