Java Code Examples for jcifs.smb.SmbException#getNtStatus()

The following examples show how to use jcifs.smb.SmbException#getNtStatus() . 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: ConcurrencyTest.java    From jcifs with GNU Lesser General Public License v2.1 6 votes vote down vote up
@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 2
Source File: ConcurrencyTest.java    From jcifs with GNU Lesser General Public License v2.1 6 votes vote down vote up
@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 3
Source File: ConcurrencyTest.java    From jcifs with GNU Lesser General Public License v2.1 6 votes vote down vote up
@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 4
Source File: ReadWriteTest.java    From jcifs with GNU Lesser General Public License v2.1 6 votes vote down vote up
@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 with GNU Lesser General Public License v2.1 6 votes vote down vote up
@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 6
Source File: ReadWriteTest.java    From jcifs with GNU Lesser General Public License v2.1 6 votes vote down vote up
@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 7
Source File: ReadWriteTest.java    From jcifs with GNU Lesser General Public License v2.1 6 votes vote down vote up
@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 8
Source File: ConcurrencyTest.java    From jcifs-ng with GNU Lesser General Public License v2.1 6 votes vote down vote up
@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 9
Source File: ConcurrencyTest.java    From jcifs-ng with GNU Lesser General Public License v2.1 6 votes vote down vote up
@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 10
Source File: ConcurrencyTest.java    From jcifs-ng with GNU Lesser General Public License v2.1 6 votes vote down vote up
@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 11
Source File: ReadWriteTest.java    From jcifs-ng with GNU Lesser General Public License v2.1 6 votes vote down vote up
@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 12
Source File: ReadWriteTest.java    From jcifs-ng with GNU Lesser General Public License v2.1 6 votes vote down vote up
@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 13
Source File: ReadWriteTest.java    From jcifs-ng with GNU Lesser General Public License v2.1 6 votes vote down vote up
@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 14
Source File: ReadWriteTest.java    From jcifs-ng with GNU Lesser General Public License v2.1 6 votes vote down vote up
@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 15
Source File: SmbFileObject.java    From commons-vfs with Apache License 2.0 5 votes vote down vote up
/**
 * 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 16
Source File: SMBOperationHandler.java    From CloverETL-Engine with GNU Lesser General Public License v2.1 4 votes vote down vote up
private static List<SmbFile> expand(SmbFile base, String part, boolean directory) throws IOException {
	if (base == null) {
		throw new NullPointerException("base"); //$NON-NLS-1$
	}
	if (!base.isDirectory()) {
		throw new IllegalArgumentException(MessageFormat.format(FileOperationMessages.getString("IOperationHandler.not_a_directory"), base)); //$NON-NLS-1$
	}
	
	base = ensureTrailingSlash(base);
	part = URIUtils.urlDecode(part);
	if (hasWildcards(part)) {
		SmbFile[] children;
		try {
			// Let's use cool SmbFile.listFiles(String) method which resolves exactly our (DOS) wildcards...
			children = base.listFiles(part);
		} catch (SmbException e) {
			// ... but it uses not so cool way of letting know that there are no files matching the pattern 
			if (e.getNtStatus() == NtStatus.NT_STATUS_NO_SUCH_FILE) {
				return Collections.emptyList(); // maybe this could be done on any SmbException
			} else {
				throw e;
			}
		}
		if (!directory) {
			return Arrays.asList(children);
		} else {
			List<SmbFile> dirsOnly = new ArrayList<SmbFile>(children.length);
			for (SmbFile child : children) {
				if (child.isDirectory()) {
					dirsOnly.add(child);
				}
			}
			return dirsOnly;
		}
	} else {
		SmbFile file = new SmbFile(base, part);
		if (file.exists()) {
			return Arrays.asList(file);
		} else {
			return new ArrayList<SmbFile>(0);
		}
	}
}