1 /* 2 * Copyright (C) 2003-2009 JNode.org 3 * 2009,2010 Matthias Treydte <mt@waldheinz.de> 4 * 5 * This library is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU Lesser General Public License as published 7 * by the Free Software Foundation; either version 2.1 of the License, or 8 * (at your option) any later version. 9 * 10 * This library is distributed in the hope that it will be useful, but 11 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 12 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 13 * License for more details. 14 * 15 * You should have received a copy of the GNU Lesser General Public License 16 * along with this library; If not, write to the Free Software Foundation, Inc., 17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 18 */ 19 20 package de.waldheinz.fs; 21 22 import java.io.IOException; 23 import java.nio.ByteBuffer; 24 25 /** 26 * A FsFile is a representation of a single block of bytes on a filesystem. It 27 * is comparable to an inode in Unix. 28 * 29 * An FsFile does not have any knowledge of who is using this file. It is also 30 * possible that the system uses a single FsFile instance to create two 31 * inputstream's for two different principals. 32 * 33 * @author Ewout Prangsma <epr at jnode.org> 34 */ 35 public interface FsFile extends FsObject { 36 37 /** 38 * Gets the length (in bytes) of this file. 39 * 40 * @return the file size 41 */ getLength()42 public long getLength(); 43 44 /** 45 * Sets the length of this file. 46 * 47 * @param length the new length of this file 48 * @throws IOException on error updating the file size 49 */ setLength(long length)50 public void setLength(long length) throws IOException; 51 52 /** 53 * Reads from this file into the specified {@code ByteBuffer}. The 54 * first byte read will be put into the buffer at it's 55 * {@link ByteBuffer#position() position}, and the number of bytes read 56 * will equal the buffer's {@link ByteBuffer#remaining() remaining} bytes. 57 * 58 * @param offset the offset into the file where to start reading 59 * @param dest the destination buffer where to put the bytes that were read 60 * @throws IOException on read error 61 */ read(long offset, ByteBuffer dest)62 public void read(long offset, ByteBuffer dest) throws IOException; 63 64 /** 65 * Writes to this file taking the data to write from the specified 66 * {@code ByteBuffer}. This method will read the buffer's 67 * {@link ByteBuffer#remaining() remaining} bytes starting at it's 68 * {@link ByteBuffer#position() position}. 69 * 70 * @param offset the offset into the file where the first byte will be 71 * written 72 * @param src the source buffer to read the data from 73 * @throws ReadOnlyException if the file is read-only 74 * @throws IOException on write error 75 */ write(long offset, ByteBuffer src)76 public void write(long offset, ByteBuffer src) 77 throws ReadOnlyException, IOException; 78 79 /** 80 * Flush any possibly cached data to the disk. 81 * 82 * @throws IOException on error flushing 83 */ flush()84 public void flush() throws IOException; 85 } 86