2017-05-05 15:16:09 +00:00
|
|
|
/*
|
2017-05-01 13:32:39 +00:00
|
|
|
* This file is part of the public ComputerCraft API - http://www.computercraft.info
|
|
|
|
* Copyright Daniel Ratcliffe, 2011-2016. This API may be redistributed unmodified and in full only.
|
|
|
|
* For help using the API, and posting your mods, visit the forums at computercraft.info.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package dan200.computercraft.api.filesystem;
|
|
|
|
|
2017-05-05 13:56:15 +00:00
|
|
|
import dan200.computercraft.api.ComputerCraftAPI;
|
|
|
|
import dan200.computercraft.api.peripheral.IComputerAccess;
|
|
|
|
import net.minecraft.world.World;
|
|
|
|
|
2017-05-01 13:32:39 +00:00
|
|
|
import java.io.IOException;
|
|
|
|
import java.io.OutputStream;
|
|
|
|
|
|
|
|
/**
|
2017-05-05 13:56:15 +00:00
|
|
|
* Represents a part of a virtual filesystem that can be mounted onto a computer using {@link IComputerAccess#mount(String, IMount)}
|
|
|
|
* or {@link IComputerAccess#mountWritable(String, IWritableMount)}, that can also be written to.
|
|
|
|
*
|
|
|
|
* Ready made implementations of this interface can be created using
|
|
|
|
* {@link ComputerCraftAPI#createSaveDirMount(World, String, long)}, or you're free to implement it yourselves!
|
|
|
|
*
|
|
|
|
* @see ComputerCraftAPI#createSaveDirMount(World, String, long)
|
|
|
|
* @see IComputerAccess#mount(String, IMount)
|
|
|
|
* @see IComputerAccess#mountWritable(String, IWritableMount)
|
|
|
|
* @see IMount
|
2017-05-01 13:32:39 +00:00
|
|
|
*/
|
|
|
|
public interface IWritableMount extends IMount
|
|
|
|
{
|
2017-05-01 14:48:44 +00:00
|
|
|
/**
|
|
|
|
* Creates a directory at a given path inside the virtual file system.
|
2017-05-05 13:56:15 +00:00
|
|
|
*
|
|
|
|
* @param path A file path in normalised format, relative to the mount location. ie: "programs/mynewprograms".
|
2017-05-05 15:07:18 +00:00
|
|
|
* @throws IOException If the directory already exists or could not be created.
|
2017-05-01 14:48:44 +00:00
|
|
|
*/
|
|
|
|
public void makeDirectory( String path ) throws IOException;
|
2017-05-01 13:32:39 +00:00
|
|
|
|
2017-05-01 14:48:44 +00:00
|
|
|
/**
|
|
|
|
* Deletes a directory at a given path inside the virtual file system.
|
2017-05-05 13:56:15 +00:00
|
|
|
*
|
|
|
|
* @param path A file path in normalised format, relative to the mount location. ie: "programs/myoldprograms".
|
2017-05-05 15:07:18 +00:00
|
|
|
* @throws IOException If the file does not exist or could not be deleted.
|
2017-05-01 14:48:44 +00:00
|
|
|
*/
|
|
|
|
public void delete( String path ) throws IOException;
|
2017-05-01 13:32:39 +00:00
|
|
|
|
2017-05-01 14:48:44 +00:00
|
|
|
/**
|
2017-05-05 13:56:15 +00:00
|
|
|
* Opens a file with a given path, and returns an {@link OutputStream} for writing to it.
|
|
|
|
*
|
|
|
|
* @param path A file path in normalised format, relative to the mount location. ie: "programs/myprogram".
|
2017-05-05 15:07:18 +00:00
|
|
|
* @return A stream for writing to
|
|
|
|
* @throws IOException If the file could not be opened for writing.
|
2017-05-01 14:48:44 +00:00
|
|
|
*/
|
|
|
|
public OutputStream openForWrite( String path ) throws IOException;
|
2017-05-01 13:32:39 +00:00
|
|
|
|
2017-05-01 14:48:44 +00:00
|
|
|
/**
|
2017-05-05 13:56:15 +00:00
|
|
|
* Opens a file with a given path, and returns an {@link OutputStream} for appending to it.
|
|
|
|
*
|
|
|
|
* @param path A file path in normalised format, relative to the mount location. ie: "programs/myprogram".
|
|
|
|
* @return A stream for writing to.
|
2017-05-05 15:07:18 +00:00
|
|
|
* @throws IOException If the file could not be opened for writing.
|
2017-05-01 14:48:44 +00:00
|
|
|
*/
|
|
|
|
public OutputStream openForAppend( String path ) throws IOException;
|
2017-05-01 13:32:39 +00:00
|
|
|
|
2017-05-01 14:48:44 +00:00
|
|
|
/**
|
2017-05-05 13:56:15 +00:00
|
|
|
* Get the amount of free space on the mount, in bytes. You should decrease this value as the user writes to the
|
|
|
|
* mount, and write operations should fail once it reaches zero.
|
|
|
|
*
|
|
|
|
* @return The amount of free space, in bytes.
|
2017-05-05 15:07:18 +00:00
|
|
|
* @throws IOException If the remaining space could not be computed.
|
2017-05-01 14:48:44 +00:00
|
|
|
*/
|
|
|
|
public long getRemainingSpace() throws IOException;
|
2017-05-01 13:32:39 +00:00
|
|
|
}
|