Java Stream Close close(Iterator iterator)

Here you can find the source of close(Iterator iterator)

Description

Checks if the provided iterator implements Closeable .

License

Open Source License

Declaration

public static void close(Iterator<?> iterator) 

Method Source Code


//package com.java2s;
/*//from  w  w  w . j  a  va  2  s.  c o m
 *    GeoTools - The Open Source Java GIS Toolkit
 *    http://geotools.org
 * 
 *    (C) 2003-2008, Open Source Geospatial Foundation (OSGeo)
 *    
 *    This library is free software; you can redistribute it and/or
 *    modify it under the terms of the GNU Lesser General Public
 *    License as published by the Free Software Foundation;
 *    version 2.1 of the License.
 *
 *    This library 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
 *    Lesser General Public License for more details.
 */

import java.io.Closeable;

import java.io.IOException;

import java.util.Iterator;

import java.util.logging.Level;
import java.util.logging.Logger;

public class Main {
    /**
     * Checks if the provided iterator implements {@link Closeable}.
     * <p>
     * Any problems are logged at {@link Level#FINE}.
     */
    public static void close(Iterator<?> iterator) {
        if (iterator != null && iterator instanceof Closeable) {
            try {
                ((Closeable) iterator).close();
            } catch (IOException e) {
                String name = iterator.getClass().getPackage().toString();
                Logger log = Logger.getLogger(name);
                log.log(Level.FINE, e.getMessage(), e);
            }
        }
    }
}

Related

  1. close(final InputStream stream)
  2. close(final Logger logger, final Closeable... closeables)
  3. close(final Object stream)
  4. close(final OutputStream dest)
  5. close(final Scanner scanner)
  6. close(java.io.Closeable in)
  7. close(JMXConnector connector)
  8. close(Object obj)
  9. close(Object resource)