当前位置: 首页>>代码示例>>Java>>正文


Java InputStreamReader类代码示例

本文整理汇总了Java中java.io.InputStreamReader的典型用法代码示例。如果您正苦于以下问题:Java InputStreamReader类的具体用法?Java InputStreamReader怎么用?Java InputStreamReader使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


InputStreamReader类属于java.io包,在下文中一共展示了InputStreamReader类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getReader

import java.io.InputStreamReader; //导入依赖的package包/类
/**
 * This method checks if the given file is a Zip file containing one entry (in case of file
 * extension .zip). If this is the case, a reader based on a ZipInputStream for this entry is
 * returned. Otherwise, this method checks if the file has the extension .gz. If this applies, a
 * gzipped stream reader is returned. Otherwise, this method just returns a BufferedReader for
 * the given file (file was not zipped at all).
 */
public static BufferedReader getReader(File file, Charset encoding) throws IOException {
	// handle zip files if necessary
	if (file.getAbsolutePath().endsWith(".zip")) {
		try (ZipFile zipFile = new ZipFile(file)) {
			if (zipFile.size() == 0) {
				throw new IOException("Input of Zip file failed: the file archive does not contain any entries.");
			}
			if (zipFile.size() > 1) {
				throw new IOException("Input of Zip file failed: the file archive contains more than one entry.");
			}
			Enumeration<? extends ZipEntry> entries = zipFile.entries();
			InputStream zipIn = zipFile.getInputStream(entries.nextElement());
			return new BufferedReader(new InputStreamReader(zipIn, encoding));
		}
	} else if (file.getAbsolutePath().endsWith(".gz")) {
		return new BufferedReader(new InputStreamReader(new GZIPInputStream(new FileInputStream(file)), encoding));
	} else {
		return new BufferedReader(new InputStreamReader(new FileInputStream(file), encoding));
	}
}
 
开发者ID:transwarpio,项目名称:rapidminer,代码行数:28,代码来源:Tools.java

示例2: buildModSource

import java.io.InputStreamReader; //导入依赖的package包/类
public String buildModSource() {
    String template;
    try (BufferedReader buffer = new BufferedReader(new InputStreamReader(getClass().getResourceAsStream("/cslmusicmod/stationeditor/Mod.cs")))) {
        template = buffer.lines().collect(Collectors.joining("\n"));
    } catch (IOException e) {
        throw new IllegalStateException();
    }

    String namespace = "MusicPack_" + getName().trim().replaceAll("[^a-zA-Z0-9]" , "_");

    template = template.replace("__NAME__", getName())
            .replace("__DESCRIPTION__", getDescription())
            .replace("__NAMESPACE__", namespace);

    return template;
}
 
开发者ID:rumangerst,项目名称:CSLMusicModStationCreator,代码行数:17,代码来源:Station.java

示例3: read

import java.io.InputStreamReader; //导入依赖的package包/类
public static JSONObject read(final String url) throws Exception {
    Exception exception = null;
    for (int i = 0; i < 3; i++) {
        Expectant.delay((i + 1) * API_DELAY_MS);
        try (InputStream is = new URL(url).openStream()) {
            BufferedReader reader = new BufferedReader(new InputStreamReader(is, Charset.forName("UTF-8")));
            String jsonText = readWhole(reader);
            JSONObject json = new JSONObject(jsonText);
            return json;
        } catch (Exception ex) {
            System.err.println("Failed read url: " + url
                    + " try #" + (i + 1) + "\n" + ex.getMessage());
            exception = ex;
        }
    }

    throw exception;
}
 
开发者ID:WslF,项目名称:CF-rating-prediction,代码行数:19,代码来源:JsonReader.java

示例4: findPatternsInLogs

import java.io.InputStreamReader; //导入依赖的package包/类
public static boolean[] findPatternsInLogs(DockerContainer dockerContainer, Pattern... patterns) throws IOException {
	boolean found[] = new boolean[patterns.length];
	dockerContainer.dockerLogs(istream -> {
		try (BufferedReader br = new BufferedReader(new InputStreamReader(istream, "UTF-8"))) {
			br.lines().forEach(line -> {
				for (int i = 0; i < patterns.length; ++i) {
					Pattern pattern = patterns[i];
					if (pattern.matcher(line).find()) {
						LOGGER.info("Found pattern {} on line '{}'", pattern, LogCleaner.cleanLine(line));
						found[i] = true;
					}
				}
			});
		}
	});
	return found;
}
 
开发者ID:xtf-cz,项目名称:xtf,代码行数:18,代码来源:LogCheckerUtils.java

示例5: readStream

import java.io.InputStreamReader; //导入依赖的package包/类
/**
 * 
 * 
 * @param coordstream
 *            InputStream
 * @param bufferSize
 *            int
 * @return result String
 * @throws IOException
 */
public static String readStream(InputStream stream, int bufferSize, String encoding) throws IOException {
	StringWriter sw = new StringWriter();
	int bytesRead;

	if (!Helper.isEmpty(encoding)) {
		BufferedReader br = new BufferedReader(new InputStreamReader(stream, encoding), bufferSize);
		String str;
		while ((str = br.readLine()) != null) {
			sw.write(str);
		}
	} else {
		byte[] buffer = new byte[bufferSize];

		while ((bytesRead = stream.read(buffer)) != -1) {
			sw.write(new String(buffer, 0, bytesRead));
		}
	}

	return sw.toString();
}
 
开发者ID:GIScience,项目名称:openrouteservice,代码行数:31,代码来源:StreamUtility.java

示例6: loadContent

import java.io.InputStreamReader; //导入依赖的package包/类
@Override
public final boolean loadContent(final File file) {
	try {
		FileInputStream fis = new FileInputStream(file);
		DataInputStream dis = new DataInputStream(fis);
		BufferedReader br = new BufferedReader(new InputStreamReader(dis));
		StringBuilder sb = new StringBuilder();
		String strLine;
		while ((strLine = br.readLine()) != null) {
			sb.append(strLine);
			sb.append("\n");
		}
		if (sb.length() != 0) {
			sb.deleteCharAt(sb.length() - 1);
		}
		setText(sb.toString());
		dis.close();
		return true;
	} catch (IOException e) {
		LOG.warning("KH: could not load specified file: " + file.getPath());
		e.printStackTrace();
	}
	return false;
}
 
开发者ID:roscisz,项目名称:KernelHive,代码行数:25,代码来源:SourceCodeEditor.java

示例7: loadJS

import java.io.InputStreamReader; //导入依赖的package包/类
private String loadJS() {
    StringBuilder buf = new StringBuilder();
    try {
        InputStream is = getResources().getAssets().open("youtube_inject.js");
        BufferedReader br = new BufferedReader(new InputStreamReader(is, "UTF-8"));
        String str;

        while ((str = br.readLine()) != null) {
            buf.append(str);
        }

        br.close();
    } catch (Throwable throwable) {
        throwable.printStackTrace();
    }

    return buf.toString();
}
 
开发者ID:monthlypub,项目名称:SmingZZick_App,代码行数:19,代码来源:YoutubeSmingActivity.java

示例8: onCreate

import java.io.InputStreamReader; //导入依赖的package包/类
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_aboutus);

    Intent incoming = getIntent();
    Bundle extras = incoming.getExtras();

    String uri = "html/about.html";
    if(extras != null){
        uri = extras.getString(EXTRA_HTML_URI);
    }

    mWebView = (WebView) findViewById(R.id.webView);
    mCloseBtn = (ImageButton) findViewById(R.id.closeButton);

    mCloseBtn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            onBackPressed();
        }
    });

    InputStream is;
    String htmlData = "";
    try {
        is = this.getAssets().open(uri);
        BufferedReader r = new BufferedReader(new InputStreamReader(is));
        StringBuilder stringBuilder = new StringBuilder();

        String line;
        while( (line=r.readLine()) != null ) {
            stringBuilder.append(line);
        }
        htmlData = stringBuilder.toString();
    } catch( IOException error ) {}
    mWebView.loadDataWithBaseURL("file:///android_asset/", htmlData, "text/html", "utf-8", "about:blank");
}
 
开发者ID:anandwana001,项目名称:Tech-Jalsa,代码行数:39,代码来源:LocalWebActivity.java

示例9: main

import java.io.InputStreamReader; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	String s;
	String[] parts;
	int testsNum = Integer.parseInt(br.readLine());
	for (int t = 0; t < testsNum; t++) {
		arrLength = Integer.parseInt(br.readLine());
		s = br.readLine();
		parts = s.split(" ", -1);
		for (int i = 0; i < arrLength; i++) {
			arr[i] = Integer.parseInt(parts[i]);
		}
		int result = solveProblem();
		System.out.println(result);
	}
}
 
开发者ID:lagodiuk,项目名称:spoj,代码行数:17,代码来源:LSORT_6_Bottom_Up_Submitted.java

示例10: main

import java.io.InputStreamReader; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
    // Считать строки с консоли и объявить ArrayList list тут

    ArrayList <String> list = new ArrayList<>();
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    for (int i=0; i<10; i++) {
        list.add(br.readLine());
    }

    ArrayList<String> result = doubleValues(list);

    // Вывести на экран result
    for (String s: result) {
        System.out.println(s);
    }
}
 
开发者ID:avedensky,项目名称:JavaRushTasks,代码行数:17,代码来源:Solution.java

示例11: commandLoop

import java.io.InputStreamReader; //导入依赖的package包/类
private void commandLoop() throws IOException {
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    while (true) {
        TerminalCommand tc = Terminal.create(in.readLine());
        if (tc instanceof TerminalCommand.Guest) {
            TerminalCommand.Guest tcg = (TerminalCommand.Guest) tc;
            createGuest(tcg.count, tcg.coffee, tcg.maxCoffeeCount);
        } else if (tc == TerminalCommand.Status.Instance) {
            getStatus();
        } else if (tc == TerminalCommand.Quit.Instance) {
            system.terminate();
            break;
        } else {
            TerminalCommand.Unknown u = (TerminalCommand.Unknown) tc;
            log.warning("Unknown terminal command {}!", u.command);
        }
    }
}
 
开发者ID:ironfish,项目名称:oreilly-reactive-architecture-student,代码行数:19,代码来源:CoffeeHouseApp.java

示例12: readFieldLayout

import java.io.InputStreamReader; //导入依赖的package包/类
static Map<String, Object> readFieldLayout(int level) {
    try {
        String assetPath = "tables/table" + level + ".json";
        InputStream fin = _context.getAssets().open(assetPath);
        BufferedReader br = new BufferedReader(new InputStreamReader(fin));

        StringBuilder buffer = new StringBuilder();
        String line;
        while ((line=br.readLine())!=null) {
            buffer.append(line);
        }
        fin.close();
        Map<String, Object> layoutMap = JSONUtils.mapFromJSONString(buffer.toString());
        return layoutMap;
    }
    catch(Exception ex) {
        throw new RuntimeException(ex);
    }
}
 
开发者ID:StringMon,项目名称:homescreenarcade,代码行数:20,代码来源:FieldLayout.java

示例13: getNextPreKeyId

import java.io.InputStreamReader; //导入依赖的package包/类
private static synchronized int getNextPreKeyId(Context context) {
  try {
    File nextFile = new File(getPreKeysDirectory(context), PreKeyIndex.FILE_NAME);

    if (!nextFile.exists()) {
      return Util.getSecureRandom().nextInt(Medium.MAX_VALUE);
    } else {
      InputStreamReader reader = new InputStreamReader(new FileInputStream(nextFile));
      PreKeyIndex       index  = JsonUtils.fromJson(reader, PreKeyIndex.class);
      reader.close();
      return index.nextPreKeyId;
    }
  } catch (IOException e) {
    Log.w("PreKeyUtil", e);
    return Util.getSecureRandom().nextInt(Medium.MAX_VALUE);
  }
}
 
开发者ID:XecureIT,项目名称:PeSanKita-android,代码行数:18,代码来源:PreKeyUtil.java

示例14: main

import java.io.InputStreamReader; //导入依赖的package包/类
public static void main(String ... ags)throws IOException
{
	BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
	String str = in.readLine();
	long n = Long.parseLong(in.readLine());
	long a =0;
	for(int i=0;i<str.length();i++)
	{	
		if(str.charAt(i)=='a')
			a++;
	}
	long c =n/(long)str.length();
	a *= c;
	c = n%(long)str.length();
	for(int i=0;i<(int)c;i++)
	{
		if(str.charAt(i)=='a')
			a++;
	}
	System.out.println(a);
}
 
开发者ID:hell-sing,项目名称:hacker-rank,代码行数:22,代码来源:Repeated_String.java

示例15: getMode

import java.io.InputStreamReader; //导入依赖的package包/类
private static String getMode(String hostPort) throws NumberFormatException, UnknownHostException, IOException {
    String parts[] = hostPort.split(":");
    Socket s = new Socket(parts[0], Integer.parseInt(parts[1]));
    s.getOutputStream().write("stat".getBytes());
    BufferedReader br = new BufferedReader(new InputStreamReader(s.getInputStream()));
    String line;
    try {
      while((line = br.readLine()) != null) {
        if (line.startsWith("Mode: ")) {
          return line.substring(6);
        }
      }
      return "unknown";
    } finally {
      s.close();
    }
}
 
开发者ID:l294265421,项目名称:ZooKeeper,代码行数:18,代码来源:GenerateLoad.java


注:本文中的java.io.InputStreamReader类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。