java.nio.file.ClosedDirectoryStreamException Java Examples

The following examples show how to use java.nio.file.ClosedDirectoryStreamException. 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 Project: jimfs   Author: google   File: JimfsFileSystemCloseTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testOpenDirectoryStreamsClosed() throws IOException {
  Path p = fs.getPath("/foo");
  Files.createDirectory(p);

  try (DirectoryStream<Path> stream = Files.newDirectoryStream(p)) {

    fs.close();

    try {
      stream.iterator();
      fail();
    } catch (ClosedDirectoryStreamException expected) {
    }
  }
}
 
Example #2
Source Project: dragonwell8_jdk   Author: alibaba   File: ZipDirectoryStream.java    License: GNU General Public License v2.0 5 votes vote down vote up
@Override
public synchronized Iterator<Path> iterator() {
    if (isClosed)
        throw new ClosedDirectoryStreamException();
    if (itr != null)
        throw new IllegalStateException("Iterator has already been returned");

    try {
        itr = zipfs.iteratorOf(path, filter);
    } catch (IOException e) {
        throw new IllegalStateException(e);
    }
    return new Iterator<Path>() {
        private Path next;
        @Override
        public boolean hasNext() {
            if (isClosed)
                return false;
            return itr.hasNext();
        }

        @Override
        public synchronized Path next() {
            if (isClosed)
                throw new NoSuchElementException();
            return itr.next();
        }

        @Override
        public void remove() {
            throw new UnsupportedOperationException();
        }
    };
}
 
Example #3
Source Project: TencentKona-8   Author: Tencent   File: ZipDirectoryStream.java    License: GNU General Public License v2.0 5 votes vote down vote up
@Override
public synchronized Iterator<Path> iterator() {
    if (isClosed)
        throw new ClosedDirectoryStreamException();
    if (itr != null)
        throw new IllegalStateException("Iterator has already been returned");

    try {
        itr = zipfs.iteratorOf(path, filter);
    } catch (IOException e) {
        throw new IllegalStateException(e);
    }
    return new Iterator<Path>() {
        private Path next;
        @Override
        public boolean hasNext() {
            if (isClosed)
                return false;
            return itr.hasNext();
        }

        @Override
        public synchronized Path next() {
            if (isClosed)
                throw new NoSuchElementException();
            return itr.next();
        }

        @Override
        public void remove() {
            throw new UnsupportedOperationException();
        }
    };
}
 
Example #4
Source Project: jdk8u60   Author: chenghanpeng   File: ZipDirectoryStream.java    License: GNU General Public License v2.0 5 votes vote down vote up
@Override
public synchronized Iterator<Path> iterator() {
    if (isClosed)
        throw new ClosedDirectoryStreamException();
    if (itr != null)
        throw new IllegalStateException("Iterator has already been returned");

    try {
        itr = zipfs.iteratorOf(path, filter);
    } catch (IOException e) {
        throw new IllegalStateException(e);
    }
    return new Iterator<Path>() {
        private Path next;
        @Override
        public boolean hasNext() {
            if (isClosed)
                return false;
            return itr.hasNext();
        }

        @Override
        public synchronized Path next() {
            if (isClosed)
                throw new NoSuchElementException();
            return itr.next();
        }

        @Override
        public void remove() {
            throw new UnsupportedOperationException();
        }
    };
}
 
Example #5
Source Project: openjdk-jdk8u   Author: AdoptOpenJDK   File: ZipDirectoryStream.java    License: GNU General Public License v2.0 5 votes vote down vote up
@Override
public synchronized Iterator<Path> iterator() {
    if (isClosed)
        throw new ClosedDirectoryStreamException();
    if (itr != null)
        throw new IllegalStateException("Iterator has already been returned");

    try {
        itr = zipfs.iteratorOf(path, filter);
    } catch (IOException e) {
        throw new IllegalStateException(e);
    }
    return new Iterator<Path>() {
        private Path next;
        @Override
        public boolean hasNext() {
            if (isClosed)
                return false;
            return itr.hasNext();
        }

        @Override
        public synchronized Path next() {
            if (isClosed)
                throw new NoSuchElementException();
            return itr.next();
        }

        @Override
        public void remove() {
            throw new UnsupportedOperationException();
        }
    };
}
 
Example #6
Source Project: openjdk-jdk8u-backup   Author: AdoptOpenJDK   File: ZipDirectoryStream.java    License: GNU General Public License v2.0 5 votes vote down vote up
@Override
public synchronized Iterator<Path> iterator() {
    if (isClosed)
        throw new ClosedDirectoryStreamException();
    if (itr != null)
        throw new IllegalStateException("Iterator has already been returned");

    try {
        itr = zipfs.iteratorOf(path, filter);
    } catch (IOException e) {
        throw new IllegalStateException(e);
    }
    return new Iterator<Path>() {
        private Path next;
        @Override
        public boolean hasNext() {
            if (isClosed)
                return false;
            return itr.hasNext();
        }

        @Override
        public synchronized Path next() {
            if (isClosed)
                throw new NoSuchElementException();
            return itr.next();
        }

        @Override
        public void remove() {
            throw new UnsupportedOperationException();
        }
    };
}
 
Example #7
Source Project: Bytecoder   Author: mirkosertic   File: JrtDirectoryStream.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public synchronized Iterator<Path> iterator() {
    if (isClosed)
        throw new ClosedDirectoryStreamException();
    if (itr != null)
        throw new IllegalStateException("Iterator has already been returned");
    try {
        itr = dir.jrtfs.iteratorOf(dir, filter);
    } catch (IOException e) {
        throw new IllegalStateException(e);
    }
    return new Iterator<Path>() {
        @Override
        public boolean hasNext() {
            synchronized (JrtDirectoryStream.this) {
                if (isClosed)
                    return false;
                return itr.hasNext();
            }
        }

        @Override
        public Path next() {
            synchronized (JrtDirectoryStream.this) {
                if (isClosed)
                    throw new NoSuchElementException();
                return itr.next();
            }
        }
    };
}
 
Example #8
Source Project: openjdk-jdk9   Author: AdoptOpenJDK   File: JrtDirectoryStream.java    License: GNU General Public License v2.0 5 votes vote down vote up
@Override
public synchronized Iterator<Path> iterator() {
    if (isClosed)
        throw new ClosedDirectoryStreamException();
    if (itr != null)
        throw new IllegalStateException("Iterator has already been returned");
    try {
        itr = dir.jrtfs.iteratorOf(dir, filter);
    } catch (IOException e) {
        throw new IllegalStateException(e);
    }
    return new Iterator<Path>() {
        @Override
        public boolean hasNext() {
            synchronized (JrtDirectoryStream.this) {
                if (isClosed)
                    return false;
                return itr.hasNext();
            }
        }

        @Override
        public Path next() {
            synchronized (JrtDirectoryStream.this) {
                if (isClosed)
                    throw new NoSuchElementException();
                return itr.next();
            }
        }
    };
}
 
Example #9
Source Project: openjdk-jdk9   Author: AdoptOpenJDK   File: ZipDirectoryStream.java    License: GNU General Public License v2.0 5 votes vote down vote up
@Override
public synchronized Iterator<Path> iterator() {
    if (isClosed)
        throw new ClosedDirectoryStreamException();
    if (itr != null)
        throw new IllegalStateException("Iterator has already been returned");

    try {
        itr = zipfs.iteratorOf(path, filter);
    } catch (IOException e) {
        throw new IllegalStateException(e);
    }
    return new Iterator<Path>() {
        private Path next;
        @Override
        public boolean hasNext() {
            if (isClosed)
                return false;
            return itr.hasNext();
        }

        @Override
        public synchronized Path next() {
            if (isClosed)
                throw new NoSuchElementException();
            return itr.next();
        }

        @Override
        public void remove() {
            throw new UnsupportedOperationException();
        }
    };
}
 
Example #10
Source Project: jdk8u-jdk   Author: lambdalab-mirror   File: ZipDirectoryStream.java    License: GNU General Public License v2.0 5 votes vote down vote up
@Override
public synchronized Iterator<Path> iterator() {
    if (isClosed)
        throw new ClosedDirectoryStreamException();
    if (itr != null)
        throw new IllegalStateException("Iterator has already been returned");

    try {
        itr = zipfs.iteratorOf(path, filter);
    } catch (IOException e) {
        throw new IllegalStateException(e);
    }
    return new Iterator<Path>() {
        private Path next;
        @Override
        public boolean hasNext() {
            if (isClosed)
                return false;
            return itr.hasNext();
        }

        @Override
        public synchronized Path next() {
            if (isClosed)
                throw new NoSuchElementException();
            return itr.next();
        }

        @Override
        public void remove() {
            throw new UnsupportedOperationException();
        }
    };
}
 
Example #11
Source Project: hottub   Author: dsrg-uoft   File: ZipDirectoryStream.java    License: GNU General Public License v2.0 5 votes vote down vote up
@Override
public synchronized Iterator<Path> iterator() {
    if (isClosed)
        throw new ClosedDirectoryStreamException();
    if (itr != null)
        throw new IllegalStateException("Iterator has already been returned");

    try {
        itr = zipfs.iteratorOf(path, filter);
    } catch (IOException e) {
        throw new IllegalStateException(e);
    }
    return new Iterator<Path>() {
        private Path next;
        @Override
        public boolean hasNext() {
            if (isClosed)
                return false;
            return itr.hasNext();
        }

        @Override
        public synchronized Path next() {
            if (isClosed)
                throw new NoSuchElementException();
            return itr.next();
        }

        @Override
        public void remove() {
            throw new UnsupportedOperationException();
        }
    };
}
 
Example #12
Source Project: openjdk-8-source   Author: keerath   File: ZipDirectoryStream.java    License: GNU General Public License v2.0 5 votes vote down vote up
@Override
public synchronized Iterator<Path> iterator() {
    if (isClosed)
        throw new ClosedDirectoryStreamException();
    if (itr != null)
        throw new IllegalStateException("Iterator has already been returned");

    try {
        itr = zipfs.iteratorOf(path, filter);
    } catch (IOException e) {
        throw new IllegalStateException(e);
    }
    return new Iterator<Path>() {
        private Path next;
        @Override
        public boolean hasNext() {
            if (isClosed)
                return false;
            return itr.hasNext();
        }

        @Override
        public synchronized Path next() {
            if (isClosed)
                throw new NoSuchElementException();
            return itr.next();
        }

        @Override
        public void remove() {
            throw new UnsupportedOperationException();
        }
    };
}
 
Example #13
Source Project: openjdk-8   Author: bpupadhyaya   File: ZipDirectoryStream.java    License: GNU General Public License v2.0 5 votes vote down vote up
@Override
public synchronized Iterator<Path> iterator() {
    if (isClosed)
        throw new ClosedDirectoryStreamException();
    if (itr != null)
        throw new IllegalStateException("Iterator has already been returned");

    try {
        itr = zipfs.iteratorOf(path, filter);
    } catch (IOException e) {
        throw new IllegalStateException(e);
    }
    return new Iterator<Path>() {
        private Path next;
        @Override
        public boolean hasNext() {
            if (isClosed)
                return false;
            return itr.hasNext();
        }

        @Override
        public synchronized Path next() {
            if (isClosed)
                throw new NoSuchElementException();
            return itr.next();
        }

        @Override
        public void remove() {
            throw new UnsupportedOperationException();
        }
    };
}
 
Example #14
Source Project: jdk8u_jdk   Author: JetBrains   File: ZipDirectoryStream.java    License: GNU General Public License v2.0 5 votes vote down vote up
@Override
public synchronized Iterator<Path> iterator() {
    if (isClosed)
        throw new ClosedDirectoryStreamException();
    if (itr != null)
        throw new IllegalStateException("Iterator has already been returned");

    try {
        itr = zipfs.iteratorOf(path, filter);
    } catch (IOException e) {
        throw new IllegalStateException(e);
    }
    return new Iterator<Path>() {
        private Path next;
        @Override
        public boolean hasNext() {
            if (isClosed)
                return false;
            return itr.hasNext();
        }

        @Override
        public synchronized Path next() {
            if (isClosed)
                throw new NoSuchElementException();
            return itr.next();
        }

        @Override
        public void remove() {
            throw new UnsupportedOperationException();
        }
    };
}
 
Example #15
Source Project: jdk8u-jdk   Author: frohoff   File: ZipDirectoryStream.java    License: GNU General Public License v2.0 5 votes vote down vote up
@Override
public synchronized Iterator<Path> iterator() {
    if (isClosed)
        throw new ClosedDirectoryStreamException();
    if (itr != null)
        throw new IllegalStateException("Iterator has already been returned");

    try {
        itr = zipfs.iteratorOf(path, filter);
    } catch (IOException e) {
        throw new IllegalStateException(e);
    }
    return new Iterator<Path>() {
        private Path next;
        @Override
        public boolean hasNext() {
            if (isClosed)
                return false;
            return itr.hasNext();
        }

        @Override
        public synchronized Path next() {
            if (isClosed)
                throw new NoSuchElementException();
            return itr.next();
        }

        @Override
        public void remove() {
            throw new UnsupportedOperationException();
        }
    };
}
 
Example #16
Source Project: jdk8u-dev-jdk   Author: frohoff   File: ZipDirectoryStream.java    License: GNU General Public License v2.0 5 votes vote down vote up
@Override
public synchronized Iterator<Path> iterator() {
    if (isClosed)
        throw new ClosedDirectoryStreamException();
    if (itr != null)
        throw new IllegalStateException("Iterator has already been returned");

    try {
        itr = zipfs.iteratorOf(path, filter);
    } catch (IOException e) {
        throw new IllegalStateException(e);
    }
    return new Iterator<Path>() {
        private Path next;
        @Override
        public boolean hasNext() {
            if (isClosed)
                return false;
            return itr.hasNext();
        }

        @Override
        public synchronized Path next() {
            if (isClosed)
                throw new NoSuchElementException();
            return itr.next();
        }

        @Override
        public void remove() {
            throw new UnsupportedOperationException();
        }
    };
}
 
Example #17
Source Project: mycore   Author: MyCoRe-Org   File: MCRDirectoryStream.java    License: GNU General Public License v3.0 4 votes vote down vote up
void checkClosed() {
    if (isClosed) {
        throw new ClosedDirectoryStreamException();
    }
}
 
Example #18
Source Project: mycore   Author: MyCoRe-Org   File: MCRDirectoryStream.java    License: GNU General Public License v3.0 4 votes vote down vote up
void checkClosed() {
    if (dir == null) {
        throw new ClosedDirectoryStreamException();
    }
}
 
Example #19
Source Project: ParallelGit   Author: beijunyi   File: GfsDirectoryStream.java    License: Apache License 2.0 4 votes vote down vote up
@Nonnull
@Override
public Iterator<Path> iterator() {
  final Iterator<String> childrenIt = children.iterator();
  return new Iterator<Path>() {

    private Path next;

    private boolean findNext() {
      while(childrenIt.hasNext()) {
        String child = childrenIt.next();
        GitPath childPath = parent.resolve(child);
        try {
          if(filter == null || filter.accept(childPath)) {
            next = childPath;
            return true;
          }
        } catch(IOException ignore) {
        }
      }
      return false;
    }

    @Override
    public boolean hasNext() throws ClosedDirectoryStreamException {
      checkNotClosed();
      return next != null || findNext();
    }

    @Nonnull
    @Override
    public Path next() throws ClosedDirectoryStreamException, NoSuchElementException {
      checkNotClosed();
      if(next != null || hasNext()) {
        Path ret = next;
        next = null;
        return ret;
      }
      throw new NoSuchElementException();
    }

    @Override
    public void remove() throws UnsupportedOperationException {
      throw new UnsupportedOperationException();
    }
  };
}
 
Example #20
Source Project: ParallelGit   Author: beijunyi   File: GfsDirectoryStream.java    License: Apache License 2.0 4 votes vote down vote up
private void checkNotClosed() throws ClosedDirectoryStreamException {
  if(closed)
    throw new ClosedDirectoryStreamException();
}
 
Example #21
Source Project: ParallelGit   Author: beijunyi   File: GfsDirectoryStream.java    License: Apache License 2.0 4 votes vote down vote up
@Nonnull
@Override
public Iterator<Path> iterator() {
  final Iterator<String> childrenIt = children.iterator();
  return new Iterator<Path>() {

    private Path next;

    private boolean findNext() {
      while(childrenIt.hasNext()) {
        String child = childrenIt.next();
        GitPath childPath = parent.resolve(child);
        try {
          if(filter == null || filter.accept(childPath)) {
            next = childPath;
            return true;
          }
        } catch(IOException ignore) {
        }
      }
      return false;
    }

    @Override
    public boolean hasNext() throws ClosedDirectoryStreamException {
      checkNotClosed();
      return next != null || findNext();
    }

    @Nonnull
    @Override
    public Path next() throws ClosedDirectoryStreamException, NoSuchElementException {
      checkNotClosed();
      if(next != null || hasNext()) {
        Path ret = next;
        next = null;
        return ret;
      }
      throw new NoSuchElementException();
    }

    @Override
    public void remove() throws UnsupportedOperationException {
      throw new UnsupportedOperationException();
    }
  };
}
 
Example #22
Source Project: ParallelGit   Author: beijunyi   File: GfsDirectoryStream.java    License: Apache License 2.0 4 votes vote down vote up
private void checkNotClosed() throws ClosedDirectoryStreamException {
  if(closed)
    throw new ClosedDirectoryStreamException();
}
 
Example #23
Source Project: jimfs   Author: google   File: JimfsSecureDirectoryStream.java    License: Apache License 2.0 4 votes vote down vote up
protected synchronized void checkOpen() {
  if (!open) {
    throw new ClosedDirectoryStreamException();
  }
}