jcifs.smb.SmbException Java Examples
The following examples show how to use
jcifs.smb.SmbException.
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: ReadWriteTest.java From jcifs with GNU Lesser General Public License v2.1 | 6 votes |
@Test public void testFifoPipeTwoHandles () throws IOException { try ( SmbNamedPipe s = new SmbNamedPipe(getFifoPipeUrl(), SmbPipeResource.PIPE_TYPE_WRONLY, withTestNTLMCredentials(getContext())); SmbNamedPipe t = new SmbNamedPipe(getFifoPipeUrl(), SmbPipeResource.PIPE_TYPE_RDONLY, withTestNTLMCredentials(getContext())) ) { try ( SmbPipeHandle sp = s.openPipe(); SmbPipeHandle tp = t.openPipe() ) { try ( OutputStream os = sp.getOutput() ) { writeRandom(1024, 1024, os); } try ( InputStream is = tp.getInput() ) { verifyRandom(1024, 1024, is); } } catch ( SmbException e ) { if ( e.getNtStatus() == 0xC0000034 ) { Assume.assumeTrue("Server does not support pipes or it does not exist", false); } throw e; } } }
Example #2
Source File: ReadWriteTest.java From jcifs-ng with GNU Lesser General Public License v2.1 | 6 votes |
@Test public void testFifoPipe () throws IOException { try ( SmbNamedPipe f = new SmbNamedPipe(getFifoPipeUrl(), SmbPipeResource.PIPE_TYPE_RDWR, withTestNTLMCredentials(getContext())) ) { try ( SmbPipeHandle p = f.openPipe() ) { try ( OutputStream os = p.getOutput() ) { writeRandom(1024, 1024, os); try ( InputStream is = p.getInput() ) { verifyRandom(1024, 1024, is); } } } catch ( SmbException e ) { if ( e.getNtStatus() == 0xC0000034 ) { Assume.assumeTrue("Server does not support pipes or it does not exist", false); } throw e; } } }
Example #3
Source File: ReadWriteTest.java From jcifs-ng with GNU Lesser General Public License v2.1 | 6 votes |
@Test public void testCallPipe () throws IOException { try ( SmbNamedPipe f = new SmbNamedPipe( getCallPipeUrl(), SmbPipeResource.PIPE_TYPE_RDWR | SmbPipeResource.PIPE_TYPE_CALL, withTestNTLMCredentials(getContext())) ) { try ( SmbPipeHandle p = f.openPipe() ) { try ( OutputStream os = p.getOutput() ) { writeRandom(1024, 1024, os); try ( InputStream is = p.getInput() ) { verifyRandom(1024, 1024, is); } } } catch ( SmbException e ) { if ( e.getNtStatus() == 0xC00000BB ) { Assume.assumeTrue("Server does not support pipes or it does not exist", false); } throw e; } } }
Example #4
Source File: ReadWriteTest.java From jcifs-ng with GNU Lesser General Public License v2.1 | 6 votes |
@Test public void testTransactPipe () throws IOException { try ( SmbNamedPipe f = new SmbNamedPipe( getTransactPipeUrl(), SmbPipeResource.PIPE_TYPE_RDWR | SmbPipeResource.PIPE_TYPE_TRANSACT, withTestNTLMCredentials(getContext())) ) { try ( SmbPipeHandle p = f.openPipe() ) { try ( OutputStream os = p.getOutput() ) { writeRandom(1024, 1024, os); try ( InputStream is = p.getInput() ) { verifyRandom(1024, 1024, is); } } } catch ( SmbException e ) { if ( e.getNtStatus() == 0xC00000BB ) { Assume.assumeTrue("Server does not support pipes or it does not exist", false); } throw e; } } }
Example #5
Source File: ReadWriteTest.java From jcifs-ng with GNU Lesser General Public License v2.1 | 6 votes |
@Test public void testFifoPipeTwoHandles () throws IOException { try ( SmbNamedPipe s = new SmbNamedPipe(getFifoPipeUrl(), SmbPipeResource.PIPE_TYPE_WRONLY, withTestNTLMCredentials(getContext())); SmbNamedPipe t = new SmbNamedPipe(getFifoPipeUrl(), SmbPipeResource.PIPE_TYPE_RDONLY, withTestNTLMCredentials(getContext())) ) { try ( SmbPipeHandle sp = s.openPipe(); SmbPipeHandle tp = t.openPipe() ) { try ( OutputStream os = sp.getOutput() ) { writeRandom(1024, 1024, os); } try ( InputStream is = tp.getInput() ) { verifyRandom(1024, 1024, is); } } catch ( SmbException e ) { if ( e.getNtStatus() == 0xC0000034 ) { Assume.assumeTrue("Server does not support pipes or it does not exist", false); } throw e; } } }
Example #6
Source File: ReadWriteTest.java From jcifs-ng with GNU Lesser General Public License v2.1 | 6 votes |
private void runReadWriteTest ( int bufSize, long length ) throws MalformedURLException, UnknownHostException, SmbException, IOException { try ( SmbFile f = createTestFile() ) { try { try ( OutputStream os = f.getOutputStream() ) { writeRandom(bufSize, length, os); } assertEquals("File size matches", length, f.length()); try ( InputStream is = f.getInputStream() ) { verifyRandom(bufSize, length, is); } } finally { f.delete(); } } }
Example #7
Source File: SmbMovie.java From Mizuu with Apache License 2.0 | 6 votes |
@Override public void addToResults(SmbFile file, TreeSet<String> results) { if (MizLib.checkFileTypes(file.getCanonicalPath())) { try { if (file.length() < getFileSizeLimit() && !file.getName().equalsIgnoreCase("video_ts.ifo")) return; } catch (SmbException e) { return; } if (!clearLibrary()) if (existingMovies.get(file.getCanonicalPath()) != null) return; String tempFileName = file.getName().substring(0, file.getName().lastIndexOf(".")); if (tempFileName.toLowerCase(Locale.ENGLISH).matches(".*part[2-9]|cd[2-9]")) return; //Add the file if it reaches this point results.add(file.getCanonicalPath()); } }
Example #8
Source File: JCIFS_NGController.java From DanDanPlayForAndroid with MIT License | 6 votes |
@Override public List<SmbFileInfo> getSelfList() { if (isRootDir()) return rootFileList; List<SmbFileInfo> fileInfoList = new ArrayList<>(); try { SmbFile smbFile = new SmbFile(mAuthUrl + mPath, cifsContext); if (smbFile.isDirectory() && smbFile.canRead()) { fileInfoList.addAll(getFileInfoList(smbFile.listFiles())); } } catch (MalformedURLException | SmbException e) { e.printStackTrace(); } return fileInfoList; }
Example #9
Source File: HFile.java From PowerFileExplorer with GNU General Public License v3.0 | 6 votes |
public boolean delete(Context context, boolean rootmode) throws RootNotPermittedException { if (isSmb()) { try { new SmbFile(path).delete(); } catch (SmbException | MalformedURLException e) { Logger.log(e, path, context); } } else { if (isRoot() && rootmode) { setMode(OpenMode.ROOT); RootUtils.delete(getPath()); } else { FileUtil.deleteFile(new File(path), context); } } return !exists(); }
Example #10
Source File: HFile.java From PowerFileExplorer with GNU General Public License v3.0 | 6 votes |
public long lastModified() throws MalformedURLException, SmbException { switch (mode) { case SMB: SmbFile smbFile = getSmbFile(); if (smbFile != null) return smbFile.lastModified(); break; case FILE: new File(path).lastModified(); break; case ROOT: BaseFile baseFile = generateBaseFileFromParent(); if (baseFile != null) return baseFile.date; } return new File("/").lastModified(); }
Example #11
Source File: HFile.java From PowerFileExplorer with GNU General Public License v3.0 | 6 votes |
/** * @deprecated use {@link #length(Context)} to handle content resolvers * @return */ public long length() { long s = 0L; switch (mode) { case SMB: SmbFile smbFile = getSmbFile(); if (smbFile != null) try { s = smbFile.length(); } catch (SmbException e) { } return s; case FILE: s = new File(path).length(); return s; case ROOT: BaseFile baseFile = generateBaseFileFromParent(); if (baseFile != null) return baseFile.size; break; } return s; }
Example #12
Source File: Samba1FileSystem.java From iaf with Apache License 2.0 | 6 votes |
@Override public Iterator<SmbFile> listFiles(String folder) throws FileSystemException { try { if (!isListHiddenFiles()) { SmbFileFilter filter = new SmbFileFilter() { @Override public boolean accept(SmbFile file) throws SmbException { return !file.isHidden(); } }; return new SmbFileIterator(smbContext.listFiles(filter)); } return new SmbFileIterator(smbContext.listFiles()); } catch (SmbException e) { throw new FileSystemException(e); } }
Example #13
Source File: SessionTest.java From jcifs-ng with GNU Lesser General Public License v2.1 | 6 votes |
@Test // BUG #14 public void testNoLeakRequestError () throws IOException { try ( SmbResource f = getDefaultShareRoot().resolve("doesnotexist") ) { try ( SmbTreeHandleInternal th = (SmbTreeHandleInternal) ( (SmbFile) f ).getTreeHandle(); SmbSessionInternal sess = th.getSession().unwrap(SmbSessionInternal.class); SmbTransportInternal t = (SmbTransportInternal) sess.getTransport() ) { assertEquals(0, t.getInflightRequests()); try ( InputStream is = f.openInputStream() ) { } catch ( SmbException e ) { // expected } assertEquals(0, t.getInflightRequests()); } } }
Example #14
Source File: ConcurrencyTest.java From jcifs-ng with GNU Lesser General Public License v2.1 | 6 votes |
@Test public void testOpenLocked () throws IOException { String fname = makeRandomName(); try ( SmbFile sr = getDefaultShareRoot(); SmbResource exclFile = new SmbFile(sr, fname) ) { try ( OutputStream s = exclFile.openOutputStream(false, SmbConstants.FILE_NO_SHARE); InputStream is = exclFile.openInputStream(SmbConstants.FILE_NO_SHARE) ) { fail("No sharing violation"); } catch ( SmbException e ) { if ( e.getNtStatus() == NtStatus.NT_STATUS_SHARING_VIOLATION ) { return; } throw e; } finally { exclFile.delete(); } } }
Example #15
Source File: SambaSenderOld.java From iaf with Apache License 2.0 | 6 votes |
private XmlBuilder getFileAsXmlBuilder(SmbFile file) throws SmbException { XmlBuilder fileXml = new XmlBuilder("file"); fileXml.addAttribute("name", file.getName()); long fileSize = file.length(); fileXml.addAttribute("size", "" + fileSize); fileXml.addAttribute("fSize", "" + Misc.toFileSize(fileSize, true)); fileXml.addAttribute("directory", "" + file.isDirectory()); fileXml.addAttribute("canonicalName", file.getCanonicalPath()); // Get the modification date of the file Date modificationDate = new Date(file.lastModified()); //add date String date = DateUtils.format(modificationDate, DateUtils.FORMAT_DATE); fileXml.addAttribute("modificationDate", date); // add the time String time = DateUtils.format(modificationDate, DateUtils.FORMAT_TIME_HMS); fileXml.addAttribute("modificationTime", time); return fileXml; }
Example #16
Source File: ReadWriteTest.java From jcifs with GNU Lesser General Public License v2.1 | 6 votes |
private void runReadWriteTest ( int bufSize, long length ) throws MalformedURLException, UnknownHostException, SmbException, IOException { try ( SmbFile f = createTestFile() ) { try { try ( OutputStream os = f.getOutputStream() ) { writeRandom(bufSize, length, os); } assertEquals("File size matches", length, f.length()); try ( InputStream is = f.getInputStream() ) { verifyRandom(bufSize, length, is); } } finally { f.delete(); } } }
Example #17
Source File: SessionTest.java From jcifs with GNU Lesser General Public License v2.1 | 6 votes |
@SuppressWarnings ( "deprecation" ) protected void testCredentialUrl ( String url, String user, String pass, String dom ) throws SmbException, MalformedURLException { try ( SmbFile f = new SmbFile(url) ) { Credentials creds = f.getContext().getCredentials(); assertFalse(creds.isAnonymous()); assertFalse(creds.isGuest()); assertTrue(creds instanceof NtlmPasswordAuthenticator); NtlmPasswordAuthenticator ntcreds = (NtlmPasswordAuthenticator) creds; assertNotNull(ntcreds.getUsername()); assertEquals(user, ntcreds.getUsername()); assertNotNull(ntcreds.getUserDomain()); if ( dom != null ) { assertEquals(dom, ntcreds.getUserDomain()); } assertNotNull(ntcreds.getPassword()); assertEquals(pass, ntcreds.getPassword()); f.exists(); } }
Example #18
Source File: SessionTest.java From jcifs with GNU Lesser General Public License v2.1 | 6 votes |
@Test // BUG #14 public void testNoLeakRequestError () throws IOException { try ( SmbResource f = getDefaultShareRoot().resolve("doesnotexist") ) { try ( SmbTreeHandleInternal th = (SmbTreeHandleInternal) ( (SmbFile) f ).getTreeHandle(); SmbSessionInternal sess = th.getSession().unwrap(SmbSessionInternal.class); SmbTransportInternal t = (SmbTransportInternal) sess.getTransport() ) { assertEquals(0, t.getInflightRequests()); try ( InputStream is = f.openInputStream() ) { } catch ( SmbException e ) { // expected } assertEquals(0, t.getInflightRequests()); } } }
Example #19
Source File: ConcurrencyTest.java From jcifs with GNU Lesser General Public License v2.1 | 6 votes |
@Test public void testOpenReadLocked () throws IOException { String fname = makeRandomName(); try ( SmbFile sr = getDefaultShareRoot(); SmbResource exclFile = new SmbFile(sr, fname) ) { exclFile.createNewFile(); try { try ( InputStream is = exclFile.openInputStream(SmbConstants.FILE_NO_SHARE); InputStream is2 = exclFile.openInputStream(SmbConstants.FILE_NO_SHARE) ) { fail("No sharing violation"); } catch ( SmbException e ) { if ( e.getNtStatus() == NtStatus.NT_STATUS_SHARING_VIOLATION ) { return; } throw e; } } finally { exclFile.delete(); } } }
Example #20
Source File: ConcurrencyTest.java From jcifs with GNU Lesser General Public License v2.1 | 6 votes |
@Test public void testOpenLocked () throws IOException { String fname = makeRandomName(); try ( SmbFile sr = getDefaultShareRoot(); SmbResource exclFile = new SmbFile(sr, fname) ) { try ( OutputStream s = exclFile.openOutputStream(false, SmbConstants.FILE_NO_SHARE); InputStream is = exclFile.openInputStream(SmbConstants.FILE_NO_SHARE) ) { fail("No sharing violation"); } catch ( SmbException e ) { if ( e.getNtStatus() == NtStatus.NT_STATUS_SHARING_VIOLATION ) { return; } throw e; } finally { exclFile.delete(); } } }
Example #21
Source File: ConcurrencyTest.java From jcifs with GNU Lesser General Public License v2.1 | 6 votes |
@Test public void testDeleteLocked () throws IOException { String fname = makeRandomName(); try ( SmbFile sr = getDefaultShareRoot(); SmbResource exclFile = new SmbFile(sr, fname) ) { try ( OutputStream s = exclFile.openOutputStream(false, SmbConstants.FILE_NO_SHARE) ) { try { exclFile.delete(); fail("Could remove locked file"); } catch ( SmbException e ) { if ( e.getNtStatus() == NtStatus.NT_STATUS_SHARING_VIOLATION ) { return; } throw e; } } finally { exclFile.delete(); } } }
Example #22
Source File: ConcurrencyTest.java From jcifs-ng with GNU Lesser General Public License v2.1 | 6 votes |
@Test public void testDeleteLocked () throws IOException { String fname = makeRandomName(); try ( SmbFile sr = getDefaultShareRoot(); SmbResource exclFile = new SmbFile(sr, fname) ) { try ( OutputStream s = exclFile.openOutputStream(false, SmbConstants.FILE_NO_SHARE) ) { try { exclFile.delete(); fail("Could remove locked file"); } catch ( SmbException e ) { if ( e.getNtStatus() == NtStatus.NT_STATUS_SHARING_VIOLATION ) { return; } throw e; } } finally { exclFile.delete(); } } }
Example #23
Source File: ConcurrencyTest.java From jcifs-ng with GNU Lesser General Public License v2.1 | 6 votes |
@Test public void testOpenReadLocked () throws IOException { String fname = makeRandomName(); try ( SmbFile sr = getDefaultShareRoot(); SmbResource exclFile = new SmbFile(sr, fname) ) { exclFile.createNewFile(); try { try ( InputStream is = exclFile.openInputStream(SmbConstants.FILE_NO_SHARE); InputStream is2 = exclFile.openInputStream(SmbConstants.FILE_NO_SHARE) ) { fail("No sharing violation"); } catch ( SmbException e ) { if ( e.getNtStatus() == NtStatus.NT_STATUS_SHARING_VIOLATION ) { return; } throw e; } } finally { exclFile.delete(); } } }
Example #24
Source File: SessionTest.java From jcifs-ng with GNU Lesser General Public License v2.1 | 6 votes |
@SuppressWarnings ( "deprecation" ) protected void testCredentialUrl ( String url, String user, String pass, String dom ) throws SmbException, MalformedURLException { try ( SmbFile f = new SmbFile(url) ) { Credentials creds = f.getContext().getCredentials(); assertFalse(creds.isAnonymous()); assertFalse(creds.isGuest()); assertTrue(creds instanceof NtlmPasswordAuthenticator); NtlmPasswordAuthenticator ntcreds = (NtlmPasswordAuthenticator) creds; assertNotNull(ntcreds.getUsername()); assertEquals(user, ntcreds.getUsername()); assertNotNull(ntcreds.getUserDomain()); if ( dom != null ) { assertEquals(dom, ntcreds.getUserDomain()); } assertNotNull(ntcreds.getPassword()); assertEquals(pass, ntcreds.getPassword()); f.exists(); } }
Example #25
Source File: SamrAliasHandle.java From jcifs-ng with GNU Lesser General Public License v2.1 | 5 votes |
public SamrAliasHandle ( DcerpcHandle handle, SamrDomainHandle domainHandle, int access, int rid ) throws IOException { this.handle = handle; MsrpcSamrOpenAlias rpc = new MsrpcSamrOpenAlias(domainHandle, access, rid, this); handle.sendrecv(rpc); if ( rpc.retval != 0 ) { throw new SmbException(rpc.retval, false); } this.opened = true; }
Example #26
Source File: SmbFileObject.java From commons-vfs with Apache License 2.0 | 5 votes |
/** * Creates an input stream to read the file content from. */ @Override protected InputStream doGetInputStream(final int bufferSize) throws Exception { try { return new SmbFileInputStream(file); } catch (final SmbException e) { if (e.getNtStatus() == SmbException.NT_STATUS_NO_SUCH_FILE) { throw new org.apache.commons.vfs2.FileNotFoundException(getName()); } else if (file.isDirectory()) { throw new FileTypeHasNoContentException(getName()); } throw e; } }
Example #27
Source File: SMBFileInfo.java From CloverETL-Engine with GNU Lesser General Public License v2.1 | 5 votes |
@Override public Date getLastModified() { try { return new Date(file.lastModified()); } catch (SmbException e) { throw new JetelRuntimeException(e); } }
Example #28
Source File: Smb2IoctlResponse.java From jcifs-ng with GNU Lesser General Public License v2.1 | 5 votes |
/** * @param responseType * @return decoded data * @throws SmbException */ @SuppressWarnings ( "unchecked" ) public <T extends Decodable> T getOutputData ( Class<T> responseType ) throws SmbException { Decodable out = getOutputData(); if ( out == null ) { throw new SmbException("Failed to decode output data"); } if ( !responseType.isAssignableFrom(out.getClass()) ) { throw new SmbException("Incompatible response data " + out.getClass()); } return (T) out; }
Example #29
Source File: Samba1FileSystem.java From iaf with Apache License 2.0 | 5 votes |
public boolean isFolder(SmbFile f) throws FileSystemException { try { return f.isDirectory(); } catch (SmbException e) { throw new FileSystemException(e); } }
Example #30
Source File: SessionTest.java From jcifs-ng with GNU Lesser General Public License v2.1 | 5 votes |
@Test public void testCredentialURLs () throws MalformedURLException, SmbException { try { testCredentialUrl( String.format("smb://%s:%s@%s/%s/doesnotexist", getTestUser(), getTestUserPassword(), getTestServer(), getTestShare()), getTestUser(), getTestUserPassword(), null); if ( getTestUserDomain() != null ) { testCredentialUrl( String.format( "smb://%s;%s:%s@%s/%s/doesnotexist", getTestUserDomain(), getTestUser(), getTestUserPassword(), getTestServer(), getTestShare()), getTestUser(), getTestUserPassword(), getTestUserDomain()); } } catch ( SmbException e ) { // no setup to resolve hostname if netbios is used if ( e.getCause() instanceof UnknownHostException ) { Assume.assumeTrue(false); } throw e; } }