Java Code Examples for java.io.Reader.close()

The following are Jave code examples for showing how to use close() of the java.io.Reader class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: hadoop   File: RumenToSLSConverter.java   View Source Code Vote up 9 votes
private static void generateSLSLoadFile(String inputFile, String outputFile)
        throws IOException {
  Reader input = new FileReader(inputFile);
  try {
    Writer output = new FileWriter(outputFile);
    try {
      ObjectMapper mapper = new ObjectMapper();
      ObjectWriter writer = mapper.writerWithDefaultPrettyPrinter();
      Iterator<Map> i = mapper.readValues(
              new JsonFactory().createJsonParser(input), Map.class);
      while (i.hasNext()) {
        Map m = i.next();
        output.write(writer.writeValueAsString(createSLSJob(m)) + EOL);
      }
    } finally {
      output.close();
    }
  } finally {
    input.close();
  }
}
 
Example 2
Project: openjdk-jdk10   File: Basic.java   View Source Code Vote up 6 votes
static void copy(Reader src, Writer dst) throws IOException {
    int len;
    char[] buf = new char[1024];
    try {
        while ((len = src.read(buf)) != -1)
            dst.write(buf, 0, len);
    } finally {
        try {
            src.close();
        } catch (IOException ignored1) {
        } finally {
            try {
                dst.close();
            } catch (IOException ignored2) {
            }
        }
    }
}
 
Example 3
Project: boohee_v5.6   File: Util.java   View Source Code Vote up 6 votes
static String readFully(Reader reader) throws IOException {
    try {
        StringWriter writer = new StringWriter();
        char[] buffer = new char[1024];
        while (true) {
            int count = reader.read(buffer);
            if (count == -1) {
                break;
            }
            writer.write(buffer, 0, count);
        }
        String stringWriter = writer.toString();
        return stringWriter;
    } finally {
        reader.close();
    }
}
 
Example 4
Project: gate-core   File: TestRepositioningInfo.java   View Source Code Vote up 6 votes
/**
 * This method tests if Repositinioning Information works.
 * It creates a document using an xml file with preserveOriginalContent
 * and collectRepositioningInfo options keeping true and which has all
 * sorts of special entities like &amp, &quot etc. + it contains both
 * kind of unix and dos stype new line characters.  It then saves the
 * document to the temporary location on the disk using
 * "save preserving document format" option and then compares the contents of
 * both the original and the temporary document to see if they are equal.
 * @throws java.lang.Exception
 */
public void testRepositioningInfo() throws Exception {

  // here we need to save the document to the file
    String encoding = ((DocumentImpl)doc).getEncoding();
    File outputFile = File.createTempFile("test-inline1","xml");
    OutputStreamWriter writer = new OutputStreamWriter(new FileOutputStream(outputFile),encoding);
    writer.write(doc.toXml(null, true));
    writer.flush();
    writer.close();
    Reader readerForSource = new BomStrippingInputStreamReader(new URL(testFile).openStream(),encoding);
    Reader readerForDesti = new BomStrippingInputStreamReader(new FileInputStream(outputFile),encoding);
    while(true) {
      int input1 = readerForSource.read();
      int input2 = readerForDesti.read();
      if(input1 < 0 || input2 < 0) {
        assertTrue(input1 < 0 && input2 < 0);
        readerForSource.close();
        readerForDesti.close();
        outputFile.delete();
        return;
      } else {
        assertEquals(input1,input2);
      }
    }
}
 
Example 5
Project: jdk8u-jdk   File: CommandLine.java   View Source Code Vote up 6 votes
private static void loadCmdFile(String name, List args)
    throws IOException
{
    Reader r = new BufferedReader(new FileReader(name));
    StreamTokenizer st = new StreamTokenizer(r);
    st.resetSyntax();
    st.wordChars(' ', 255);
    st.whitespaceChars(0, ' ');
    st.commentChar('#');
    st.quoteChar('"');
    st.quoteChar('\'');
    while (st.nextToken() != st.TT_EOF) {
        args.add(st.sval);
    }
    r.close();
}
 
Example 6
Project: openjdk-jdk10   File: CommandLine.java   View Source Code Vote up 6 votes
private static void loadCmdFile(String name, List<String> args)
    throws IOException
{
    Reader r = new BufferedReader(new FileReader(name));
    StreamTokenizer st = new StreamTokenizer(r);
    st.resetSyntax();
    st.wordChars(' ', 255);
    st.whitespaceChars(0, ' ');
    st.commentChar('#');
    st.quoteChar('"');
    st.quoteChar('\'');
    while (st.nextToken() != StreamTokenizer.TT_EOF) {
        args.add(st.sval);
    }
    r.close();
}
 
Example 7
Project: Jupiter   File: Utils.java   View Source Code Vote up 6 votes
/**
* 
* @param reader リーダー
* 
* @return ファイルの内容
* 
* <p>readFile - Utils</p>
* 
* <p>fileで指定したファイルを読み込みます。</p>
* 
* Jupiter by Jupiter Development Team
* 
*/

  public static String readFile(Reader reader) throws IOException {
      BufferedReader br = new BufferedReader(reader);
      String temp;
      StringBuilder stringBuilder = new StringBuilder();
      temp = br.readLine();
      while (temp != null) {
          if (stringBuilder.length() != 0) {
              stringBuilder.append("\n");
          }
          stringBuilder.append(temp);
          temp = br.readLine();
      }
      br.close();
      reader.close();
      return stringBuilder.toString();
  }
 
Example 8
Project: JBKWeather   File: DiskLruCache.java   View Source Code Vote up 5 votes
/**
 * Returns the remainder of 'reader' as a string, closing it when done.
 */
public static String readFully(Reader reader) throws IOException {
    try {
        StringWriter writer = new StringWriter();
        char[] buffer = new char[1024];
        int count;
        while ((count = reader.read(buffer)) != -1) {
            writer.write(buffer, 0, count);
        }
        return writer.toString();
    } finally {
        reader.close();
    }
}
 
Example 9
Project: GifImageLoader   File: Util.java   View Source Code Vote up 5 votes
static String readFully(Reader reader) throws IOException {
	try {
		StringWriter writer = new StringWriter();
		char[] buffer = new char[1024];
		int count;
		while ((count = reader.read(buffer)) != -1) {
			writer.write(buffer, 0, count);
		}
		return writer.toString();
	} finally {
		reader.close();
	}
}
 
Example 10
Project: GitHub   File: Util.java   View Source Code Vote up 5 votes
static String readFully(Reader reader) throws IOException {
	try {
		StringWriter writer = new StringWriter();
		char[] buffer = new char[1024];
		int count;
		while ((count = reader.read(buffer)) != -1) {
			writer.write(buffer, 0, count);
		}
		return writer.toString();
	} finally {
		reader.close();
	}
}
 
Example 11
Project: L2jBrasil   File: L2Properties.java   View Source Code Vote up 5 votes
@Override
public synchronized void load(Reader reader) throws IOException
{
	try
	{
		super.load(reader);
	}
	finally
	{
		reader.close();
	}
}
 
Example 12
Project: aos-FileCoreLibrary   File: OpenSSHConfig.java   View Source Code Vote up 5 votes
/**
 * Parses the given file, and returns an instance of ConfigRepository.
 *
 * @param file OpenSSH's config file
 * @return an instanceof OpenSSHConfig
 */
public static OpenSSHConfig parseFile(String file) throws IOException {
  Reader r = new FileReader(Util.checkTilde(file));
  try {
    return new OpenSSHConfig(r);
  }
  finally {
    r.close();
  }
}
 
Example 13
Project: mybatis-plus-mini   File: PaginationInterceptorTest.java   View Source Code Vote up 5 votes
@Before
public void setUp() throws Exception {
    SqlSession session = sqlSessionTemplate.getSqlSessionFactory().openSession();
    Connection conn = session.getConnection();
    Reader reader = Resources.getResourceAsReader("com/baomidou/mybatisplus/test/plugins/paginationInterceptor/CreateDB.sql");
    ScriptRunner runner = new ScriptRunner(conn);
    runner.setLogWriter(null);
    runner.runScript(reader);
    reader.close();
    session.close();
    // 随机当前页和分页大小
    size = RandomUtils.nextInt(1, 50);
    current = RandomUtils.nextInt(1, 200 / size);
    System.err.println("当前页为:" + current + " 分页大小为" + size);
}
 
Example 14
Project: incubator-netbeans   File: PropertiesEditorSupport.java   View Source Code Vote up 5 votes
/**
 * Reads the file from the stream, filter the guarded section
 * comments, and mark the sections in the editor. Overrides superclass method. 
 * @param document the document to read into
 * @param inputStream the open stream to read from
 * @param editorKit the associated editor kit
 * @throws <code>IOException</code> if there was a problem reading the file
 * @throws <code>BadLocationException</code> should not normally be thrown
 * @see #saveFromKitToStream
 */
@Override
protected void loadFromStreamToKit(StyledDocument document, InputStream inputStream, EditorKit editorKit) throws IOException, BadLocationException {
    final Charset c = getCharset();
    final Reader reader = new BufferedReader(new InputStreamReader(inputStream, c));

    try {
        editorKit.read(reader, document, 0);
    } finally {
        reader.close();
    }
}
 
Example 15
Project: neoscada   File: CommonPackageDeploymentContext.java   View Source Code Vote up 5 votes
@Override
public void addPreInstallationScript ( final Reader reader ) throws IOException
{
    try
    {
        CharStreams.copy ( reader, this.preInstallation );
    }
    finally
    {
        reader.close ();
    }
}
 
Example 16
Project: Android-Practice   File: DiskLruCache.java   View Source Code Vote up 5 votes
/**
 * Returns the remainder of 'reader' as a string, closing it when done.
 */
public static String readFully(Reader reader) throws IOException {
    try {
        StringWriter writer = new StringWriter();
        char[] buffer = new char[1024];
        int count;
        while ((count = reader.read(buffer)) != -1) {
            writer.write(buffer, 0, count);
        }
        return writer.toString();
    } finally {
        reader.close();
    }
}
 
Example 17
Project: ArtOfAndroid   File: DiskLruCache.java   View Source Code Vote up 5 votes
/**
 * Returns the remainder of 'reader' as a string, closing it when done.
 */
public static String readFully(Reader reader) throws IOException {
    try {
        StringWriter writer = new StringWriter();
        char[] buffer = new char[1024];
        int count;
        while ((count = reader.read(buffer)) != -1) {
            writer.write(buffer, 0, count);
        }
        return writer.toString();
    } finally {
        reader.close();
    }
}
 
Example 18
Project: RNLearn_Project1   File: NetworkingModule.java   View Source Code Vote up 5 votes
private void readWithProgress(
    RCTDeviceEventEmitter eventEmitter,
    int requestId,
    ResponseBody responseBody) throws IOException {
  long totalBytesRead = -1;
  long contentLength = -1;
  try {
    ProgressResponseBody progressResponseBody = (ProgressResponseBody) responseBody;
    totalBytesRead = progressResponseBody.totalBytesRead();
    contentLength = progressResponseBody.contentLength();
  } catch (ClassCastException e) {
    // Ignore
  }

  Reader reader = responseBody.charStream();
  try {
    char[] buffer = new char[MAX_CHUNK_SIZE_BETWEEN_FLUSHES];
    int read;
    while ((read = reader.read(buffer)) != -1) {
      ResponseUtil.onIncrementalDataReceived(
        eventEmitter,
        requestId,
        new String(buffer, 0, read),
        totalBytesRead,
        contentLength);
    }
  } finally {
    reader.close();
  }
}
 
Example 19
Project: neoscada   File: CommonPackageDeploymentContext.java   View Source Code Vote up 5 votes
@Override
public void addPostInstallationScript ( final Reader reader ) throws IOException
{
    try
    {
        CharStreams.copy ( reader, this.postInstallation );
    }
    finally
    {
        reader.close ();
    }
}
 
Example 20
Project: incubator-netbeans   File: FileObjectsTest.java   View Source Code Vote up 4 votes
@Override
public void close() throws IOException {
    for (Reader r : rds) {
        r.close();
    }
}