當前位置: 首頁>>代碼示例>>Java>>正文


Java Reader.close方法代碼示例

本文整理匯總了Java中java.io.Reader.close方法的典型用法代碼示例。如果您正苦於以下問題:Java Reader.close方法的具體用法?Java Reader.close怎麽用?Java Reader.close使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.io.Reader的用法示例。


在下文中一共展示了Reader.close方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: generateSLSLoadFile

import java.io.Reader; //導入方法依賴的package包/類
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();
  }
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:22,代碼來源:RumenToSLSConverter.java

示例2: copy

import java.io.Reader; //導入方法依賴的package包/類
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) {
            }
        }
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:19,代碼來源:Basic.java

示例3: readFully

import java.io.Reader; //導入方法依賴的package包/類
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();
    }
}
 
開發者ID:JackChan1999,項目名稱:boohee_v5.6,代碼行數:18,代碼來源:Util.java

示例4: testRepositioningInfo

import java.io.Reader; //導入方法依賴的package包/類
/**
 * 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);
      }
    }
}
 
開發者ID:GateNLP,項目名稱:gate-core,代碼行數:37,代碼來源:TestRepositioningInfo.java

示例5: loadCmdFile

import java.io.Reader; //導入方法依賴的package包/類
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();
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:17,代碼來源:CommandLine.java

示例6: loadCmdFile

import java.io.Reader; //導入方法依賴的package包/類
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();
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:17,代碼來源:CommandLine.java

示例7: readFile

import java.io.Reader; //導入方法依賴的package包/類
/**
* 
* @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();
  }
 
開發者ID:JupiterDevelopmentTeam,項目名稱:Jupiter,代碼行數:31,代碼來源:Utils.java

示例8: readFully

import java.io.Reader; //導入方法依賴的package包/類
/**
 * 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();
    }
}
 
開發者ID:Jiabaokang,項目名稱:JBKWeather,代碼行數:17,代碼來源:DiskLruCache.java

示例9: readFully

import java.io.Reader; //導入方法依賴的package包/類
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();
	}
}
 
開發者ID:Spencer231,項目名稱:GifImageLoader,代碼行數:14,代碼來源:Util.java

示例10: load

import java.io.Reader; //導入方法依賴的package包/類
@Override
public synchronized void load(Reader reader) throws IOException
{
	try
	{
		super.load(reader);
	}
	finally
	{
		reader.close();
	}
}
 
開發者ID:L2jBrasil,項目名稱:L2jBrasil,代碼行數:13,代碼來源:L2Properties.java

示例11: parseFile

import java.io.Reader; //導入方法依賴的package包/類
/**
 * 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();
  }
}
 
開發者ID:archos-sa,項目名稱:aos-FileCoreLibrary,代碼行數:16,代碼來源:OpenSSHConfig.java

示例12: setUp

import java.io.Reader; //導入方法依賴的package包/類
@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);
}
 
開發者ID:Caratacus,項目名稱:mybatis-plus-mini,代碼行數:16,代碼來源:PaginationInterceptorTest.java

示例13: loadFromStreamToKit

import java.io.Reader; //導入方法依賴的package包/類
/**
 * 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();
    }
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:22,代碼來源:PropertiesEditorSupport.java

示例14: addPreInstallationScript

import java.io.Reader; //導入方法依賴的package包/類
@Override
public void addPreInstallationScript ( final Reader reader ) throws IOException
{
    try
    {
        CharStreams.copy ( reader, this.preInstallation );
    }
    finally
    {
        reader.close ();
    }
}
 
開發者ID:eclipse,項目名稱:neoscada,代碼行數:13,代碼來源:CommonPackageDeploymentContext.java

示例15: readWithProgress

import java.io.Reader; //導入方法依賴的package包/類
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();
  }
}
 
開發者ID:qq565999484,項目名稱:RNLearn_Project1,代碼行數:31,代碼來源:NetworkingModule.java


注:本文中的java.io.Reader.close方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。