本文整理匯總了Java中jcifs.smb.SmbFile類的典型用法代碼示例。如果您正苦於以下問題:Java SmbFile類的具體用法?Java SmbFile怎麽用?Java SmbFile使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
SmbFile類屬於jcifs.smb包,在下文中一共展示了SmbFile類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: performListing
import jcifs.smb.SmbFile; //導入依賴的package包/類
private Set<SmbFile> performListing(final SmbFile directory2, final boolean recurseSubdirectories) throws SmbException {
if (!directory2.canRead() || !directory2.canWrite()) {
throw new IllegalStateException("Directory '" + directory2 + "' does not have sufficient permissions (i.e., not writable and readable)");
}
final Set<SmbFile> queue = new HashSet<SmbFile>();
if (!directory2.exists()) {
return queue;
}
final SmbFile[] children = directory2.listFiles();
if (children == null) {
return queue;
}
for (final SmbFile child : children) {
if (child.isDirectory()) {
if (recurseSubdirectories) {
queue.addAll(performListing(child, recurseSubdirectories));
}
} else {
queue.add(child);
}
}
return queue;
}
示例2: listFiles
import jcifs.smb.SmbFile; //導入依賴的package包/類
public void listFiles() {
try {
NtlmPasswordAuthentication authentication = new NtlmPasswordAuthentication(
null, USER, PASSWORD);
SmbFile home = new SmbFile("smb://localhost:8445/user/", authentication);
if(home.isDirectory()) {
List<SmbFile> files = Arrays.asList(home.listFiles());
for(SmbFile file: files) {
if(file.isDirectory()) {
System.out.println("Directory: " + file.getName());
}
if(file.isFile()) {
System.out.println("File: " + file.getName());
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
示例3: checkAccess
import jcifs.smb.SmbFile; //導入依賴的package包/類
/**
* Checks access to file under the provided {@link SMBPath}.
*
* @param path {@link SMBPath} for which access should be checked.
* @param modes AccessModes that should be checked. Onl yREAD and WRITE are supported.
*
* @throws NoSuchFileException If file or folder specified by {@link SMBPath} does not exist.
* @throws AccessDeniedException If requested access cannot be provided for file or folder under {@link SMBPath}.
* @throws IllegalArgumentException If provided path is not a {@link SMBPath} instance.
* @throws IOException If checking accessfails for some reason.
*/
@Override
public void checkAccess(Path path, AccessMode... modes) throws IOException {
SmbFile smbFile = SMBPath.fromPath(path).getSmbFile();
/* First check if file exists. */
if (!smbFile.exists()) throw new NoSuchFileException("The specified SMB resource does not exist.");
/* Determin which attributes to check. */
boolean checkRead = false;
boolean checkWrite = false;
for (AccessMode mode : modes) {
if (mode.equals(AccessMode.READ)) checkRead = true;
if (mode.equals(AccessMode.WRITE)) checkWrite = true;
}
/* Perform necessary checks. */
if (checkRead && !smbFile.canRead()) throw new AccessDeniedException("The specified SMB resource is not readable.");
if (checkWrite && !smbFile.canWrite()) throw new AccessDeniedException("The specified SMB resource is not writable.");
}
示例4: SeekableSMBByteChannel
import jcifs.smb.SmbFile; //導入依賴的package包/類
/**
* Constructor for {@link SeekableSMBByteChannel}
*
* @param file The {@link SmbFile} instance that should be opened.
* @param write Flag that indicates, whether write access is requested.
* @param create Flag that indicates, whether file should be created.
* @param create_new Flag that indicates, whether file should be created. If it is set to true, operation will fail if file exists!
* @param truncate Flag that indicates, whether file should be truncated to length 0 when being opened.
* @param append Flag that indicates, whether data should be appended.
* @throws IOException If something goes wrong when accessing the file.
*/
SeekableSMBByteChannel(SmbFile file, boolean write, boolean create, boolean create_new, boolean truncate, boolean append) throws IOException {
/* Tries to create a new file, if so specified. */
if (create || create_new) {
if (file.exists()) {
if (create_new) throw new FileAlreadyExistsException("The specified file '" + file.getPath() + "' does already exist!");
} else {
file.createNewFile();
}
}
/* Opens the file with either read only or write access. */
if (write) {
file.setReadWrite();
this.random = new SmbRandomAccessFile(file, "rw");
if (truncate) this.random.setLength(0);
if (append) this.random.seek(this.random.length());
} else {
file.setReadOnly();
this.random = new SmbRandomAccessFile(file, "r");
}
}
示例5: copy
import jcifs.smb.SmbFile; //導入依賴的package包/類
@Override
public boolean copy(String srcFilePath, String dstFilePath)
throws IOException {
SmbFile currentFolder = new SmbFile(getAbsolutePath(srcFilePath), authentication);
SmbFile targetFolder = new SmbFile(getAbsolutePath(dstFilePath), authentication);
try {
currentFolder.copyTo(targetFolder);
return true;
} catch (Exception e){
return false;
}
}
示例6: SmbFile2EncFSFileInfo
import jcifs.smb.SmbFile; //導入依賴的package包/類
private EncFSFileInfo SmbFile2EncFSFileInfo(SmbFile smbFile){
EncFSFileInfo result;
try {
String name = smbFile.getName();
//transform parent absolute path into path relative to server path
String relativePath=this.getRelativePathFromAbsolutePath(smbFile.getParent());
if (name.endsWith("/")) name=name.substring(0,name.length()-1);
result = new EncFSFileInfo(name,relativePath,smbFile.isDirectory(),smbFile.getLastModified(),smbFile.length(),true,true,true);
} catch (Exception e){
throw new RuntimeException(e);
}
return result;
}
示例7: fsList
import jcifs.smb.SmbFile; //導入依賴的package包/類
@Override
public List<EncFSFileInfo> fsList(String path) throws IOException {
System.out.println("*** fsList "+path+" => "+getAbsolutePath(path));
String pathToList = getAbsolutePath(path);
if (!pathToList.endsWith("/")) pathToList+="/";
SmbFile currentFolder = new SmbFile(pathToList, authentication);
SmbFile[] files = currentFolder.listFiles();
List<EncFSFileInfo> fList = new LinkedList<EncFSFileInfo>();
for(int a = 0; a < files.length; a++)
{
EncFSFileInfo encFSFileInfo = SmbFile2EncFSFileInfo(files[a]);
fList.add(encFSFileInfo);
}
return fList;
}
示例8: main
import jcifs.smb.SmbFile; //導入依賴的package包/類
public static void main( String argv[] ) throws Exception {
SmbFile f = new SmbFile( argv[0] );
SmbFileOutputStream out = new SmbFileOutputStream( f, true );
byte[] msg;
int i = 0;
while( i++ < 3 ) {
msg = new String( "this is msg #" + i ).getBytes();
out.write( msg );
System.out.write( msg );
Thread.sleep( 10000 );
//out = new SmbFileOutputStream( f, true );
}
out.close();
}
示例9: testReadWriteTwoHandles
import jcifs.smb.SmbFile; //導入依賴的package包/類
@Test
public void testReadWriteTwoHandles () throws IOException {
try ( SmbFile f = createTestFile() ) {
try ( SmbFile s = new SmbFile(f.getURL().toString(), withTestNTLMCredentials(getContext()));
SmbFile t = new SmbFile(f.getURL().toString(), withTestNTLMCredentials(getContext())) ) {
try ( OutputStream os = s.getOutputStream();
InputStream is = t.getInputStream() ) {
writeRandom(1024, 1024, os);
verifyRandom(1024, 1024, is);
}
}
finally {
f.delete();
}
}
}
示例10: testWatchRecursive
import jcifs.smb.SmbFile; //導入依賴的package包/類
@Test
public void testWatchRecursive () throws InterruptedException, ExecutionException, IOException {
try ( SmbResource subdir = this.base.resolve("test/") ) {
subdir.mkdir();
try ( SmbWatchHandle w = this.base.watch(FileNotifyInformation.FILE_NOTIFY_CHANGE_FILE_NAME, true) ) {
setupWatch(w);
try ( SmbResource cr = new SmbFile(subdir, "created") ) {
cr.createNewFile();
assertNotified(w, FileNotifyInformation.FILE_ACTION_ADDED, "test\\created", null);
}
}
catch ( TimeoutException e ) {
log.info("Timeout waiting", e);
fail("Did not recieve notification");
}
}
}
示例11: run
import jcifs.smb.SmbFile; //導入依賴的package包/類
void run( String url ) throws Exception {
traverse( new SmbFile( url ), maxDepth );
for (int p = 0; p < 16; p++) {
int len = 15 - permissionNames[p].length();
while( len > 0 ) {
System.out.print( " " );
len--;
}
System.out.println( permissionNames[p] + ": " + permissionCounts[p] );
}
System.out.println( " num files: " + numFiles );
System.out.println( " num directories: " + numDirectories );
System.out.println( " num both: " + (numFiles + numDirectories) );
System.out.println( " meta req: " + numMeta );
System.out.println( "meta (incl. arch) req: " + numMetaWithArch );
}
示例12: testTimeoutOpenFile
import jcifs.smb.SmbFile; //導入依賴的package包/類
@Test
public void testTimeoutOpenFile () throws IOException, InterruptedException {
// use separate context here as the settings stick to the transport
CIFSContext ctx = lowTimeout(withTestNTLMCredentials(getNewContext()));
try ( SmbFile f = new SmbFile(new SmbFile(getTestShareURL(), ctx), makeRandomName()) ) {
int soTimeout = ctx.getConfig().getSoTimeout();
f.createNewFile();
try {
try ( OutputStream os = f.getOutputStream() ) {
os.write(new byte[] {
1, 2, 3, 4, 5, 6, 7, 8
});
}
try ( InputStream is = f.getInputStream() ) {
for ( int i = 0; i < 8; i++ ) {
is.read();
Thread.sleep(soTimeout);
}
}
}
finally {
f.delete();
}
}
}
示例13: traverse
import jcifs.smb.SmbFile; //導入依賴的package包/類
void traverse( SmbFile f, int depth ) throws MalformedURLException, IOException {
if( depth == 0 ) {
return;
}
SmbFile[] l = f.listFiles();
for(int i = 0; l != null && i < l.length; i++ ) {
try {
for( int j = maxDepth - depth; j > 0; j-- ) {
System.out.print( " " );
}
System.out.println( l[i] + " " + l[i].exists() );
if( l[i].isDirectory() ) {
traverse( l[i], depth - 1 );
}
} catch( IOException ioe ) {
System.out.println( l[i] + ":" );
ioe.printStackTrace( System.out );
}
}
}
示例14: testWriteVerify
import jcifs.smb.SmbFile; //導入依賴的package包/類
@Test
public void testWriteVerify () throws IOException {
try ( SmbFile f = createTestFile() ) {
try {
int bufSize = 4096;
int l = 1024;
int off = 2048;
try ( SmbRandomAccessFile raf = new SmbRandomAccessFile(f, "rw") ) {
raf.seek(off);
writeRandom(bufSize, l, raf);
assertEquals(l + off, raf.getFilePointer());
raf.setLength(raf.getFilePointer() + l);
}
try ( InputStream is = f.getInputStream() ) {
verifyZero(off, is);
ReadWriteTest.verifyRandom(bufSize, l, false, is);
verifyZero(l, is);
}
}
finally {
f.delete();
}
}
}
示例15: main
import jcifs.smb.SmbFile; //導入依賴的package包/類
public static void main( String argv[] ) throws Exception {
SmbFile f = new SmbFile( argv[0] );
SmbFileInputStream in = new SmbFileInputStream( f );
FileOutputStream out = new FileOutputStream( f.getName() );
long t0 = System.currentTimeMillis();
byte[] b = new byte[8192];
int n, tot = 0;
long t1 = t0;
while(( n = in.read( b )) > 0 ) {
out.write( b, 0, n );
tot += n;
System.out.print( '#' );
}
long t = System.currentTimeMillis() - t0;
System.out.println();
System.out.println( tot + " bytes transfered in " + ( t / 1000 ) + " seconds at " + (( tot / 1000 ) / Math.max( 1, ( t / 1000 ))) + "Kbytes/sec" );
in.close();
out.close();
}