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


Java InputStreamReader.close方法代碼示例

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


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

示例1: doGet

import java.io.InputStreamReader; //導入方法依賴的package包/類
public void doGet(String url) throws Exception{
	URL localURL = new URL(url);
	URLConnection con = openConnection(localURL);
	HttpURLConnection httpCon = (HttpURLConnection)con;
	httpCon.setRequestProperty("Accept-Charset",CHARSET);
	httpCon.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
	if(httpCon.getResponseCode()>=300){
		throw new RuntimeException("請求失敗...");
	}
	InputStreamReader isr = new InputStreamReader(httpCon.getInputStream());
	BufferedReader reader = new BufferedReader(isr);
	String res = reader.readLine();
	System.out.println(res);
	isr.close();
	reader.close();
}
 
開發者ID:Awesky,項目名稱:awe-awesomesky,代碼行數:17,代碼來源:HttpUtil.java

示例2: BacktrackInputReader

import java.io.InputStreamReader; //導入方法依賴的package包/類
/**
 * Create an object to read the file name passed with the given charset.
 *
 * @param file	The filename to open
 */

public BacktrackInputReader(File file, String charset)
{
	try
	{
		InputStreamReader isr = readerFactory(file, charset);
		data = new char[readerLength(file, isr)];
		max = isr.read(data);
		pos = 0;
		isr.close();
	}
	catch (IOException e)
	{
		throw new InternalException(0, e.getMessage());
	}
}
 
開發者ID:nickbattle,項目名稱:FJ-VDMJ,代碼行數:22,代碼來源:BacktrackInputReader.java

示例3: getContent

import java.io.InputStreamReader; //導入方法依賴的package包/類
public String getContent(String charSet) throws IOException {
    InputStreamReader reader = new InputStreamReader(createInputStream(),
            Charset.forName(charSet));
    char[] tmp = new char[4096];
    StringBuilder b = new StringBuilder();
    try {
        while (true) {
            int len = reader.read(tmp);
            if (len < 0) {
                break;
            }
            b.append(tmp, 0, len);
        }
        reader.close();
    } finally {
        reader.close();
    }
    return b.toString();
}
 
開發者ID:ISA-tools,項目名稱:FAIRsharing-Owl2Neo,代碼行數:20,代碼來源:ResourceFile.java

示例4: BacktrackInputReader

import java.io.InputStreamReader; //導入方法依賴的package包/類
/**
 * Create an object to read the string passed. This is used in the
 * interpreter to parse expressions typed in.
 *
 * @param expression
 */
public BacktrackInputReader(String expression, String charset)
{
   	try
       {
        ByteArrayInputStream is =
        	new ByteArrayInputStream(expression.getBytes(charset));

        InputStreamReader isr =
        	new LatexStreamReader(is, charset);

   		data = new char[expression.length() + 1];
        max = isr.read(data);
        pos = 0;

        isr.close();
        is.close();
       }
       catch (IOException e)
       {
        // This can never really happen...
       }
}
 
開發者ID:nickbattle,項目名稱:FJ-VDMJ,代碼行數:29,代碼來源:BacktrackInputReader.java

示例5: handleMetadata

import java.io.InputStreamReader; //導入方法依賴的package包/類
/**
 * Parse metadata and take appropriate action (that is, upgrade dictionaries).
 * @param context the context to read settings.
 * @param stream an input stream pointing to the downloaded data. May not be null.
 *  Will be closed upon finishing.
 * @param clientId the ID of the client to update
 * @throws BadFormatException if the metadata is not in a known format.
 * @throws IOException if the downloaded file can't be read from the disk
 */
public static void handleMetadata(final Context context, final InputStream stream,
        final String clientId) throws IOException, BadFormatException {
    DebugLogUtils.l("Entering handleMetadata");
    final List<WordListMetadata> newMetadata;
    final InputStreamReader reader = new InputStreamReader(stream);
    try {
        // According to the doc InputStreamReader buffers, so no need to add a buffering layer
        newMetadata = MetadataHandler.readMetadata(reader);
    } finally {
        reader.close();
    }

    DebugLogUtils.l("Downloaded metadata :", newMetadata);
    PrivateLog.log("Downloaded metadata\n" + newMetadata);

    final ActionBatch actions = computeUpgradeTo(context, clientId, newMetadata);
    // TODO: Check with UX how we should report to the user
    // TODO: add an action to close the database
    actions.execute(context, new LogProblemReporter(TAG));
}
 
開發者ID:sergeychilingaryan,項目名稱:AOSP-Kayboard-7.1.2,代碼行數:30,代碼來源:UpdateHandler.java

示例6: readSensitiveWord

import java.io.InputStreamReader; //導入方法依賴的package包/類
private Set<String> readSensitiveWord(InputStream in,Charset charset) throws Exception{
	Set<String> set = new HashSet<String>();
	InputStreamReader read = new InputStreamReader(in,charset);
	try {
		set = new HashSet<String>();
		BufferedReader bufferedReader = new BufferedReader(read);
		String txt = null;
		while((txt = bufferedReader.readLine()) != null){    //讀取文件,將文件內容放入到set中
			set.add(txt);
	    }
	} catch (Exception e) {
		throw e;
	}finally{
		read.close();     //關閉文件流
	}
	return set;
}
 
開發者ID:juebanlin,項目名稱:util4j,代碼行數:18,代碼來源:SensitiveFilter.java

示例7: readFile

import java.io.InputStreamReader; //導入方法依賴的package包/類
/**
 * 根據指定編碼讀取文件
 * 
 * @param fileName
 *            文件名
 * @param charset
 *            字符集
 * @return 文件字符串
 */
public static String readFile(String fileName, String charset) {
    StringBuffer sb = new StringBuffer();
    File file = new File(fileName);
    try {
        InputStreamReader read = new InputStreamReader(new FileInputStream(file), charset);
        BufferedReader bufferedReader = new BufferedReader(read);
        String lineTxt = null;
        while ((lineTxt = bufferedReader.readLine()) != null) {
            sb.append(lineTxt + System.getProperty("line.separator"));
        }
        read.close();
    } catch (IOException e) {
        logger.error(e.getMessage(), e);
    }
    return sb.toString();
}
 
開發者ID:Chihpin,項目名稱:Yidu,代碼行數:26,代碼來源:FileUtils.java

示例8: txtToHtml

import java.io.InputStreamReader; //導入方法依賴的package包/類
private void txtToHtml() throws Throwable {
	FileOutputStream output = new FileOutputStream(new File(htmlPath));
	String head = "<!DOCTYPE><html><head><meta charset=\"utf-8\"><meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge\">"
			+ "<meta name=\"viewport\" content=\"initial-scale=1, maximum-scale=1\">"
			+ "</head><body style=\"background:#fff padding:10px,10px,10px,10px\"><div style=\"font-size:.66667rem color:#666\">";
	String end = "</div></body></html>";
	output.write(head.getBytes());
	InputStreamReader isr = new InputStreamReader(new FileInputStream(filePath), getCharset(filePath));
	BufferedReader br = new BufferedReader(isr);
	String line;
	while ((line = br.readLine()) != null) {
		output.write(line.getBytes());
		output.write("<br />".getBytes("UTF-8"));
	}
	br.close();
	isr.close();
	output.write(end.getBytes());
	output.close();
}
 
開發者ID:MobClub,項目名稱:BBSSDK-for-Android,代碼行數:20,代碼來源:OfficeConverter.java

示例9: getGPIOC7

import java.io.InputStreamReader; //導入方法依賴的package包/類
public int getGPIOC7(){
    File file = new File("/sys/class/gpio/gpio71/value");
    try {
        InputStream instream = new FileInputStream(file);
        InputStreamReader inputreader = new InputStreamReader(instream);
        BufferedReader buffreader = new BufferedReader(inputreader);
        String c7value = buffreader.readLine();
        if(c7value == null || c7value =="")
            return -1;
        instream.close();
        inputreader.close();
        buffreader.close();
        return Integer.parseInt(c7value);

    } catch (Exception e) {
        e.printStackTrace();
    }
    return -1;
}
 
開發者ID:harveyandroid,項目名稱:AndroidSerialPort,代碼行數:20,代碼來源:GPIOFileUtils.java

示例10: fromFile

import java.io.InputStreamReader; //導入方法依賴的package包/類
/**
 * Parses an {@link EntityArguments} object from the given .json file
 *
 * @param name the name of the .json file
 * @return the parsed {@link EntityArguments}
 * @throws IOException
 */
public static EntityArguments fromFile(String name) throws IOException {

    EntityArguments arguments = new EntityArguments();
    InputStream is = EntityArguments.class.getResourceAsStream("/" + name);
    InputStreamReader reader = new InputStreamReader(is);
    Type type = new TypeToken<Map<String, Template>>() {
    }.getType();
    Map<String, Template> defs = GsonUtil.getGSON().fromJson(reader, type);
    reader.close();

    for (Map.Entry<String, Template> entries : defs.entrySet()) {
        arguments.put(entries.getKey(), entries.getValue());
    }
    return arguments;
}
 
開發者ID:EtherWorks,項目名稱:arcadelegends-gg,代碼行數:23,代碼來源:EntityArguments.java

示例11: setupLyricResource

import java.io.InputStreamReader; //導入方法依賴的package包/類
private void setupLyricResource(InputStream inputStream, String charsetName) {
    if (inputStream != null) {
        try {
            LyricInfo lyricInfo = new LyricInfo();
            lyricInfo.songLines = new ArrayList<>();
            InputStreamReader inputStreamReader = new InputStreamReader(inputStream, charsetName);
            BufferedReader reader = new BufferedReader(inputStreamReader);
            String line;
            while ((line = reader.readLine()) != null) {
                analyzeLyric(lyricInfo, line);
            }
            reader.close();
            inputStream.close();
            inputStreamReader.close();

            mLyricInfo = lyricInfo;
            mLineCount = mLyricInfo.songLines.size();
            invalidateView();
        } catch (IOException e) {
            e.printStackTrace();
        }
    } else {
        invalidateView();
    }
}
 
開發者ID:Zackratos,項目名稱:PureMusic,代碼行數:26,代碼來源:LyricView.java

示例12: retornarListaDeFarmacias

import java.io.InputStreamReader; //導入方法依賴的package包/類
public LinkedList<String> retornarListaDeFarmacias() throws IOException{
    String linha;
    LinkedList<String> farmacias = new LinkedList(); 
    File file = new File("FarmaciasCadastradas.txt");
    if(!file.exists()) file.createNewFile();
    InputStream is = new FileInputStream("FarmaciasCadastradas.txt");
    InputStreamReader isr = new InputStreamReader(is);
    BufferedReader br = new BufferedReader(isr);
    
    do{
        linha = br.readLine();
        if(linha != null) farmacias.add(linha);
    }while(linha != null);
    is.close();
    isr.close();
    br.close();
    return farmacias;

}
 
開發者ID:knowrafa,項目名稱:lembredio,代碼行數:20,代碼來源:PacienteInterface.java

示例13: doGet

import java.io.InputStreamReader; //導入方法依賴的package包/類
@Override
public void doGet(HttpServletRequest request, 
                  HttpServletResponse response
                  ) throws ServletException, IOException {
  InputStreamReader in = new InputStreamReader(request.getInputStream());
  PrintStream out = new PrintStream(response.getOutputStream());

  calledTimes++;
  try {
    requestUri = new URI(null, null,
        request.getRequestURI(), request.getQueryString(), null);
  } catch (URISyntaxException e) {
  }

  in.close();
  out.close();
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:18,代碼來源:TestJobEndNotifier.java

示例14: readSensitiveWordFile

import java.io.InputStreamReader; //導入方法依賴的package包/類
/**
 * 讀取敏感詞庫中的內容,將內容添加到set集合中
 * @author chenssy 
 * @date 2014年4月20日 下午2:31:18
 * @return
 * @version 1.0
 * @throws Exception 
 */
@SuppressWarnings("resource")
private Set<String> readSensitiveWordFile() throws Exception{
	Set<String> set = null;
	
	File file = new File("D:\\SensitiveWord.txt");    //讀取文件
	InputStreamReader read = new InputStreamReader(new FileInputStream(file),ENCODING);
	try {
		if(file.isFile() && file.exists()){      //文件流是否存在
			set = new HashSet<String>();
			BufferedReader bufferedReader = new BufferedReader(read);
			String txt = null;
			while((txt = bufferedReader.readLine()) != null){    //讀取文件,將文件內容放入到set中
				set.add(txt);
		    }
		}
		else{         //不存在拋出異常信息
			throw new Exception("敏感詞庫文件不存在");
		}
	} catch (Exception e) {
		throw e;
	}finally{
		read.close();     //關閉文件流
	}
	return set;
}
 
開發者ID:onsoul,項目名稱:os,代碼行數:34,代碼來源:SensitiveWordInit.java

示例15: getNextSignedPreKeyId

import java.io.InputStreamReader; //導入方法依賴的package包/類
private static synchronized int getNextSignedPreKeyId(Context context) {
  try {
    File nextFile = new File(getSignedPreKeysDirectory(context), SignedPreKeyIndex.FILE_NAME);

    if (!nextFile.exists()) {
      return Util.getSecureRandom().nextInt(Medium.MAX_VALUE);
    } else {
      InputStreamReader reader = new InputStreamReader(new FileInputStream(nextFile));
      SignedPreKeyIndex index  = JsonUtils.fromJson(reader, SignedPreKeyIndex.class);
      reader.close();
      return index.nextSignedPreKeyId;
    }
  } catch (IOException e) {
    Log.w("PreKeyUtil", e);
    return Util.getSecureRandom().nextInt(Medium.MAX_VALUE);
  }
}
 
開發者ID:CableIM,項目名稱:Cable-Android,代碼行數:18,代碼來源:PreKeyUtil.java


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