diff --git a/src/main/java/dan200/computercraft/ComputerCraft.java b/src/main/java/dan200/computercraft/ComputerCraft.java index 741403964c..77c344db0d 100644 --- a/src/main/java/dan200/computercraft/ComputerCraft.java +++ b/src/main/java/dan200/computercraft/ComputerCraft.java @@ -928,7 +928,7 @@ public static IMount createResourceMount( Class modClass, String domain, Stri FileSystem fs = FileSystems.newFileSystem( modJar.toPath(), ComputerCraft.class.getClassLoader() ); mounts.add( new FileSystemMount( fs, subPath ) ); } - catch( IOException | ProviderNotFoundException | ServiceConfigurationError e ) + catch( IOException | RuntimeException | ServiceConfigurationError e ) { ComputerCraft.log.error( "Could not load mount from mod jar", e ); // Ignore @@ -940,16 +940,16 @@ public static IMount createResourceMount( Class modClass, String domain, Stri if( resourcePackDir.exists() && resourcePackDir.isDirectory() ) { String[] resourcePacks = resourcePackDir.list(); - for( String resourcePack1 : resourcePacks ) + for( String resourcePackName : resourcePacks ) { try { - File resourcePack = new File( resourcePackDir, resourcePack1 ); + File resourcePack = new File( resourcePackDir, resourcePackName ); if( !resourcePack.isDirectory() ) { // Mount a resource pack from a jar - IMount resourcePackMount = new FileSystemMount( FileSystems.getFileSystem( resourcePack.toURI() ), subPath ); - mounts.add( resourcePackMount ); + FileSystem fs = FileSystems.newFileSystem( resourcePack.toPath(), ComputerCraft.class.getClassLoader() ); + mounts.add( new FileSystemMount( fs, subPath ) ); } else { @@ -962,9 +962,9 @@ public static IMount createResourceMount( Class modClass, String domain, Stri } } } - catch( IOException e ) + catch( IOException | RuntimeException | ServiceConfigurationError e ) { - ComputerCraft.log.error( "Could not load resource pack '" + resourcePack1 + "'", e ); + ComputerCraft.log.error( "Could not load resource pack '" + resourcePackName + "'", e ); } } } diff --git a/src/main/java/dan200/computercraft/core/apis/handles/BinaryReadableHandle.java b/src/main/java/dan200/computercraft/core/apis/handles/BinaryReadableHandle.java index d9078ab000..33d57a42b8 100644 --- a/src/main/java/dan200/computercraft/core/apis/handles/BinaryReadableHandle.java +++ b/src/main/java/dan200/computercraft/core/apis/handles/BinaryReadableHandle.java @@ -33,7 +33,7 @@ public BinaryReadableHandle( ReadableByteChannel channel, Closeable closeable ) { super( closeable ); this.m_reader = channel; - this.m_seekable = channel instanceof SeekableByteChannel ? (SeekableByteChannel) channel : null; + this.m_seekable = asSeekable( channel ); } public BinaryReadableHandle( ReadableByteChannel channel ) diff --git a/src/main/java/dan200/computercraft/core/apis/handles/BinaryWritableHandle.java b/src/main/java/dan200/computercraft/core/apis/handles/BinaryWritableHandle.java index b377c4a104..8502245082 100644 --- a/src/main/java/dan200/computercraft/core/apis/handles/BinaryWritableHandle.java +++ b/src/main/java/dan200/computercraft/core/apis/handles/BinaryWritableHandle.java @@ -27,7 +27,7 @@ public BinaryWritableHandle( WritableByteChannel channel, Closeable closeable ) { super( closeable ); this.m_writer = channel; - this.m_seekable = channel instanceof SeekableByteChannel ? (SeekableByteChannel) channel : null; + this.m_seekable = asSeekable( channel ); } public BinaryWritableHandle( WritableByteChannel channel ) diff --git a/src/main/java/dan200/computercraft/core/apis/handles/HandleGeneric.java b/src/main/java/dan200/computercraft/core/apis/handles/HandleGeneric.java index 44d14505b7..19b70f4c29 100644 --- a/src/main/java/dan200/computercraft/core/apis/handles/HandleGeneric.java +++ b/src/main/java/dan200/computercraft/core/apis/handles/HandleGeneric.java @@ -6,6 +6,7 @@ import javax.annotation.Nonnull; import java.io.Closeable; import java.io.IOException; +import java.nio.channels.Channel; import java.nio.channels.SeekableByteChannel; import static dan200.computercraft.core.apis.ArgumentHelper.optInt; @@ -69,15 +70,31 @@ protected static Object[] handleSeek( SeekableByteChannel channel, Object[] args throw new LuaException( "bad argument #1 to 'seek' (invalid option '" + whence + "'" ); } - return new Object[] { channel.position() }; + return new Object[]{ channel.position() }; } catch( IllegalArgumentException e ) { - return new Object[] { false, "Position is negative" }; + return new Object[]{ false, "Position is negative" }; } catch( IOException e ) { return null; } } + + protected static SeekableByteChannel asSeekable( Channel channel ) + { + if( !(channel instanceof SeekableByteChannel) ) return null; + + SeekableByteChannel seekable = (SeekableByteChannel) channel; + try + { + seekable.position( seekable.position() ); + return seekable; + } + catch( IOException | UnsupportedOperationException e ) + { + return null; + } + } }