1
0
mirror of https://github.com/SquidDev-CC/CC-Tweaked synced 2025-08-29 00:32:18 +00:00

Couple of minor improvements to the alternative mount implementation

- Rename openStreamFor* methods to more accurate openChannelFor*
 - Fix ArrayByteChannel having an incorrect .position() implementation

Cherry-picked from the PR against dan200/ComputerCraft
This commit is contained in:
SquidDev 2018-10-24 12:32:37 +01:00
parent e555f9f7f0
commit 8080699030
5 changed files with 22 additions and 22 deletions

View File

@ -52,7 +52,7 @@ public interface IWritableMount extends IMount
* @param path A file path in normalised format, relative to the mount location. ie: "programs/myprogram". * @param path A file path in normalised format, relative to the mount location. ie: "programs/myprogram".
* @return A stream for writing to * @return A stream for writing to
* @throws IOException If the file could not be opened for writing. * @throws IOException If the file could not be opened for writing.
* @deprecated Use {@link #openStreamForWrite(String)} instead. * @deprecated Use {@link #openChannelForWrite(String)} instead.
*/ */
@Nonnull @Nonnull
@Deprecated @Deprecated
@ -68,7 +68,7 @@ public interface IWritableMount extends IMount
*/ */
@Nonnull @Nonnull
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
default WritableByteChannel openStreamForWrite( @Nonnull String path ) throws IOException default WritableByteChannel openChannelForWrite( @Nonnull String path ) throws IOException
{ {
return Channels.newChannel( openForWrite( path ) ); return Channels.newChannel( openForWrite( path ) );
} }
@ -79,7 +79,7 @@ public interface IWritableMount extends IMount
* @param path A file path in normalised format, relative to the mount location. ie: "programs/myprogram". * @param path A file path in normalised format, relative to the mount location. ie: "programs/myprogram".
* @return A stream for writing to. * @return A stream for writing to.
* @throws IOException If the file could not be opened for writing. * @throws IOException If the file could not be opened for writing.
* @deprecated Use {@link #openStreamForAppend(String)} instead. * @deprecated Use {@link #openChannelForAppend(String)} instead.
*/ */
@Nonnull @Nonnull
@Deprecated @Deprecated
@ -95,7 +95,7 @@ public interface IWritableMount extends IMount
*/ */
@Nonnull @Nonnull
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
default WritableByteChannel openStreamForAppend( @Nonnull String path ) throws IOException default WritableByteChannel openChannelForAppend( @Nonnull String path ) throws IOException
{ {
return Channels.newChannel( openForAppend( path ) ); return Channels.newChannel( openForAppend( path ) );
} }

View File

@ -48,7 +48,7 @@ public class ArrayByteChannel implements SeekableByteChannel
public long position() throws IOException public long position() throws IOException
{ {
if( closed ) throw new ClosedChannelException(); if( closed ) throw new ClosedChannelException();
return 0; return position;
} }
@Override @Override

View File

@ -347,7 +347,7 @@ public class FileMount implements IWritableMount
@Deprecated @Deprecated
public OutputStream openForWrite( @Nonnull String path ) throws IOException public OutputStream openForWrite( @Nonnull String path ) throws IOException
{ {
return Channels.newOutputStream( openStreamForWrite( path ) ); return Channels.newOutputStream( openChannelForWrite( path ) );
} }
@Nonnull @Nonnull
@ -355,12 +355,12 @@ public class FileMount implements IWritableMount
@Deprecated @Deprecated
public OutputStream openForAppend( @Nonnull String path ) throws IOException public OutputStream openForAppend( @Nonnull String path ) throws IOException
{ {
return Channels.newOutputStream( openStreamForAppend( path ) ); return Channels.newOutputStream( openChannelForAppend( path ) );
} }
@Nonnull @Nonnull
@Override @Override
public WritableByteChannel openStreamForWrite( @Nonnull String path ) throws IOException public WritableByteChannel openChannelForWrite( @Nonnull String path ) throws IOException
{ {
create(); create();
File file = getRealPath( path ); File file = getRealPath( path );
@ -393,7 +393,7 @@ public class FileMount implements IWritableMount
@Nonnull @Nonnull
@Override @Override
public WritableByteChannel openStreamForAppend( @Nonnull String path ) throws IOException public WritableByteChannel openChannelForAppend( @Nonnull String path ) throws IOException
{ {
if( created() ) if( created() )
{ {

View File

@ -252,7 +252,7 @@ public class FileSystem
m_writableMount.makeDirectory( dir ); m_writableMount.makeDirectory( dir );
} }
} }
return m_writableMount.openStreamForWrite( path ); return m_writableMount.openChannelForWrite( path );
} }
} }
catch( AccessDeniedException e ) catch( AccessDeniedException e )
@ -284,7 +284,7 @@ public class FileSystem
m_writableMount.makeDirectory( dir ); m_writableMount.makeDirectory( dir );
} }
} }
return m_writableMount.openStreamForWrite( path ); return m_writableMount.openChannelForWrite( path );
} }
else if( m_mount.isDirectory( path ) ) else if( m_mount.isDirectory( path ) )
{ {
@ -292,7 +292,7 @@ public class FileSystem
} }
else else
{ {
return m_writableMount.openStreamForAppend( path ); return m_writableMount.openChannelForAppend( path );
} }
} }
catch( AccessDeniedException e ) catch( AccessDeniedException e )
@ -669,10 +669,10 @@ public class FileSystem
path = sanitizePath( path ); path = sanitizePath( path );
MountWrapper mount = getMount( path ); MountWrapper mount = getMount( path );
ReadableByteChannel stream = mount.openForRead( path ); ReadableByteChannel channel = mount.openForRead( path );
if( stream != null ) if( channel != null )
{ {
return openFile( open.apply( stream ) ); return openFile( open.apply( channel ) );
} }
return null; return null;
} }
@ -683,10 +683,10 @@ public class FileSystem
path = sanitizePath( path ); path = sanitizePath( path );
MountWrapper mount = getMount( path ); MountWrapper mount = getMount( path );
WritableByteChannel stream = append ? mount.openForAppend( path ) : mount.openForWrite( path ); WritableByteChannel channel = append ? mount.openForAppend( path ) : mount.openForWrite( path );
if( stream != null ) if( channel != null )
{ {
return openFile( open.apply( stream ) ); return openFile( open.apply( channel ) );
} }
return null; return null;
} }

View File

@ -71,7 +71,7 @@ public class FileSystemWrapperMount implements IFileSystem
@Nonnull @Nonnull
@Override @Override
public WritableByteChannel openStreamForWrite( @Nonnull String path ) throws IOException public WritableByteChannel openChannelForWrite( @Nonnull String path ) throws IOException
{ {
try try
{ {
@ -85,7 +85,7 @@ public class FileSystemWrapperMount implements IFileSystem
@Nonnull @Nonnull
@Override @Override
public WritableByteChannel openStreamForAppend( @Nonnull String path ) throws IOException public WritableByteChannel openChannelForAppend( @Nonnull String path ) throws IOException
{ {
try try
{ {
@ -110,7 +110,7 @@ public class FileSystemWrapperMount implements IFileSystem
@Deprecated @Deprecated
public OutputStream openForWrite( @Nonnull String path ) throws IOException public OutputStream openForWrite( @Nonnull String path ) throws IOException
{ {
return Channels.newOutputStream( openStreamForWrite( path ) ); return Channels.newOutputStream( openChannelForWrite( path ) );
} }
@Nonnull @Nonnull
@ -118,7 +118,7 @@ public class FileSystemWrapperMount implements IFileSystem
@Deprecated @Deprecated
public OutputStream openForAppend( @Nonnull String path ) throws IOException public OutputStream openForAppend( @Nonnull String path ) throws IOException
{ {
return Channels.newOutputStream( openStreamForAppend( path ) ); return Channels.newOutputStream( openChannelForAppend( path ) );
} }
@Override @Override