jcifs.smb.SmbFileOutputStream Java Examples

The following examples show how to use jcifs.smb.SmbFileOutputStream. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RandomAccessFileTest.java    From jcifs with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Test
public void testReadOnly () throws IOException {
    try ( SmbFile f = createTestFile() ) {
        try {
            try ( SmbFileOutputStream os = f.openOutputStream() ) {
                os.write(new byte[] {
                    0x0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7
                });
            }

            byte[] buf = new byte[4];
            try ( SmbRandomAccessFile raf = new SmbRandomAccessFile(f, "r") ) {
                raf.seek(4);
                raf.readFully(buf);
            }

            Assert.assertArrayEquals(new byte[] {
                0x4, 0x5, 0x6, 0x7
            }, buf);
        }
        finally {
            f.delete();
        }
    }
}
 
Example #2
Source File: RandomAccessFileTest.java    From jcifs-ng with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Test
public void testReadOnly () throws IOException {
    try ( SmbFile f = createTestFile() ) {
        try {
            try ( SmbFileOutputStream os = f.openOutputStream() ) {
                os.write(new byte[] {
                    0x0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7
                });
            }

            byte[] buf = new byte[4];
            try ( SmbRandomAccessFile raf = new SmbRandomAccessFile(f, "r") ) {
                raf.seek(4);
                raf.readFully(buf);
            }

            Assert.assertArrayEquals(new byte[] {
                0x4, 0x5, 0x6, 0x7
            }, buf);
        }
        finally {
            f.delete();
        }
    }
}
 
Example #3
Source File: RandomAccessFileTest.java    From jcifs with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Test
public void testReadOnlySeekOOB () throws IOException {
    try ( SmbFile f = createTestFile() ) {
        try {
            try ( SmbFileOutputStream os = f.openOutputStream() ) {
                os.write(new byte[] {
                    0x0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7
                });
            }

            try ( SmbRandomAccessFile raf = new SmbRandomAccessFile(f, "r") ) {
                raf.seek(10);
                Assert.assertEquals(-1, raf.read());
            }

            byte[] buf = new byte[4];
            try ( SmbRandomAccessFile raf = new SmbRandomAccessFile(f, "r") ) {
                raf.seek(6);
                Assert.assertEquals(2, raf.read(buf));
                Assert.assertArrayEquals(new byte[] {
                    0x6, 0x7, 0x0, 0x0
                }, buf);
            }

            try ( SmbRandomAccessFile raf = new SmbRandomAccessFile(f, "r") ) {
                raf.seek(6);
                try {
                    raf.readFully(buf);
                    Assert.fail("Should have thrown exception");
                }
                catch ( SmbEndOfFileException e ) {}
            }

        }
        finally {
            f.delete();
        }
    }
}
 
Example #4
Source File: RandomAccessFileTest.java    From jcifs-ng with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Test
public void testReadOnlySeekOOB () throws IOException {
    try ( SmbFile f = createTestFile() ) {
        try {
            try ( SmbFileOutputStream os = f.openOutputStream() ) {
                os.write(new byte[] {
                    0x0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7
                });
            }

            try ( SmbRandomAccessFile raf = new SmbRandomAccessFile(f, "r") ) {
                raf.seek(10);
                Assert.assertEquals(-1, raf.read());
            }

            byte[] buf = new byte[4];
            try ( SmbRandomAccessFile raf = new SmbRandomAccessFile(f, "r") ) {
                raf.seek(6);
                Assert.assertEquals(2, raf.read(buf));
                Assert.assertArrayEquals(new byte[] {
                    0x6, 0x7, 0x0, 0x0
                }, buf);
            }

            try ( SmbRandomAccessFile raf = new SmbRandomAccessFile(f, "r") ) {
                raf.seek(6);
                try {
                    raf.readFully(buf);
                    Assert.fail("Should have thrown exception");
                }
                catch ( SmbEndOfFileException e ) {}
            }

        }
        finally {
            f.delete();
        }
    }
}
 
Example #5
Source File: Samba1FileSystem.java    From iaf with Apache License 2.0 5 votes vote down vote up
@Override
public OutputStream createFile(SmbFile f) throws FileSystemException {
	try {
		return new SmbFileOutputStream(f);
	} catch (Exception e) {
		throw new FileSystemException(e);
	}
}
 
Example #6
Source File: Samba1FileSystem.java    From iaf with Apache License 2.0 5 votes vote down vote up
@Override
public OutputStream appendFile(SmbFile f) throws FileSystemException {
	try {
		return new SmbFileOutputStream(f, true);
	} catch (Exception e) {
		throw new FileSystemException(e);
	}
}
 
Example #7
Source File: SMBOperationHandler.java    From CloverETL-Engine with GNU Lesser General Public License v2.1 4 votes vote down vote up
public WritableByteChannel write(boolean append) throws IOException {
	return Channels.newChannel(new SmbFileOutputStream(file, append));
}
 
Example #8
Source File: SambaFileSystemTestHelper.java    From iaf with Apache License 2.0 4 votes vote down vote up
@Override
public OutputStream _createFile(String folder, String filename) throws Exception {
	return new SmbFileOutputStream(new SmbFile(context, filename));
}
 
Example #9
Source File: SmbFileObject.java    From commons-vfs with Apache License 2.0 4 votes vote down vote up
/**
 * Creates an output stream to write the file content to.
 */
@Override
protected OutputStream doGetOutputStream(final boolean bAppend) throws Exception {
    return new SmbFileOutputStream(file, bAppend);
}