Java Code Examples for jcifs.smb.NtStatus#NT_STATUS_SHARING_VIOLATION

The following examples show how to use jcifs.smb.NtStatus#NT_STATUS_SHARING_VIOLATION . 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: 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 5
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 6
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();
        }
    }
}