mirror of
				https://github.com/SquidDev-CC/CC-Tweaked
				synced 2025-10-31 13:42:59 +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:
		| @@ -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 ) | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 SquidDev
					SquidDev