当前位置: 首页>>代码示例>>Java>>正文


Java SmbFile类代码示例

本文整理汇总了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;
}
 
开发者ID:dream-lab,项目名称:echo,代码行数:27,代码来源:GetSmbFiles.java

示例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();
    }
}
 
开发者ID:thebagchi,项目名称:heimdall-proxy,代码行数:22,代码来源:SambaTester.java

示例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.");
}
 
开发者ID:pontiussoftware,项目名称:smb-nio,代码行数:31,代码来源:SMBFileSystemProvider.java

示例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");
    }
}
 
开发者ID:pontiussoftware,项目名称:smb-nio,代码行数:34,代码来源:SeekableSMBByteChannel.java

示例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;
	}
}
 
开发者ID:starn,项目名称:encdroidMC,代码行数:13,代码来源:FileProvider3.java

示例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;
}
 
开发者ID:starn,项目名称:encdroidMC,代码行数:19,代码来源:FileProvider3.java

示例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;
}
 
开发者ID:starn,项目名称:encdroidMC,代码行数:17,代码来源:FileProvider3.java

示例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();
    }
 
开发者ID:IdentityAutomation,项目名称:jcifs-idautopatch,代码行数:18,代码来源:Append.java

示例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();
        }
    }
}
 
开发者ID:AgNO3,项目名称:jcifs-ng,代码行数:17,代码来源:ReadWriteTest.java

示例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");
        }
    }

}
 
开发者ID:AgNO3,项目名称:jcifs-ng,代码行数:19,代码来源:WatchTest.java

示例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 );
}
 
开发者ID:codelibs,项目名称:jcifs,代码行数:18,代码来源:CountPerms.java

示例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();
        }
    }
}
 
开发者ID:AgNO3,项目名称:jcifs-ng,代码行数:27,代码来源:TimeoutTest.java

示例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 );
            }
        }
    }
 
开发者ID:codelibs,项目名称:jcifs,代码行数:24,代码来源:CrawlTest.java

示例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();
        }
    }
}
 
开发者ID:AgNO3,项目名称:jcifs-ng,代码行数:26,代码来源:RandomAccessFileTest.java

示例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();
    }
 
开发者ID:IdentityAutomation,项目名称:jcifs-idautopatch,代码行数:26,代码来源:Get.java


注:本文中的jcifs.smb.SmbFile类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。