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
|
2017-05-13 18:20:39 +00:00
|
|
|
* Copyright Daniel Ratcliffe, 2011-2017. This API may be redistributed unmodified and in full only.
|
2017-05-01 13:32:39 +00:00
|
|
|
* 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-06 23:07:42 +00:00
|
|
|
import javax.annotation.Nonnull;
|
2017-05-01 13:32:39 +00:00
|
|
|
import java.io.IOException;
|
|
|
|
import java.io.InputStream;
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
/**
|
2017-05-05 13:56:15 +00:00
|
|
|
* Represents a read only part of a virtual filesystem that can be mounted onto a computer using
|
|
|
|
* {@link IComputerAccess#mount(String, IMount)}
|
|
|
|
*
|
|
|
|
* Ready made implementations of this interface can be created using
|
|
|
|
* {@link ComputerCraftAPI#createSaveDirMount(World, String, long)} or
|
|
|
|
* {@link ComputerCraftAPI#createResourceMount(Class, String, String)}, or you're free to implement it yourselves!
|
|
|
|
*
|
|
|
|
* @see ComputerCraftAPI#createSaveDirMount(World, String, long)
|
|
|
|
* @see ComputerCraftAPI#createResourceMount(Class, String, String)
|
|
|
|
* @see IComputerAccess#mount(String, IMount)
|
2017-05-01 13:32:39 +00:00
|
|
|
* @see IWritableMount
|
|
|
|
*/
|
|
|
|
public interface IMount
|
|
|
|
{
|
2017-05-01 14:48:44 +00:00
|
|
|
/**
|
|
|
|
* Returns whether a file with a given path exists or not.
|
2017-05-05 13:56:15 +00:00
|
|
|
*
|
2017-05-01 14:48:44 +00:00
|
|
|
* @param path A file path in normalised format, relative to the mount location. ie: "programs/myprogram"
|
2017-05-05 13:56:15 +00:00
|
|
|
* @return If the file exists.
|
2017-05-05 15:07:18 +00:00
|
|
|
* @throws IOException If an error occurs when checking the existence of the file.
|
2017-05-01 14:48:44 +00:00
|
|
|
*/
|
2017-05-06 23:07:42 +00:00
|
|
|
boolean exists( @Nonnull String path ) throws IOException;
|
2017-05-01 13:32:39 +00:00
|
|
|
|
2017-05-01 14:48:44 +00:00
|
|
|
/**
|
|
|
|
* Returns whether a file with a given path is a directory or not.
|
2017-05-05 13:56:15 +00:00
|
|
|
*
|
|
|
|
* @param path A file path in normalised format, relative to the mount location. ie: "programs/myprograms".
|
|
|
|
* @return If the file exists and is a directory
|
2017-05-05 15:07:18 +00:00
|
|
|
* @throws IOException If an error occurs when checking whether the file is a directory.
|
2017-05-01 14:48:44 +00:00
|
|
|
*/
|
2017-05-06 23:07:42 +00:00
|
|
|
boolean isDirectory( @Nonnull String path ) throws IOException;
|
2017-05-01 13:32:39 +00:00
|
|
|
|
2017-05-01 14:48:44 +00:00
|
|
|
/**
|
|
|
|
* Returns the file names of all the files in a directory.
|
2017-05-05 13:56:15 +00:00
|
|
|
*
|
|
|
|
* @param path A file path in normalised format, relative to the mount location. ie: "programs/myprograms".
|
|
|
|
* @param contents A list of strings. Add all the file names to this list.
|
2017-05-05 15:07:18 +00:00
|
|
|
* @throws IOException If the file was not a directory, or could not be listed.
|
2017-05-01 14:48:44 +00:00
|
|
|
*/
|
2017-05-06 23:07:42 +00:00
|
|
|
void list( @Nonnull String path, @Nonnull List<String> contents ) throws IOException;
|
2017-05-01 13:32:39 +00:00
|
|
|
|
2017-05-01 14:48:44 +00:00
|
|
|
/**
|
|
|
|
* Returns the size of a file with a given path, in bytes
|
2017-05-05 13:56:15 +00:00
|
|
|
*
|
|
|
|
* @param path A file path in normalised format, relative to the mount location. ie: "programs/myprogram".
|
|
|
|
* @return The size of the file, in bytes.
|
2017-05-05 15:07:18 +00:00
|
|
|
* @throws IOException If the file does not exist, or its size could not be determined.
|
2017-05-01 14:48:44 +00:00
|
|
|
*/
|
2017-05-06 23:07:42 +00:00
|
|
|
long getSize( @Nonnull String path ) throws IOException;
|
2017-05-05 13:56:15 +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 InputStream} representing its contents.
|
|
|
|
*
|
|
|
|
* @param path A file path in normalised format, relative to the mount location. ie: "programs/myprogram".
|
|
|
|
* @return A stream representing the contents of the file.
|
2017-05-05 15:07:18 +00:00
|
|
|
* @throws IOException If the file does not exist, or could not be opened.
|
2017-05-01 14:48:44 +00:00
|
|
|
*/
|
2017-05-06 23:07:42 +00:00
|
|
|
@Nonnull
|
|
|
|
InputStream openForRead( @Nonnull String path ) throws IOException;
|
2017-05-01 13:32:39 +00:00
|
|
|
}
|