本文整理汇总了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();
}
示例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());
}
}
示例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();
}
示例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...
}
}
示例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));
}
示例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;
}
示例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();
}
示例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();
}
示例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;
}
示例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;
}
示例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();
}
}
示例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;
}
示例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();
}
示例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;
}
示例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);
}
}