Package org.uberfire.java.nio.channels

Examples of org.uberfire.java.nio.channels.SeekableByteChannel


        final String userBasedPath = System.getProperty( "user.dir" ) + "/byte_some_file_here.txt";

        final Path path = GeneralPathImpl.create( fsProvider.getFileSystem( URI.create( "file:///" ) ), userBasedPath, false );
        assertThat( path.toFile().exists() ).isFalse();

        final SeekableByteChannel channel = fsProvider.newByteChannel( path, null );

        assertThat( channel ).isNotNull();
        assertThat( path.toFile().exists() ).isTrue();
        path.toFile().delete();
        assertThat( path.toFile().exists() ).isFalse();
View Full Code Here


        final String userBasedPath = System.getProperty( "user.dir" ) + "/my_byte_some_file_here.txt";

        final Path path = GeneralPathImpl.create( fsProvider.getFileSystem( URI.create( "file:///" ) ), userBasedPath, false );
        assertThat( path.toFile().exists() ).isFalse();

        final SeekableByteChannel channel = fsProvider.newByteChannel( path, null );

        assertThat( channel ).isNotNull();
        assertThat( path.toFile().exists() ).isTrue();

        assertThat( channel.isOpen() ).isTrue();

        channel.close();

        assertThat( channel.isOpen() ).isFalse();

//        try {
//            channel.position();
//            fail( "method not implemented - exception expected!" );
//        } catch ( NotImplementedException ex ) {
View Full Code Here

    @Test
    public void test() throws IOException {
        final File tempFile = File.createTempFile( "foo", "bar" );

        final SeekableByteChannel sbc = new SeekableByteChannelFileBasedImpl( new RandomAccessFile( tempFile, "rw" ).getChannel() );

        assertTrue( sbc.isOpen() );
        sbc.write( ByteBuffer.wrap( "CONTENT\n?!".getBytes() ) );

        sbc.position( 0L );
        ByteBuffer buffer = ByteBuffer.allocate( 10 );
        sbc.read( buffer );
        assertEquals( "CONTENT\n?!", new String( buffer.array() ) );

        sbc.close();
        assertFalse( sbc.isOpen() );

    }
View Full Code Here

    @Test
    public void testPosition() throws IOException {
        final File tempFile = File.createTempFile( "foo", "bar" );

        final SeekableByteChannel sbc = new SeekableByteChannelFileBasedImpl( new RandomAccessFile( tempFile, "rw" ).getChannel() );

        assertTrue( sbc.isOpen() );
        sbc.write( ByteBuffer.wrap( "CONTENT\n?!".getBytes() ) );

        assertEquals( 10L, sbc.position() );
        assertEquals( 10L, sbc.size() );

        sbc.position( 1L );
        ByteBuffer buffer = ByteBuffer.allocate( 8 );
        sbc.read( buffer );
        assertEquals( "ONTENT\n?", new String( buffer.array() ) );

        assertEquals( 9L, sbc.position() );

        sbc.position( 0L );
        sbc.truncate( 2L );
        ByteBuffer buffer3 = ByteBuffer.allocate( 2 );
        sbc.read( buffer3 );
        assertEquals( "CO", new String( buffer3.array() ) );

        sbc.close();
        assertFalse( sbc.isOpen() );

    }
View Full Code Here

    }

    @Override
    public SeekableByteChannel newByteChannel( final Path path,
                                               final OpenOption... options ) throws IllegalArgumentException, UnsupportedOperationException, FileAlreadyExistsException, IOException, SecurityException {
        final SeekableByteChannel sbc = service.newByteChannel( path, options );

        return new SeekableByteChannelWrapperImpl( sbc ) {
            @Override
            public void close() throws java.io.IOException {
                new FileSystemSyncLock<Void>( service.getId(), path.getFileSystem() ).execute( clusterService, new FutureTask<Void>( new Callable<Void>() {
                    @Override
                    public Void call() throws Exception {
                        sbc.close();
                        return null;
                    }
                } ) );
            }
        };
View Full Code Here

    @Override
    public SeekableByteChannel newByteChannel( final Path path,
                                               final Set<? extends OpenOption> options,
                                               final FileAttribute<?>... attrs ) throws IllegalArgumentException, UnsupportedOperationException, FileAlreadyExistsException, IOException, SecurityException {
        final SeekableByteChannel sbc = service.newByteChannel( path, options, attrs );

        return new SeekableByteChannelWrapperImpl( sbc ) {
            @Override
            public void close() throws java.io.IOException {
                new FileSystemSyncLock<Void>( service.getId(), path.getFileSystem() ).execute( clusterService, new FutureTask<Void>( new Callable<Void>() {
                    @Override
                    public Void call() throws Exception {
                        sbc.close();
                        return null;
                    }
                } ) );
            }
        };
View Full Code Here

        if ( exists( dot( path ) ) ) {
            properties.load( newInputStream( dot( path ) ) );
        }
        final FileAttribute<?>[] allAttrs = consolidate( properties, attrs );

        final SeekableByteChannel result = Files.newByteChannel( path, buildOptions( options ), allAttrs );

        if ( isFileScheme( path ) ) {
            buildDotFile( path, newOutputStream( dot( path ) ), allAttrs );
        }
View Full Code Here

    public synchronized Path write( final Path path,
                                    final byte[] bytes,
                                    final Set<? extends OpenOption> options,
                                    final FileAttribute<?>... attrs ) throws IllegalArgumentException, IOException, UnsupportedOperationException {
        waitFSUnlock( path );
        SeekableByteChannel byteChannel;
        try {
            byteChannel = newByteChannel( path, buildOptions( options ), attrs );
        } catch ( final FileAlreadyExistsException ex ) {
            ( (AbstractPath) path ).clearCache();
            byteChannel = newByteChannel( path, buildOptions( options, TRUNCATE_EXISTING ), attrs );
        }

        try {
            byteChannel.write( ByteBuffer.wrap( bytes ) );
            byteChannel.close();
        } catch ( final java.io.IOException e ) {
            throw new IOException( e );
        }

        return path;
View Full Code Here

        Files.newOutputStream( null );
    }

    @Test
    public void newByteChannel() throws IOException {
        final SeekableByteChannel sbc = Files.newByteChannel( newTempDir().resolve( "file.temp.txt" ), new HashSet<OpenOption>() );
        assertThat( sbc ).isNotNull();
        sbc.close();

        final SeekableByteChannel sbc2 = Files.newByteChannel( newTempDir().resolve( "file.temp2.txt" ) );
        assertThat( sbc ).isNotNull();
        sbc.close();
    }
View Full Code Here

    private void copyFile( final JGitPathImpl source,
                           final JGitPathImpl target,
                           final CopyOption... options ) {

        final InputStream in = newInputStream( source, convert( options ) );
        final SeekableByteChannel out = newByteChannel( target, new HashSet<OpenOption>() {{
            add( StandardOpenOption.TRUNCATE_EXISTING );
            for ( final CopyOption _option : options ) {
                if ( _option instanceof OpenOption ) {
                    add( (OpenOption) _option );
                }
            }
        }} );

        try {
            int count;
            byte[] buffer = new byte[ 8192 ];
            while ( ( count = in.read( buffer ) ) > 0 ) {
                out.write( ByteBuffer.wrap( buffer, 0, count ) );
            }
        } catch ( Exception e ) {
            throw new IOException( e );
        } finally {
            try {
                out.close();
            } catch ( java.io.IOException e ) {
                throw new IOException( e );
            } finally {
                try {
                    in.close();
View Full Code Here

TOP

Related Classes of org.uberfire.java.nio.channels.SeekableByteChannel

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.