Example usage for java.io Reader close

List of usage examples for java.io Reader close

Introduction

In this page you can find the example usage for java.io Reader close.

Prototype

public abstract void close() throws IOException;

Source Link

Document

Closes the stream and releases any system resources associated with it.

Usage

From source file:com.neocotic.blingaer.common.IOUtils.java

/**
 * Unconditionally closes an the {@code Reader} provided.
 * <p>//from  w w w  .  ja v  a  2 s  .c o  m
 * Does nothing if {@code input} is {@code null} or already closed and
 * ignores any {@code Exceptions} that may be thrown while closing.
 * 
 * @param input
 *            the {@code Reader} to close
 * @see Reader#close()
 */
public static void closeQuietly(Reader input) {
    if (input != null) {
        try {
            input.close();
        } catch (Exception e) {
            // Ignorance is bliss
        }
    }
}

From source file:jfix.zk.Medias.java

public static String asString(Media media) {
    try {//w  ww  .  j a va 2  s  . c om
        String result = null;
        if (media.isBinary()) {
            InputStream input = Medias.asStream(media);
            result = IOUtils.toString(input, "UTF-8");
            input.close();
        } else {
            Reader reader = Medias.asReader(media);
            result = IOUtils.toString(reader);
            reader.close();
        }
        return result;
    } catch (Exception e) {
        throw new RuntimeException(e.getMessage(), e);
    }
}

From source file:org.jenkinsci.plugins.jacksondatabind.JSONReadWrite.java

public static <T> T fromInputStream(InputStream inputStream, Class<T> to) throws IOException {
    Reader reader = new InputStreamReader(inputStream, UTF8);
    try {//from www.  j a va2  s .c  om
        return fromReader(reader, to);
    } finally {
        reader.close();
    }
}

From source file:net.emphased.lastcontact.CookieFileStore.java

public static CookieFileStore load(File file) throws IOException, CookieFileStoreException {
    Reader reader = new FileReader(file);
    try {/*  w  w  w .  j  av  a2 s.c o m*/
        return load(reader);
    } finally {
        reader.close();
    }
}

From source file:Main.java

/**
 * Parses the given {@link File} with the specified {@link XMLReader}.
 * //from  w  ww  .  j ava2s. c  o  m
 * <p>This method assumes the XML is in 'UTF-8', it will not sniff the XML to
 * determine the encoding to use.
 * 
 * @param xmlreader The XML reader to use.
 * @param file      The file to parse
 * 
 * @throws FileNotFoundException If the file does not exists
 * @throws SAXException          Should an SAX exception occur
 * @throws IOException           Should an I/O exception occur
 */
public static void parse(XMLReader xmlreader, File file)
        throws FileNotFoundException, SAXException, IOException {
    // create the input source
    InputStream bin = new BufferedInputStream(new FileInputStream(file));
    Reader reader = new InputStreamReader(bin, "utf-8");
    InputSource source = new InputSource(reader);
    // parse the file
    xmlreader.parse(source);
    reader.close();
}

From source file:StreamConverter.java

static String readInput() {

    StringBuffer buffer = new StringBuffer();
    try {//from  w  w  w  .  j a  v  a2  s .  c o  m
        FileInputStream fis = new FileInputStream("test.txt");
        InputStreamReader isr = new InputStreamReader(fis, "UTF8");
        Reader in = new BufferedReader(isr);
        int ch;
        while ((ch = in.read()) > -1) {
            buffer.append((char) ch);
        }
        in.close();
        return buffer.toString();
    } catch (IOException e) {
        e.printStackTrace();
        return null;
    }
}

From source file:com.google.mr4c.config.site.MR4CSite.java

private static void loadSiteConfig() throws IOException {
    URI siteConf = findSiteConf();
    s_log.info("Reading site config from [{}]", siteConf);
    ConfigSerializer ser = SerializerFactories.getSerializerFactory("application/json")
            .createConfigSerializer(); // assume json config for now
    Reader reader = ContentFactories.readContentAsReader(siteConf);
    try {/*from   www . j  av  a 2s.c  o  m*/
        s_config = ser.deserializeSiteConfig(reader);
    } finally {
        reader.close();
    }
}

From source file:com.lightboxtechnologies.nsrl.SmallTableLoader.java

protected static void load(String filename, LineHandler lh, RecordLoader loader) throws IOException {
    Reader r = null;
    try {//from   ww  w  .  j a va2  s.com
        r = new FileReader(filename);
        loader.load(r, lh);
        r.close();
    } finally {
        IOUtils.closeQuietly(r);
    }
}

From source file:Main.java

public static boolean isValidXML(String xml) {
    try {//w  ww. j a v  a  2 s  .  c o m
        DocumentBuilder builder = dbf.newDocumentBuilder();
        Reader reader = null;
        try {
            reader = new StringReader(xml);
            builder.parse(new InputSource(reader));
        } finally {
            if (reader != null) {
                reader.close();
            }
        }
        return true;
    } catch (Exception e) {
        return false;
    }
}

From source file:org.cloudfoundry.maven.common.CommonUtils.java

/**
 * @param reader//  w w w .  j a  v a2 s .com
 */
public static void closeReader(Reader reader) {
    if (reader != null) {
        try {
            reader.close();
        } catch (IOException e) {
            throw new IllegalStateException("Encountered problem closing Reader.", e);
        }
    }
}