SBC.java revision 3471
/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/* @test
* @bug 4313887
* @summary Unit test for java.nio.file.Files.newByteChannel
* @library ..
*/
public class SBC {
static boolean supportsLinks;
try {
// open options
// SeekableByteChannel methods
// platform specific
// misc. tests
} finally {
}
}
// test CREATE and CREATE_NEW options
// CREATE
try {
// create file (no existing file)
throw new RuntimeException("File not created");
// create file (existing file)
// create file where existing file is a sym link
if (supportsLinks) {
try {
// file already exists
// file does not exist
throw new RuntimeException("File not created");
} finally {
}
}
} finally {
}
// CREATE_NEW
try {
// create file
throw new RuntimeException("File not created");
// create should fail
try {
throw new RuntimeException("FileAlreadyExistsException not thrown");
} catch (FileAlreadyExistsException x) { }
// create should fail
if (supportsLinks) {
try {
try {
throw new RuntimeException("FileAlreadyExistsException not thrown");
} catch (FileAlreadyExistsException x) { }
} finally {
}
}
} finally {
}
// CREATE_NEW + SPARSE
try {
throw new RuntimeException("Unexpected size");
}
} finally {
}
}
// test APPEND option
try {
// "hello there" should be written to file
}
// check file
throw new RuntimeException("Unexpected file contents");
}
// check that read is not allowed
} catch (NonReadableChannelException x) {
}
} finally {
// clean-up
}
}
// test TRUNCATE_EXISTING option
try {
}
// re-open with truncate option
// write short message and check
}
throw new RuntimeException("Unexpected file contents");
}
// re-open with create + truncate option
// check file is of size 0L
if (size != 0L)
throw new RuntimeException("File not truncated");
}
} finally {
// clean-up
}
}
// test NOFOLLOW_LINKS option
if (!supportsLinks)
return;
try {
// ln -s foo link
// open with NOFOLLOW_LINKS option
try {
throw new RuntimeException();
} catch (IOException x) {
} finally {
}
} finally {
// clean-up
}
}
try {
throw new RuntimeException("Unexpected size");
// check size
throw new RuntimeException("Unexpected size");
// truncate (size and position should change)
throw new RuntimeException("Unexpected size");
throw new RuntimeException("Unexpected position");
// truncate (position should not change)
throw new RuntimeException("Unexpected size");
throw new RuntimeException("Unexpected position");
}
} finally {
}
}
// Windows specific options for the use by applications that really want
// to use legacy DOS sharing options
try {
// no sharing
{
try {
throw new RuntimeException("Sharing violation expected");
} catch (IOException ignore) { }
try {
throw new RuntimeException("Sharing violation expected");
} catch (IOException ignore) { }
try {
throw new RuntimeException("Sharing violation expected");
} catch (IOException ignore) { }
}
// read allowed
try {
throw new RuntimeException("Sharing violation expected");
} catch (IOException ignore) { }
try {
throw new RuntimeException("Sharing violation expected");
} catch (IOException ignore) { }
}
// write allowed
try {
throw new RuntimeException("Sharing violation expected");
} catch (IOException ignore) { }
try {
throw new RuntimeException("Sharing violation expected");
} catch (IOException ignore) { }
}
// delete allowed
try {
throw new RuntimeException("Sharing violation expected");
} catch (IOException ignore) { }
try {
throw new RuntimeException("Sharing violation expected");
} catch (IOException ignore) { }
}
} finally {
}
}
// invalid combinations of options
try {
throw new RuntimeException("IllegalArgumentException expected");
} catch (IllegalArgumentException x) { }
try {
throw new RuntimeException("IllegalArgumentException expected");
} catch (IllegalArgumentException x) { }
}
// unsupported operations
try {
throw new RuntimeException("UnsupportedOperationException expected");
} catch (UnsupportedOperationException e) { }
try {
throw new RuntimeException("UnsupportedOperationException expected");
} catch (UnsupportedOperationException e) { }
}
// null handling
try {
throw new RuntimeException("NullPointerException expected");
} catch (NullPointerException x) { }
try {
throw new RuntimeException("NullPointerException expected");
} catch (NullPointerException x) { }
try {
throw new RuntimeException("NullPointerException expected");
} catch (NullPointerException x) { }
try {
throw new RuntimeException("NullPointerException expected");
} catch (NullPointerException x) { }
try {
throw new RuntimeException("NullPointerException expected");
} catch (NullPointerException x) { }
try {
throw new RuntimeException("NullPointerException expected");
} catch (NullPointerException x) { }
try {
throw new RuntimeException("NullPointerException expected");
} catch (NullPointerException x) { }
}
while (buf.hasRemaining())
}
}