< prev index next >

src/share/demo/nio/zipfs/src/com/sun/nio/zipfs/ZipFileSystem.java

Print this page
rev 13714 : 8028480: (zipfs) NoSuchFileException on creating a file in ZipFileSystem with CREATE and WRITE
8034773: (zipfs) newOutputstream uses CREATE_NEW when no options specified
Summary: to open the new steram with appropricate open options
Reviewed-by:

*** 1,7 **** /* ! * Copyright (c) 2009, 2013, Oracle and/or its affiliates. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * --- 1,7 ---- /* ! * Copyright (c) 2009, 2019, Oracle and/or its affiliates. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: *
*** 495,514 **** --- 495,519 ---- { checkWritable(); boolean hasCreateNew = false; boolean hasCreate = false; boolean hasAppend = false; + boolean hasTruncate = false; for (OpenOption opt: options) { if (opt == READ) throw new IllegalArgumentException("READ not allowed"); if (opt == CREATE_NEW) hasCreateNew = true; if (opt == CREATE) hasCreate = true; if (opt == APPEND) hasAppend = true; + if (opt == TRUNCATE_EXISTING) + hasTruncate = true; } + if (hasAppend && hasTruncate) + throw new IllegalArgumentException("APPEND + TRUNCATE_EXISTING not allowed"); beginRead(); // only need a readlock, the "update()" will try { // try to obtain a writelock when the os is ensureOpen(); // being closed. Entry e = getEntry0(path); if (e != null) {
*** 556,565 **** --- 561,572 ---- if (option == null) throw new NullPointerException(); if (!(option instanceof StandardOpenOption)) throw new IllegalArgumentException(); } + if (options.contains(APPEND) && options.contains(TRUNCATE_EXISTING)) + throw new IllegalArgumentException("APPEND + TRUNCATE_EXISTING not allowed"); } // Returns a Writable/ReadByteChannel for now. Might consdier to use // newFileChannel() instead, which dump the entry data into a regular // file on the default file system and create a FileChannel on top of
*** 703,721 **** ensureOpen(); Entry e = getEntry0(path); if (forWrite) { checkWritable(); if (e == null) { ! if (!options.contains(StandardOpenOption.CREATE_NEW)) throw new NoSuchFileException(getString(path)); } else { ! if (options.contains(StandardOpenOption.CREATE_NEW)) throw new FileAlreadyExistsException(getString(path)); if (e.isDir()) throw new FileAlreadyExistsException("directory <" + getString(path) + "> exists"); } options.remove(StandardOpenOption.CREATE_NEW); // for tmpfile } else if (e == null || e.isDir()) { throw new NoSuchFileException(getString(path)); } --- 710,732 ---- ensureOpen(); Entry e = getEntry0(path); if (forWrite) { checkWritable(); if (e == null) { ! if (!options.contains(StandardOpenOption.CREATE) && ! !options.contains(StandardOpenOption.CREATE_NEW)) { throw new NoSuchFileException(getString(path)); + } } else { ! if (options.contains(StandardOpenOption.CREATE_NEW)) { throw new FileAlreadyExistsException(getString(path)); + } if (e.isDir()) throw new FileAlreadyExistsException("directory <" + getString(path) + "> exists"); } + options = new HashSet<>(options); options.remove(StandardOpenOption.CREATE_NEW); // for tmpfile } else if (e == null || e.isDir()) { throw new NoSuchFileException(getString(path)); }
< prev index next >