1
0
mirror of https://github.com/SquidDev-CC/CC-Tweaked synced 2024-06-13 16:56:49 +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".
* @return A stream for writing to
* @throws IOException If the file could not be opened for writing.
* @deprecated Use {@link #openStreamForWrite(String)} instead.
* @deprecated Use {@link #openChannelForWrite(String)} instead.
*/
@Nonnull
@Deprecated
@ -68,7 +68,7 @@ public interface IWritableMount extends IMount
*/
@Nonnull
@SuppressWarnings("deprecation")
default WritableByteChannel openStreamForWrite( @Nonnull String path ) throws IOException
default WritableByteChannel openChannelForWrite( @Nonnull String path ) throws IOException
{
return Channels.newChannel( openForWrite( path ) );
}
@ -79,7 +79,7 @@ default WritableByteChannel openStreamForWrite( @Nonnull String path ) throws IO
* @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 #openStreamForAppend(String)} instead.
* @deprecated Use {@link #openChannelForAppend(String)} instead.
*/
@Nonnull
@Deprecated
@ -95,7 +95,7 @@ default WritableByteChannel openStreamForWrite( @Nonnull String path ) throws IO
*/
@Nonnull
@SuppressWarnings("deprecation")
default WritableByteChannel openStreamForAppend( @Nonnull String path ) throws IOException
default WritableByteChannel openChannelForAppend( @Nonnull String path ) throws IOException
{
return Channels.newChannel( openForAppend( path ) );
}

View File

@ -48,7 +48,7 @@ public int write( ByteBuffer src ) throws IOException
public long position() throws IOException
{
if( closed ) throw new ClosedChannelException();
return 0;
return position;
}
@Override

View File

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

View File

@ -252,7 +252,7 @@ public WritableByteChannel openForWrite( String path ) throws FileSystemExceptio
m_writableMount.makeDirectory( dir );
}
}
return m_writableMount.openStreamForWrite( path );
return m_writableMount.openChannelForWrite( path );
}
}
catch( AccessDeniedException e )
@ -284,7 +284,7 @@ public WritableByteChannel openForAppend( String path ) throws FileSystemExcepti
m_writableMount.makeDirectory( dir );
}
}
return m_writableMount.openStreamForWrite( path );
return m_writableMount.openChannelForWrite( path );
}
else if( m_mount.isDirectory( path ) )
{
@ -292,7 +292,7 @@ else if( m_mount.isDirectory( path ) )
}
else
{
return m_writableMount.openStreamForAppend( path );
return m_writableMount.openChannelForAppend( path );
}
}
catch( AccessDeniedException e )
@ -669,10 +669,10 @@ public synchronized <T extends Closeable> FileSystemWrapper<T> openForRead( Stri
path = sanitizePath( path );
MountWrapper mount = getMount( path );
ReadableByteChannel stream = mount.openForRead( path );
if( stream != null )
ReadableByteChannel channel = mount.openForRead( path );
if( channel != null )
{
return openFile( open.apply( stream ) );
return openFile( open.apply( channel ) );
}
return null;
}
@ -683,10 +683,10 @@ public synchronized <T extends Closeable> FileSystemWrapper<T> openForWrite( Str
path = sanitizePath( path );
MountWrapper mount = getMount( path );
WritableByteChannel stream = append ? mount.openForAppend( path ) : mount.openForWrite( path );
if( stream != null )
WritableByteChannel channel = append ? mount.openForAppend( path ) : mount.openForWrite( path );
if( channel != null )
{
return openFile( open.apply( stream ) );
return openFile( open.apply( channel ) );
}
return null;
}

View File

@ -71,7 +71,7 @@ public ReadableByteChannel openChannelForRead( @Nonnull String path ) throws IOE
@Nonnull
@Override
public WritableByteChannel openStreamForWrite( @Nonnull String path ) throws IOException
public WritableByteChannel openChannelForWrite( @Nonnull String path ) throws IOException
{
try
{
@ -85,7 +85,7 @@ public WritableByteChannel openStreamForWrite( @Nonnull String path ) throws IOE
@Nonnull
@Override
public WritableByteChannel openStreamForAppend( @Nonnull String path ) throws IOException
public WritableByteChannel openChannelForAppend( @Nonnull String path ) throws IOException
{
try
{
@ -110,7 +110,7 @@ public InputStream openForRead( @Nonnull String path ) throws IOException
@Deprecated
public OutputStream openForWrite( @Nonnull String path ) throws IOException
{
return Channels.newOutputStream( openStreamForWrite( path ) );
return Channels.newOutputStream( openChannelForWrite( path ) );
}
@Nonnull
@ -118,7 +118,7 @@ public OutputStream openForWrite( @Nonnull String path ) throws IOException
@Deprecated
public OutputStream openForAppend( @Nonnull String path ) throws IOException
{
return Channels.newOutputStream( openStreamForAppend( path ) );
return Channels.newOutputStream( openChannelForAppend( path ) );
}
@Override