Java Code Examples for jcifs.smb.SmbFileOutputStream

The following examples show how to use jcifs.smb.SmbFileOutputStream. These examples are extracted from open source projects. 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
@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
@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
@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
@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 Project: iaf   Source File: Samba1FileSystem.java    License: 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 Project: iaf   Source File: Samba1FileSystem.java    License: 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
public WritableByteChannel write(boolean append) throws IOException {
	return Channels.newChannel(new SmbFileOutputStream(file, append));
}
 
Example 8
Source Project: iaf   Source File: SambaFileSystemTestHelper.java    License: 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 Project: commons-vfs   Source File: SmbFileObject.java    License: 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);
}