mirror of
https://github.com/SquidDev-CC/CC-Tweaked
synced 2024-12-14 20:20:30 +00:00
Some API cleanup
- Remove *Stream methods on IMount/IWritableMount, and make the channel ones the primary. - Fix location of AbstractTurtleUpgrade - Make IComputerAccess.getAvailablePeripheral and .getMainThreadMonitor mandatory. - IComputerAccess throws a specialised NotAttachedException
This commit is contained in:
parent
fb440b0d2e
commit
044d2b2b06
@ -112,31 +112,6 @@ public final class ComputerCraftAPI
|
||||
return getInstance().createResourceMount( domain, subPath );
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a file system mount to a resource folder, and returns it.
|
||||
*
|
||||
* Use in conjunction with {@link IComputerAccess#mount} or {@link IComputerAccess#mountWritable} to mount a
|
||||
* resource folder onto a computer's file system.
|
||||
*
|
||||
* The files in this mount will be a combination of files in all mod jar, and data packs that contain
|
||||
* resources with the same domain and path.
|
||||
*
|
||||
* @param klass The mod class to which the files belong.
|
||||
* @param domain The domain under which to look for resources. eg: "mymod".
|
||||
* @param subPath The subPath under which to look for resources. eg: "lua/myfiles".
|
||||
* @return The mount, or {@code null} if it could be created for some reason.
|
||||
* @see IComputerAccess#mount(String, IMount)
|
||||
* @see IComputerAccess#mountWritable(String, IWritableMount)
|
||||
* @see IMount
|
||||
* @deprecated Use {@link #createResourceMount(String, String)} instead.
|
||||
*/
|
||||
@Nullable
|
||||
@Deprecated
|
||||
public static IMount createResourceMount( Class<?> klass, @Nonnull String domain, @Nonnull String subPath )
|
||||
{
|
||||
return getInstance().createResourceMount( domain, subPath );
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a peripheral provider to convert blocks into {@link IPeripheral} implementations.
|
||||
*
|
||||
|
@ -11,8 +11,6 @@ import net.minecraft.world.World;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.channels.Channels;
|
||||
import java.nio.channels.ReadableByteChannel;
|
||||
import java.util.List;
|
||||
|
||||
@ -22,10 +20,10 @@ import java.util.List;
|
||||
*
|
||||
* 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!
|
||||
* {@link ComputerCraftAPI#createResourceMount(String, String)}, or you're free to implement it yourselves!
|
||||
*
|
||||
* @see ComputerCraftAPI#createSaveDirMount(World, String, long)
|
||||
* @see ComputerCraftAPI#createResourceMount(Class, String, String)
|
||||
* @see ComputerCraftAPI#createResourceMount(String, String)
|
||||
* @see IComputerAccess#mount(String, IMount)
|
||||
* @see IWritableMount
|
||||
*/
|
||||
@ -67,18 +65,6 @@ public interface IMount
|
||||
*/
|
||||
long getSize( @Nonnull String path ) throws IOException;
|
||||
|
||||
/**
|
||||
* 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.
|
||||
* @throws IOException If the file does not exist, or could not be opened.
|
||||
* @deprecated Use {@link #openChannelForRead(String)} instead
|
||||
*/
|
||||
@Nonnull
|
||||
@Deprecated
|
||||
InputStream openForRead( @Nonnull String path ) throws IOException;
|
||||
|
||||
/**
|
||||
* Opens a file with a given path, and returns an {@link ReadableByteChannel} representing its contents.
|
||||
*
|
||||
@ -89,8 +75,5 @@ public interface IMount
|
||||
* @throws IOException If the file does not exist, or could not be opened.
|
||||
*/
|
||||
@Nonnull
|
||||
default ReadableByteChannel openChannelForRead( @Nonnull String path ) throws IOException
|
||||
{
|
||||
return Channels.newChannel( openForRead( path ) );
|
||||
}
|
||||
ReadableByteChannel openForRead( @Nonnull String path ) throws IOException;
|
||||
}
|
||||
|
@ -12,7 +12,6 @@ import net.minecraft.world.World;
|
||||
import javax.annotation.Nonnull;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.nio.channels.Channels;
|
||||
import java.nio.channels.WritableByteChannel;
|
||||
|
||||
/**
|
||||
@ -45,18 +44,6 @@ public interface IWritableMount extends IMount
|
||||
*/
|
||||
void delete( @Nonnull String path ) throws IOException;
|
||||
|
||||
/**
|
||||
* 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".
|
||||
* @return A stream for writing to
|
||||
* @throws IOException If the file could not be opened for writing.
|
||||
* @deprecated Use {@link #openChannelForWrite(String)} instead.
|
||||
*/
|
||||
@Nonnull
|
||||
@Deprecated
|
||||
OutputStream openForWrite( @Nonnull String path ) throws IOException;
|
||||
|
||||
/**
|
||||
* Opens a file with a given path, and returns an {@link OutputStream} for writing to it.
|
||||
*
|
||||
@ -66,22 +53,7 @@ public interface IWritableMount extends IMount
|
||||
* @throws IOException If the file could not be opened for writing.
|
||||
*/
|
||||
@Nonnull
|
||||
default WritableByteChannel openChannelForWrite( @Nonnull String path ) throws IOException
|
||||
{
|
||||
return Channels.newChannel( openForWrite( path ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
* @throws IOException If the file could not be opened for writing.
|
||||
* @deprecated Use {@link #openChannelForAppend(String)} instead.
|
||||
*/
|
||||
@Nonnull
|
||||
@Deprecated
|
||||
OutputStream openForAppend( @Nonnull String path ) throws IOException;
|
||||
WritableByteChannel openForWrite( @Nonnull String path ) throws IOException;
|
||||
|
||||
/**
|
||||
* Opens a file with a given path, and returns an {@link OutputStream} for appending to it.
|
||||
@ -92,10 +64,7 @@ public interface IWritableMount extends IMount
|
||||
* @throws IOException If the file could not be opened for writing.
|
||||
*/
|
||||
@Nonnull
|
||||
default WritableByteChannel openChannelForAppend( @Nonnull String path ) throws IOException
|
||||
{
|
||||
return Channels.newChannel( openForAppend( path ) );
|
||||
}
|
||||
WritableByteChannel openForAppend( @Nonnull String path ) throws IOException;
|
||||
|
||||
/**
|
||||
* Get the amount of free space on the mount, in bytes. You should decrease this value as the user writes to the
|
||||
|
@ -79,7 +79,7 @@ public interface IMedia
|
||||
* @see IMount
|
||||
* @see dan200.computercraft.api.filesystem.IWritableMount
|
||||
* @see dan200.computercraft.api.ComputerCraftAPI#createSaveDirMount(World, String, long)
|
||||
* @see dan200.computercraft.api.ComputerCraftAPI#createResourceMount(Class, String, String)
|
||||
* @see dan200.computercraft.api.ComputerCraftAPI#createResourceMount(String, String)
|
||||
*/
|
||||
@Nullable
|
||||
default IMount createDataMount( @Nonnull ItemStack stack, @Nonnull World world )
|
||||
|
@ -14,7 +14,6 @@ import net.minecraft.world.World;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
@ -31,9 +30,9 @@ public interface IComputerAccess
|
||||
* @param mount The mount object to mount on the computer.
|
||||
* @return The location on the computer's file system where you the mount mounted, or {@code null} if there was already a
|
||||
* file in the desired location. Store this value if you wish to unmount the mount later.
|
||||
* @throws RuntimeException If the peripheral has been detached.
|
||||
* @throws NotAttachedException If the peripheral has been detached.
|
||||
* @see ComputerCraftAPI#createSaveDirMount(World, String, long)
|
||||
* @see ComputerCraftAPI#createResourceMount(Class, String, String)
|
||||
* @see ComputerCraftAPI#createResourceMount(String, String)
|
||||
* @see #mount(String, IMount, String)
|
||||
* @see #mountWritable(String, IWritableMount)
|
||||
* @see #unmount(String)
|
||||
@ -53,9 +52,9 @@ public interface IComputerAccess
|
||||
* @param driveName A custom name to give for this mount location, as returned by {@code fs.getDrive()}.
|
||||
* @return The location on the computer's file system where you the mount mounted, or {@code null} if there was already a
|
||||
* file in the desired location. Store this value if you wish to unmount the mount later.
|
||||
* @throws RuntimeException If the peripheral has been detached.
|
||||
* @throws NotAttachedException If the peripheral has been detached.
|
||||
* @see ComputerCraftAPI#createSaveDirMount(World, String, long)
|
||||
* @see ComputerCraftAPI#createResourceMount(Class, String, String)
|
||||
* @see ComputerCraftAPI#createResourceMount(String, String)
|
||||
* @see #mount(String, IMount)
|
||||
* @see #mountWritable(String, IWritableMount)
|
||||
* @see #unmount(String)
|
||||
@ -71,9 +70,9 @@ public interface IComputerAccess
|
||||
* @param mount The mount object to mount on the computer.
|
||||
* @return The location on the computer's file system where you the mount mounted, or null if there was already a
|
||||
* file in the desired location. Store this value if you wish to unmount the mount later.
|
||||
* @throws RuntimeException If the peripheral has been detached.
|
||||
* @throws NotAttachedException If the peripheral has been detached.
|
||||
* @see ComputerCraftAPI#createSaveDirMount(World, String, long)
|
||||
* @see ComputerCraftAPI#createResourceMount(Class, String, String)
|
||||
* @see ComputerCraftAPI#createResourceMount(String, String)
|
||||
* @see #mount(String, IMount)
|
||||
* @see #unmount(String)
|
||||
* @see IMount
|
||||
@ -92,9 +91,9 @@ public interface IComputerAccess
|
||||
* @param driveName A custom name to give for this mount location, as returned by {@code fs.getDrive()}.
|
||||
* @return The location on the computer's file system where you the mount mounted, or null if there was already a
|
||||
* file in the desired location. Store this value if you wish to unmount the mount later.
|
||||
* @throws RuntimeException If the peripheral has been detached.
|
||||
* @throws NotAttachedException If the peripheral has been detached.
|
||||
* @see ComputerCraftAPI#createSaveDirMount(World, String, long)
|
||||
* @see ComputerCraftAPI#createResourceMount(Class, String, String)
|
||||
* @see ComputerCraftAPI#createResourceMount(String, String)
|
||||
* @see #mount(String, IMount)
|
||||
* @see #unmount(String)
|
||||
* @see IMount
|
||||
@ -114,8 +113,8 @@ public interface IComputerAccess
|
||||
* @param location The desired location in the computers file system of the directory to unmount.
|
||||
* This must be the location of a directory previously mounted by {@link #mount(String, IMount)} or
|
||||
* {@link #mountWritable(String, IWritableMount)}, as indicated by their return value.
|
||||
* @throws RuntimeException If the peripheral has been detached.
|
||||
* @throws RuntimeException If the mount does not exist, or was mounted by another peripheral.
|
||||
* @throws NotAttachedException If the peripheral has been detached.
|
||||
* @throws IllegalStateException If the mount does not exist, or was mounted by another peripheral.
|
||||
* @see #mount(String, IMount)
|
||||
* @see #mountWritable(String, IWritableMount)
|
||||
*/
|
||||
@ -146,7 +145,7 @@ public interface IComputerAccess
|
||||
* to lua data types in the same fashion as the return values of IPeripheral.callMethod().
|
||||
*
|
||||
* You may supply {@code null} to indicate that no arguments are to be supplied.
|
||||
* @throws RuntimeException If the peripheral has been detached.
|
||||
* @throws NotAttachedException If the peripheral has been detached.
|
||||
* @see IPeripheral#callMethod
|
||||
*/
|
||||
void queueEvent( @Nonnull String event, @Nullable Object[] arguments );
|
||||
@ -159,7 +158,7 @@ public interface IComputerAccess
|
||||
* which peripheral the event came.
|
||||
*
|
||||
* @return A string unique to the computer, but not globally.
|
||||
* @throws RuntimeException If the peripheral has been detached.
|
||||
* @throws NotAttachedException If the peripheral has been detached.
|
||||
*/
|
||||
@Nonnull
|
||||
String getAttachmentName();
|
||||
@ -170,14 +169,12 @@ public interface IComputerAccess
|
||||
* This may include other peripherals on the wired network or peripherals on other sides of the computer.
|
||||
*
|
||||
* @return All reachable peripherals
|
||||
* @throws NotAttachedException If the peripheral has been detached.
|
||||
* @see #getAttachmentName()
|
||||
* @see #getAvailablePeripheral(String)
|
||||
*/
|
||||
@Nonnull
|
||||
default Map<String, IPeripheral> getAvailablePeripherals()
|
||||
{
|
||||
return Collections.emptyMap();
|
||||
}
|
||||
Map<String, IPeripheral> getAvailablePeripherals();
|
||||
|
||||
/**
|
||||
* Get a reachable peripheral with the given attachment name. This is a equivalent to
|
||||
@ -188,10 +185,7 @@ public interface IComputerAccess
|
||||
* @see #getAvailablePeripherals()
|
||||
*/
|
||||
@Nullable
|
||||
default IPeripheral getAvailablePeripheral( @Nonnull String name )
|
||||
{
|
||||
return null;
|
||||
}
|
||||
IPeripheral getAvailablePeripheral( @Nonnull String name );
|
||||
|
||||
/**
|
||||
* Get a {@link IWorkMonitor} for tasks your peripheral might execute on the main (server) thread.
|
||||
@ -205,10 +199,8 @@ public interface IComputerAccess
|
||||
* thread.
|
||||
*
|
||||
* @return The work monitor for the main thread, or {@code null} if this computer does not have one.
|
||||
* @throws NotAttachedException If the peripheral has been detached.
|
||||
*/
|
||||
@Nullable
|
||||
default IWorkMonitor getMainThreadMonitor()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
@Nonnull
|
||||
IWorkMonitor getMainThreadMonitor();
|
||||
}
|
||||
|
@ -0,0 +1,25 @@
|
||||
/*
|
||||
* This file is part of the public ComputerCraft API - http://www.computercraft.info
|
||||
* Copyright Daniel Ratcliffe, 2011-2020. 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.peripheral;
|
||||
|
||||
/**
|
||||
* Thrown when performing operations on {@link IComputerAccess} when the current peripheral is no longer attached to
|
||||
* the computer.
|
||||
*/
|
||||
public class NotAttachedException extends IllegalStateException
|
||||
{
|
||||
private static final long serialVersionUID = 1221244785535553536L;
|
||||
|
||||
public NotAttachedException()
|
||||
{
|
||||
super( "You are not attached to this Computer" );
|
||||
}
|
||||
|
||||
public NotAttachedException( String s )
|
||||
{
|
||||
super( s );
|
||||
}
|
||||
}
|
@ -3,10 +3,8 @@
|
||||
* Copyright Daniel Ratcliffe, 2011-2020. 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;
|
||||
package dan200.computercraft.api.turtle;
|
||||
|
||||
import dan200.computercraft.api.turtle.ITurtleUpgrade;
|
||||
import dan200.computercraft.api.turtle.TurtleUpgradeType;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.IItemProvider;
|
||||
import net.minecraft.util.ResourceLocation;
|
@ -13,7 +13,6 @@ import dan200.computercraft.core.filesystem.FileSystem;
|
||||
import dan200.computercraft.core.filesystem.FileSystemException;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.HashSet;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
@ -123,7 +122,7 @@ public abstract class ComputerAccess implements IComputerAccess
|
||||
m_environment.queueEvent( event, arguments );
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Nonnull
|
||||
@Override
|
||||
public IWorkMonitor getMainThreadMonitor()
|
||||
{
|
||||
|
@ -11,6 +11,8 @@ import dan200.computercraft.api.lua.ILuaAPI;
|
||||
import dan200.computercraft.api.lua.ILuaContext;
|
||||
import dan200.computercraft.api.lua.LuaException;
|
||||
import dan200.computercraft.api.peripheral.IPeripheral;
|
||||
import dan200.computercraft.api.peripheral.IWorkMonitor;
|
||||
import dan200.computercraft.api.peripheral.NotAttachedException;
|
||||
import dan200.computercraft.core.computer.ComputerSide;
|
||||
import dan200.computercraft.core.tracking.TrackingField;
|
||||
|
||||
@ -122,53 +124,35 @@ public class PeripheralAPI implements ILuaAPI, IAPIEnvironment.IPeripheralChange
|
||||
@Override
|
||||
public synchronized String mount( @Nonnull String desiredLoc, @Nonnull IMount mount, @Nonnull String driveName )
|
||||
{
|
||||
if( !m_attached )
|
||||
{
|
||||
throw new RuntimeException( "You are not attached to this Computer" );
|
||||
}
|
||||
|
||||
if( !m_attached ) throw new NotAttachedException();
|
||||
return super.mount( desiredLoc, mount, driveName );
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized String mountWritable( @Nonnull String desiredLoc, @Nonnull IWritableMount mount, @Nonnull String driveName )
|
||||
{
|
||||
if( !m_attached )
|
||||
{
|
||||
throw new RuntimeException( "You are not attached to this Computer" );
|
||||
}
|
||||
|
||||
if( !m_attached ) throw new NotAttachedException();
|
||||
return super.mountWritable( desiredLoc, mount, driveName );
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void unmount( String location )
|
||||
{
|
||||
if( !m_attached )
|
||||
{
|
||||
throw new RuntimeException( "You are not attached to this Computer" );
|
||||
}
|
||||
|
||||
if( !m_attached ) throw new NotAttachedException();
|
||||
super.unmount( location );
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getID()
|
||||
{
|
||||
if( !m_attached )
|
||||
{
|
||||
throw new RuntimeException( "You are not attached to this Computer" );
|
||||
}
|
||||
if( !m_attached ) throw new NotAttachedException();
|
||||
return super.getID();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void queueEvent( @Nonnull final String event, final Object[] arguments )
|
||||
{
|
||||
if( !m_attached )
|
||||
{
|
||||
throw new RuntimeException( "You are not attached to this Computer" );
|
||||
}
|
||||
if( !m_attached ) throw new NotAttachedException();
|
||||
super.queueEvent( event, arguments );
|
||||
}
|
||||
|
||||
@ -176,10 +160,7 @@ public class PeripheralAPI implements ILuaAPI, IAPIEnvironment.IPeripheralChange
|
||||
@Override
|
||||
public String getAttachmentName()
|
||||
{
|
||||
if( !m_attached )
|
||||
{
|
||||
throw new RuntimeException( "You are not attached to this Computer" );
|
||||
}
|
||||
if( !m_attached ) throw new NotAttachedException();
|
||||
return m_side;
|
||||
}
|
||||
|
||||
@ -187,10 +168,7 @@ public class PeripheralAPI implements ILuaAPI, IAPIEnvironment.IPeripheralChange
|
||||
@Override
|
||||
public Map<String, IPeripheral> getAvailablePeripherals()
|
||||
{
|
||||
if( !m_attached )
|
||||
{
|
||||
throw new RuntimeException( "You are not attached to this Computer" );
|
||||
}
|
||||
if( !m_attached ) throw new NotAttachedException();
|
||||
|
||||
Map<String, IPeripheral> peripherals = new HashMap<>();
|
||||
for( PeripheralWrapper wrapper : m_peripherals )
|
||||
@ -208,10 +186,7 @@ public class PeripheralAPI implements ILuaAPI, IAPIEnvironment.IPeripheralChange
|
||||
@Override
|
||||
public IPeripheral getAvailablePeripheral( @Nonnull String name )
|
||||
{
|
||||
if( !m_attached )
|
||||
{
|
||||
throw new RuntimeException( "You are not attached to this Computer" );
|
||||
}
|
||||
if( !m_attached ) throw new NotAttachedException();
|
||||
|
||||
for( PeripheralWrapper wrapper : m_peripherals )
|
||||
{
|
||||
@ -222,6 +197,14 @@ public class PeripheralAPI implements ILuaAPI, IAPIEnvironment.IPeripheralChange
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public IWorkMonitor getMainThreadMonitor()
|
||||
{
|
||||
if( !m_attached ) throw new NotAttachedException();
|
||||
return super.getMainThreadMonitor();
|
||||
}
|
||||
}
|
||||
|
||||
private final IAPIEnvironment m_environment;
|
||||
|
@ -9,12 +9,15 @@ import dan200.computercraft.api.filesystem.IFileSystem;
|
||||
import dan200.computercraft.api.lua.IComputerSystem;
|
||||
import dan200.computercraft.api.lua.ILuaAPIFactory;
|
||||
import dan200.computercraft.api.peripheral.IComputerAccess;
|
||||
import dan200.computercraft.api.peripheral.IPeripheral;
|
||||
import dan200.computercraft.core.apis.ComputerAccess;
|
||||
import dan200.computercraft.core.apis.IAPIEnvironment;
|
||||
import dan200.computercraft.core.filesystem.FileSystem;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Implementation of {@link IComputerAccess}/{@link IComputerSystem} for usage by externally registered APIs.
|
||||
@ -54,4 +57,19 @@ public class ComputerSystem extends ComputerAccess implements IComputerSystem
|
||||
{
|
||||
return environment.getLabel();
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public Map<String, IPeripheral> getAvailablePeripherals()
|
||||
{
|
||||
// TODO: Should this return peripherals on the current computer?
|
||||
return Collections.emptyMap();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public IPeripheral getAvailablePeripheral( @Nonnull String name )
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@ -10,7 +10,6 @@ import dan200.computercraft.api.filesystem.IMount;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.channels.ReadableByteChannel;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
@ -115,8 +114,7 @@ public class ComboMount implements IMount
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
@Deprecated
|
||||
public InputStream openForRead( @Nonnull String path ) throws IOException
|
||||
public ReadableByteChannel openForRead( @Nonnull String path ) throws IOException
|
||||
{
|
||||
for( int i = m_parts.length - 1; i >= 0; --i )
|
||||
{
|
||||
@ -128,19 +126,4 @@ public class ComboMount implements IMount
|
||||
}
|
||||
throw new FileOperationException( path, "No such file" );
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public ReadableByteChannel openChannelForRead( @Nonnull String path ) throws IOException
|
||||
{
|
||||
for( int i = m_parts.length - 1; i >= 0; --i )
|
||||
{
|
||||
IMount part = m_parts[i];
|
||||
if( part.exists( path ) && !part.isDirectory( path ) )
|
||||
{
|
||||
return part.openChannelForRead( path );
|
||||
}
|
||||
}
|
||||
throw new FileOperationException( path, "No such file" );
|
||||
}
|
||||
}
|
||||
|
@ -10,7 +10,6 @@ import dan200.computercraft.api.filesystem.IMount;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.channels.ReadableByteChannel;
|
||||
import java.util.List;
|
||||
|
||||
@ -42,15 +41,7 @@ public class EmptyMount implements IMount
|
||||
@Nonnull
|
||||
@Override
|
||||
@Deprecated
|
||||
public InputStream openForRead( @Nonnull String path ) throws IOException
|
||||
{
|
||||
throw new FileOperationException( path, "No such file" );
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
@Deprecated
|
||||
public ReadableByteChannel openChannelForRead( @Nonnull String path ) throws IOException
|
||||
public ReadableByteChannel openForRead( @Nonnull String path ) throws IOException
|
||||
{
|
||||
throw new FileOperationException( path, "No such file" );
|
||||
}
|
||||
|
@ -10,7 +10,8 @@ import dan200.computercraft.api.filesystem.FileOperationException;
|
||||
import dan200.computercraft.api.filesystem.IWritableMount;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.io.*;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.channels.*;
|
||||
import java.nio.file.Files;
|
||||
@ -199,21 +200,7 @@ public class FileMount implements IWritableMount
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
@Deprecated
|
||||
public InputStream openForRead( @Nonnull String path ) throws IOException
|
||||
{
|
||||
if( created() )
|
||||
{
|
||||
File file = getRealPath( path );
|
||||
if( file.exists() && !file.isDirectory() ) return new FileInputStream( file );
|
||||
}
|
||||
|
||||
throw new FileOperationException( path, "No such file" );
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public ReadableByteChannel openChannelForRead( @Nonnull String path ) throws IOException
|
||||
public ReadableByteChannel openForRead( @Nonnull String path ) throws IOException
|
||||
{
|
||||
if( created() )
|
||||
{
|
||||
@ -299,23 +286,7 @@ public class FileMount implements IWritableMount
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
@Deprecated
|
||||
public OutputStream openForWrite( @Nonnull String path ) throws IOException
|
||||
{
|
||||
return Channels.newOutputStream( openChannelForWrite( path ) );
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
@Deprecated
|
||||
public OutputStream openForAppend( @Nonnull String path ) throws IOException
|
||||
{
|
||||
return Channels.newOutputStream( openChannelForAppend( path ) );
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public WritableByteChannel openChannelForWrite( @Nonnull String path ) throws IOException
|
||||
public WritableByteChannel openForWrite( @Nonnull String path ) throws IOException
|
||||
{
|
||||
create();
|
||||
File file = getRealPath( path );
|
||||
@ -336,7 +307,7 @@ public class FileMount implements IWritableMount
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public WritableByteChannel openChannelForAppend( @Nonnull String path ) throws IOException
|
||||
public WritableByteChannel openForAppend( @Nonnull String path ) throws IOException
|
||||
{
|
||||
if( !created() )
|
||||
{
|
||||
|
@ -165,7 +165,7 @@ public class FileSystem
|
||||
{
|
||||
if( m_mount.exists( path ) && !m_mount.isDirectory( path ) )
|
||||
{
|
||||
return m_mount.openChannelForRead( path );
|
||||
return m_mount.openForRead( path );
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -245,7 +245,7 @@ public class FileSystem
|
||||
m_writableMount.makeDirectory( dir );
|
||||
}
|
||||
}
|
||||
return m_writableMount.openChannelForWrite( path );
|
||||
return m_writableMount.openForWrite( path );
|
||||
}
|
||||
}
|
||||
catch( AccessDeniedException e )
|
||||
@ -275,7 +275,7 @@ public class FileSystem
|
||||
m_writableMount.makeDirectory( dir );
|
||||
}
|
||||
}
|
||||
return m_writableMount.openChannelForWrite( path );
|
||||
return m_writableMount.openForWrite( path );
|
||||
}
|
||||
else if( m_mount.isDirectory( path ) )
|
||||
{
|
||||
@ -283,7 +283,7 @@ public class FileSystem
|
||||
}
|
||||
else
|
||||
{
|
||||
return m_writableMount.openChannelForAppend( path );
|
||||
return m_writableMount.openForAppend( path );
|
||||
}
|
||||
}
|
||||
catch( AccessDeniedException e )
|
||||
|
@ -9,9 +9,6 @@ import dan200.computercraft.api.filesystem.IFileSystem;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.nio.channels.Channels;
|
||||
import java.nio.channels.ReadableByteChannel;
|
||||
import java.nio.channels.WritableByteChannel;
|
||||
import java.util.Collections;
|
||||
@ -55,7 +52,7 @@ public class FileSystemWrapperMount implements IFileSystem
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public ReadableByteChannel openChannelForRead( @Nonnull String path ) throws IOException
|
||||
public ReadableByteChannel openForRead( @Nonnull String path ) throws IOException
|
||||
{
|
||||
try
|
||||
{
|
||||
@ -70,7 +67,7 @@ public class FileSystemWrapperMount implements IFileSystem
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public WritableByteChannel openChannelForWrite( @Nonnull String path ) throws IOException
|
||||
public WritableByteChannel openForWrite( @Nonnull String path ) throws IOException
|
||||
{
|
||||
try
|
||||
{
|
||||
@ -84,7 +81,7 @@ public class FileSystemWrapperMount implements IFileSystem
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public WritableByteChannel openChannelForAppend( @Nonnull String path ) throws IOException
|
||||
public WritableByteChannel openForAppend( @Nonnull String path ) throws IOException
|
||||
{
|
||||
try
|
||||
{
|
||||
@ -96,30 +93,6 @@ public class FileSystemWrapperMount implements IFileSystem
|
||||
}
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
@Deprecated
|
||||
public InputStream openForRead( @Nonnull String path ) throws IOException
|
||||
{
|
||||
return Channels.newInputStream( openChannelForRead( path ) );
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
@Deprecated
|
||||
public OutputStream openForWrite( @Nonnull String path ) throws IOException
|
||||
{
|
||||
return Channels.newOutputStream( openChannelForWrite( path ) );
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
@Deprecated
|
||||
public OutputStream openForAppend( @Nonnull String path ) throws IOException
|
||||
{
|
||||
return Channels.newOutputStream( openChannelForAppend( path ) );
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getRemainingSpace() throws IOException
|
||||
{
|
||||
|
@ -181,15 +181,7 @@ public class JarMount implements IMount
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
@Deprecated
|
||||
public InputStream openForRead( @Nonnull String path ) throws IOException
|
||||
{
|
||||
return Channels.newInputStream( openChannelForRead( path ) );
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public ReadableByteChannel openChannelForRead( @Nonnull String path ) throws IOException
|
||||
public ReadableByteChannel openForRead( @Nonnull String path ) throws IOException
|
||||
{
|
||||
FileEntry file = get( path );
|
||||
if( file != null && !file.isDirectory() )
|
||||
|
@ -223,15 +223,7 @@ public final class ResourceMount implements IMount
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
@Deprecated
|
||||
public InputStream openForRead( @Nonnull String path ) throws IOException
|
||||
{
|
||||
return Channels.newInputStream( openChannelForRead( path ) );
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public ReadableByteChannel openChannelForRead( @Nonnull String path ) throws IOException
|
||||
public ReadableByteChannel openForRead( @Nonnull String path ) throws IOException
|
||||
{
|
||||
FileEntry file = get( path );
|
||||
if( file != null && !file.isDirectory() )
|
||||
|
@ -9,7 +9,6 @@ import dan200.computercraft.api.filesystem.IMount;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.channels.ReadableByteChannel;
|
||||
import java.util.List;
|
||||
|
||||
@ -52,19 +51,11 @@ public class SubMount implements IMount
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
@Deprecated
|
||||
public InputStream openForRead( @Nonnull String path ) throws IOException
|
||||
public ReadableByteChannel openForRead( @Nonnull String path ) throws IOException
|
||||
{
|
||||
return m_parent.openForRead( getFullPath( path ) );
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public ReadableByteChannel openChannelForRead( @Nonnull String path ) throws IOException
|
||||
{
|
||||
return m_parent.openChannelForRead( getFullPath( path ) );
|
||||
}
|
||||
|
||||
private String getFullPath( String path )
|
||||
{
|
||||
if( path.isEmpty() )
|
||||
|
@ -374,7 +374,7 @@ public abstract class WiredModemPeripheral extends ModemPeripheral implements IW
|
||||
m_computer.queueEvent( event, arguments );
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Nonnull
|
||||
@Override
|
||||
public IWorkMonitor getMainThreadMonitor()
|
||||
{
|
||||
|
@ -5,9 +5,9 @@
|
||||
*/
|
||||
package dan200.computercraft.shared.turtle.upgrades;
|
||||
|
||||
import dan200.computercraft.api.AbstractTurtleUpgrade;
|
||||
import dan200.computercraft.api.client.TransformedModel;
|
||||
import dan200.computercraft.api.peripheral.IPeripheral;
|
||||
import dan200.computercraft.api.turtle.AbstractTurtleUpgrade;
|
||||
import dan200.computercraft.api.turtle.ITurtleAccess;
|
||||
import dan200.computercraft.api.turtle.TurtleSide;
|
||||
import dan200.computercraft.api.turtle.TurtleUpgradeType;
|
||||
|
@ -6,7 +6,6 @@
|
||||
package dan200.computercraft.shared.turtle.upgrades;
|
||||
|
||||
import dan200.computercraft.ComputerCraft;
|
||||
import dan200.computercraft.api.AbstractTurtleUpgrade;
|
||||
import dan200.computercraft.api.client.TransformedModel;
|
||||
import dan200.computercraft.api.peripheral.IPeripheral;
|
||||
import dan200.computercraft.api.turtle.*;
|
||||
|
@ -7,9 +7,9 @@
|
||||
package dan200.computercraft.shared.turtle.upgrades;
|
||||
|
||||
import dan200.computercraft.ComputerCraft;
|
||||
import dan200.computercraft.api.AbstractTurtleUpgrade;
|
||||
import dan200.computercraft.api.client.TransformedModel;
|
||||
import dan200.computercraft.api.peripheral.IPeripheral;
|
||||
import dan200.computercraft.api.turtle.AbstractTurtleUpgrade;
|
||||
import dan200.computercraft.api.turtle.ITurtleAccess;
|
||||
import dan200.computercraft.api.turtle.TurtleSide;
|
||||
import dan200.computercraft.api.turtle.TurtleUpgradeType;
|
||||
|
@ -6,7 +6,6 @@
|
||||
package dan200.computercraft.shared.turtle.upgrades;
|
||||
|
||||
import dan200.computercraft.ComputerCraft;
|
||||
import dan200.computercraft.api.AbstractTurtleUpgrade;
|
||||
import dan200.computercraft.api.client.TransformedModel;
|
||||
import dan200.computercraft.api.turtle.*;
|
||||
import dan200.computercraft.api.turtle.event.TurtleAttackEvent;
|
||||
|
@ -86,7 +86,7 @@ public class ComputerTestDelegate
|
||||
for( String child : children ) mount.delete( child );
|
||||
|
||||
// And add our startup file
|
||||
try( WritableByteChannel channel = mount.openChannelForWrite( "startup.lua" );
|
||||
try( WritableByteChannel channel = mount.openForWrite( "startup.lua" );
|
||||
Writer writer = Channels.newWriter( channel, StandardCharsets.UTF_8.newEncoder(), -1 ) )
|
||||
{
|
||||
writer.write( "loadfile('test/mcfly.lua', nil, _ENV)('test/spec') cct_test.finish()" );
|
||||
|
@ -13,14 +13,14 @@ import org.junit.jupiter.api.Test;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.channels.Channels;
|
||||
import java.nio.channels.ReadableByteChannel;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipOutputStream;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
@SuppressWarnings( "deprecation" )
|
||||
public class JarMountTest
|
||||
{
|
||||
private static final File ZIP_FILE = new File( "test-files/jar-mount.zip" );
|
||||
@ -63,9 +63,9 @@ public class JarMountTest
|
||||
{
|
||||
IMount mount = new JarMount( ZIP_FILE, "dir/file.lua" );
|
||||
byte[] contents;
|
||||
try( InputStream stream = mount.openForRead( "" ) )
|
||||
try( ReadableByteChannel stream = mount.openForRead( "" ) )
|
||||
{
|
||||
contents = ByteStreams.toByteArray( stream );
|
||||
contents = ByteStreams.toByteArray( Channels.newInputStream( stream ) );
|
||||
}
|
||||
|
||||
assertEquals( new String( contents, StandardCharsets.UTF_8 ), "print('testing')" );
|
||||
@ -76,9 +76,9 @@ public class JarMountTest
|
||||
{
|
||||
IMount mount = new JarMount( ZIP_FILE, "dir" );
|
||||
byte[] contents;
|
||||
try( InputStream stream = mount.openForRead( "file.lua" ) )
|
||||
try( ReadableByteChannel stream = mount.openForRead( "file.lua" ) )
|
||||
{
|
||||
contents = ByteStreams.toByteArray( stream );
|
||||
contents = ByteStreams.toByteArray( Channels.newInputStream( stream ) );
|
||||
}
|
||||
|
||||
assertEquals( new String( contents, StandardCharsets.UTF_8 ), "print('testing')" );
|
||||
|
@ -6,9 +6,15 @@
|
||||
package dan200.computercraft.core.filesystem;
|
||||
|
||||
import dan200.computercraft.api.filesystem.IWritableMount;
|
||||
import dan200.computercraft.core.apis.handles.ArrayByteChannel;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.io.*;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.channels.Channels;
|
||||
import java.nio.channels.ReadableByteChannel;
|
||||
import java.nio.channels.WritableByteChannel;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
@ -61,10 +67,9 @@ public class MemoryMount implements IWritableMount
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
@Deprecated
|
||||
public OutputStream openForWrite( @Nonnull final String path )
|
||||
public WritableByteChannel openForWrite( @Nonnull final String path )
|
||||
{
|
||||
return new ByteArrayOutputStream()
|
||||
return Channels.newChannel( new ByteArrayOutputStream()
|
||||
{
|
||||
@Override
|
||||
public void close() throws IOException
|
||||
@ -72,13 +77,12 @@ public class MemoryMount implements IWritableMount
|
||||
super.close();
|
||||
files.put( path, toByteArray() );
|
||||
}
|
||||
};
|
||||
} );
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
@Deprecated
|
||||
public OutputStream openForAppend( @Nonnull final String path ) throws IOException
|
||||
public WritableByteChannel openForAppend( @Nonnull final String path ) throws IOException
|
||||
{
|
||||
ByteArrayOutputStream stream = new ByteArrayOutputStream()
|
||||
{
|
||||
@ -93,7 +97,7 @@ public class MemoryMount implements IWritableMount
|
||||
byte[] current = files.get( path );
|
||||
if( current != null ) stream.write( current );
|
||||
|
||||
return stream;
|
||||
return Channels.newChannel( stream );
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -131,10 +135,9 @@ public class MemoryMount implements IWritableMount
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
@Deprecated
|
||||
public InputStream openForRead( @Nonnull String path )
|
||||
public ReadableByteChannel openForRead( @Nonnull String path )
|
||||
{
|
||||
return new ByteArrayInputStream( files.get( path ) );
|
||||
return new ArrayByteChannel( files.get( path ) );
|
||||
}
|
||||
|
||||
public MemoryMount addFile( String file, String contents )
|
||||
|
Loading…
Reference in New Issue
Block a user