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.lightboxtechnologies.nsrl.RecordLoader.java

public void load(String filename, LineHandler lh) throws IOException {
    Reader r = null;
    try {/*ww  w  .  j  a v a  2s .  c o m*/
        r = new FileReader(filename);
        load(r, lh);
        r.close();
    } finally {
        IOUtils.closeQuietly(r);
    }
}

From source file:com.norconex.importer.handler.transformer.impl.ReplaceTransformerTest.java

@Test
public void testTransformTextDocument() throws IOException, ImporterHandlerException {
    String text = "I like to eat cakes and candies.";

    ReplaceTransformer t = new ReplaceTransformer();

    Reader reader = new InputStreamReader(IOUtils.toInputStream(xml));
    t.loadFromXML(reader);/*from w w  w . jav a  2s.co m*/
    reader.close();

    InputStream is = IOUtils.toInputStream(text);
    ByteArrayOutputStream os = new ByteArrayOutputStream();
    t.transformDocument("dummyRef", is, os, new ImporterMetadata(), true);

    String response = os.toString();
    System.out.println(response);
    Assert.assertEquals("i like to eat fruits and vegetables.", response.toLowerCase());

    is.close();
    os.close();
}

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

public void load(InputStream in, LineHandler lh) throws IOException {
    Reader r = null;
    try {/*from w ww  .  ja v  a2s .  c  om*/
        r = new InputStreamReader(in);
        load(r, lh);
        r.close();
    } finally {
        IOUtils.closeQuietly(r);
    }
}

From source file:org.n52.car.io.RESTConnectionTest.java

private void assertReader(Reader data) throws IOException {
    Assert.assertThat(data, is(notNullValue()));
    Assert.assertThat(data.read(), is(not(-1)));

    data.close();
}

From source file:com.bumptech.glide.disklrucache.DiskLruCacheTest.java

private static String readFile(File file) throws Exception {
    Reader reader = new FileReader(file);
    StringWriter writer = new StringWriter();
    char[] buffer = new char[1024];
    int count;//from   ww w .  j ava 2s.  co m
    while ((count = reader.read(buffer)) != -1) {
        writer.write(buffer, 0, count);
    }
    reader.close();
    return writer.toString();
}

From source file:cherry.windows.charset.TableParser.java

public List<Entry> parse(String name) throws IOException {
    InputStream in = getClass().getClassLoader().getResourceAsStream(name);
    Reader reader = new InputStreamReader(in);
    try {/* w w w . java  2  s. c  o  m*/
        return parse(reader);
    } finally {
        reader.close();
    }
}

From source file:com.github.magicsky.sya.checkers.TestSourceReader.java

/**
 * Searches for the offset of the first occurrence of a string in a workspace file.
 *
 * @param lookfor  string to be searched for
 * @param fullPath full path of the workspace file
 * @return the offset or -1//ww w.  ja  v a 2  s .  c om
 * @throws Exception
 * @throws UnsupportedEncodingException
 * @since 4.0
 */
public static int indexOfInFile(String lookfor, Path fullPath) throws Exception {
    IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(fullPath);
    Reader reader = new BufferedReader(new InputStreamReader(file.getContents(), file.getCharset()));
    Assert.assertTrue(lookfor.indexOf('\n') == -1);
    try {
        int c = 0;
        int offset = 0;
        StringBuilder buf = new StringBuilder();
        while ((c = reader.read()) >= 0) {
            buf.append((char) c);
            if (c == '\n') {
                int idx = buf.indexOf(lookfor);
                if (idx >= 0) {
                    return idx + offset;
                }
                offset += buf.length();
                buf.setLength(0);
            }
        }
        int idx = buf.indexOf(lookfor);
        if (idx >= 0) {
            return idx + offset;
        }
        return -1;
    } finally {
        reader.close();
    }
}

From source file:retrofit.JacksonResponseBodyConverter.java

@Override
public T convert(ResponseBody value) throws IOException {
    Reader reader = value.charStream();
    try {/*from w ww.  j  a  v  a2  s . c  om*/
        return adapter.readValue(reader);
    } finally {
        if (reader != null) {
            try {
                reader.close();
            } catch (IOException ignored) {
            }
        }
    }
}

From source file:edu.cornell.mannlib.vitro.webapp.utils.Html2Text.java

public void parse(String in) throws IOException {
    Reader r = new StringReader(in);
    try {/*from   w w w  .j  a v  a 2 s  .c o  m*/
        parse(r);
    } catch (IOException e) {
        log.error("could not strip html", e);
    } finally {
        r.close();
    }
}

From source file:org.callimachusproject.xml.XdmNodeFactory.java

public XdmNode parse(String systemId) throws SAXException, IOException {
    InputSource isource = resolveEntity(null, systemId);
    if (isource == null)
        return null;
    try {/*from w  w w  .j a  v  a  2 s.c  o m*/
        return parse(isource);
    } finally {
        InputStream in = isource.getByteStream();
        if (in != null) {
            in.close();
        }
        Reader reader = isource.getCharacterStream();
        if (reader != null) {
            reader.close();
        }
    }
}