java.io.BufferedReader Java Examples
The following examples show how to use
java.io.BufferedReader.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: XMLGeneratorTest.java From netbeans with Apache License 2.0 | 7 votes |
protected static BaseDocument getResourceAsDocument(String path) throws Exception { InputStream in = XMLGeneratorTest.class.getResourceAsStream(path); BaseDocument sd = new BaseDocument(true, "text/xml"); //NOI18N BufferedReader br = new BufferedReader(new InputStreamReader(in,"UTF-8")); StringBuffer sbuf = new StringBuffer(); try { String line = null; while ((line = br.readLine()) != null) { sbuf.append(line); sbuf.append(System.getProperty("line.separator")); } } finally { br.close(); } sd.insertString(0,sbuf.toString(),null); return sd; }
Example #2
Source File: MainActivity.java From TextThing with BSD 2-Clause "Simplified" License | 6 votes |
@Override protected void onActivityResult(int requestCode, int resultCode, Intent intent) { super.onActivityResult(requestCode, resultCode, intent); if(requestCode == FILEREQCODE && resultCode == RESULT_OK) { if (intent != null) { data = intent.getData(); fromExtern = true; Log.d(App.PACKAGE_NAME, "intent.getData() is not Null - Use App via filemanager?"); try { InputStream input = getContentResolver().openInputStream(data); BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(input)); String text = ""; while (bufferedReader.ready()) { text += bufferedReader.readLine() + "\n"; } contentView.setText(text); } catch (Exception e) { e.printStackTrace(); } } } }
Example #3
Source File: SystemInfoUtilities.java From rapidminer-studio with GNU Affero General Public License v3.0 | 6 votes |
private static String executeMemoryInfoProcess(String... command) throws IOException { ProcessBuilder procBuilder = new ProcessBuilder(command); Process process = procBuilder.start(); InputStream is = process.getInputStream(); InputStreamReader isr = new InputStreamReader(is, StandardCharsets.UTF_8); BufferedReader br = new BufferedReader(isr); try { String line; while ((line = br.readLine()) != null) { if (line.trim().isEmpty()) { continue; } else { return line; } } } catch (IOException e1) { // NOPMD throw e1; } finally { br.close(); } throw new IOException("Could not read memory process output for command " + Arrays.toString(command)); }
Example #4
Source File: PasteBinOccurrenceDownloader.java From wandora with GNU General Public License v3.0 | 6 votes |
public static String getUrl(URL url) throws IOException { StringBuilder sb = new StringBuilder(5000); if(url != null) { URLConnection con = url.openConnection(); Wandora.initUrlConnection(con); con.setUseCaches(false); BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream(), "UTF-8")); String s; while ((s = in.readLine()) != null) { sb.append(s); } in.close(); } return sb.toString(); }
Example #5
Source File: UVA_11332 Summing Digits.java From UVA with GNU General Public License v3.0 | 6 votes |
public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String s; while(!(s=br.readLine()).equals("0")){ if(s.length()==1){ System.out.println(s); } else{ while(s.length()!=1){ int sum=0; for(int i=0;i<s.length();i++){ sum+=Integer.parseInt(s.charAt(i)+""); } s=sum+""; } System.out.println(s); } } }
Example #6
Source File: JsonDownloader.java From cordova-hot-code-push with MIT License | 6 votes |
private String downloadJson() throws Exception { final StringBuilder jsonContent = new StringBuilder(); final URLConnection urlConnection = URLConnectionHelper.createConnectionToURL(downloadUrl, requestHeaders); final InputStreamReader streamReader = new InputStreamReader(urlConnection.getInputStream()); final BufferedReader bufferedReader = new BufferedReader(streamReader); final char data[] = new char[1024]; int count; while ((count = bufferedReader.read(data)) != -1) { jsonContent.append(data, 0, count); } bufferedReader.close(); return jsonContent.toString(); }
Example #7
Source File: AxisVideoOutput.java From sensorhub with Mozilla Public License 2.0 | 6 votes |
protected int[] getImageSize() throws IOException { String ipAddress = parentSensor.getConfiguration().ipAddress; URL getImgSizeUrl = new URL("http://" + ipAddress + "/axis-cgi/view/imagesize.cgi?camera=1"); BufferedReader reader = new BufferedReader(new InputStreamReader(getImgSizeUrl.openStream())); int imgSize[] = new int[2]; String line; while ((line = reader.readLine()) != null) { // split line and parse each possible property String[] tokens = line.split("="); if (tokens[0].trim().equalsIgnoreCase("image width")) imgSize[0] = Integer.parseInt(tokens[1].trim()); else if (tokens[0].trim().equalsIgnoreCase("image height")) imgSize[1] = Integer.parseInt(tokens[1].trim()); } // index 0 is width, index 1 is height return imgSize; }
Example #8
Source File: GenomeIo.java From SproutLife with MIT License | 6 votes |
private static void loadSettings(BufferedReader reader, GameModel gameModel) throws IOException { String line = reader.readLine(); while (line != null && (!line.contains(":") || line.trim().equalsIgnoreCase("settings"))) { line = reader.readLine(); } if (line == null) { return; } if (line.trim().equalsIgnoreCase("settings")) { line = reader.readLine(); } while (true) { if (line == null || line.trim().isEmpty()) { return; } String[] kv = line.split(" : "); if (kv.length != 2) { throw new IOException("Error parsing organism settings"); } String k = kv[0]; String v = kv[1]; gameModel.getSettings().set(k, v); line = reader.readLine(); } }
Example #9
Source File: CustomerServlet.java From keycloak with Apache License 2.0 | 6 votes |
private String invokeService(String serviceUrl, KeycloakSecurityContext context) throws IOException { StringBuilder result = new StringBuilder(); URL url = new URL(serviceUrl); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); conn.setRequestMethod("GET"); conn.setRequestProperty(HttpHeaders.AUTHORIZATION, "Bearer " + context.getTokenString()); if (conn.getResponseCode() != 200) { conn.getErrorStream().close(); return "Service returned: " + conn.getResponseCode(); } BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream())); String line; while ((line = rd.readLine()) != null) { result.append(line); } rd.close(); return result.toString(); }
Example #10
Source File: AndesJMSPublisher.java From product-ei with Apache License 2.0 | 6 votes |
/** * Reads message content from a file which is used as the message content to when publishing * messages. * * @throws IOException */ public void getMessageContentFromFile() throws IOException { if (null != this.publisherConfig.getReadMessagesFromFilePath()) { BufferedReader br = new BufferedReader(new FileReader(this.publisherConfig .getReadMessagesFromFilePath())); try { StringBuilder sb = new StringBuilder(); String line = br.readLine(); while (line != null) { sb.append(line); sb.append('\n'); line = br.readLine(); } // Remove the last appended next line since there is no next line. sb.replace(sb.length() - 1, sb.length() + 1, ""); messageContent = sb.toString(); } finally { br.close(); } } }
Example #11
Source File: PropertyFileMerger.java From commerce-gradle-plugin with Apache License 2.0 | 6 votes |
public Map<String, String> mergeProperties() { Map<String, String> finalProperties = new HashMap<>(); for (Path propertyFile : propertyFiles) { if (!Files.exists(propertyFile)) { continue; } try (BufferedReader reader = Files.newBufferedReader(propertyFile)) { Properties properties = new Properties(); properties.load(reader); properties.forEach((key, value) -> finalProperties.put(String.valueOf(key), String.valueOf(value))); } catch (IOException e) { //ignore } } return Collections.unmodifiableMap(finalProperties); }
Example #12
Source File: MifParser.java From translationstudio8 with GNU General Public License v2.0 | 6 votes |
public void parseFile(String file, String encoding) throws IOException, MifParseException, UnSuportedFileExcetption { File path = new File(file); FileInputStream in = new FileInputStream(path); InputStreamReader inr = new InputStreamReader(in, encoding); BufferedReader bfr = new BufferedReader(inr); char[] doc = new char[(int) path.length()]; bfr.read(doc); in.close(); bfr.close(); inr.close(); setDoc(doc); parse(); }
Example #13
Source File: CommandProcessor.java From hottub with GNU General Public License v2.0 | 6 votes |
public void doit(Tokens t) { if (t.countTokens() != 1) { usage(); return; } String file = t.nextToken(); BufferedReader savedInput = in; try { BufferedReader input = new BufferedReader(new InputStreamReader(new FileInputStream(file))); in = input; run(false); } catch (Exception e) { out.println("Error: " + e); if (verboseExceptions) { e.printStackTrace(out); } } finally { in = savedInput; } }
Example #14
Source File: TestGrunt.java From spork with Apache License 2.0 | 6 votes |
@Test public void testBagConstantWithSchemaInForeachBlock() throws Throwable { PigServer server = new PigServer(cluster.getExecType(), cluster.getProperties()); PigContext context = server.getPigContext(); String strCmd = "a = load 'input1'; " + "b = foreach a {generate {(1, '1', 0.4f),(2, '2', 0.45)} " + "as b: bag{t:(i: int, c:chararray, d: double)};};\n"; ByteArrayInputStream cmd = new ByteArrayInputStream(strCmd.getBytes()); InputStreamReader reader = new InputStreamReader(cmd); Grunt grunt = new Grunt(new BufferedReader(reader), context); grunt.exec(); }
Example #15
Source File: Template.java From civcraft with GNU General Public License v2.0 | 6 votes |
public void load_template(String filepath) throws IOException, CivException { File templateFile = new File(filepath); BufferedReader reader = new BufferedReader(new FileReader(templateFile)); // Read first line and get size. String line = null; line = reader.readLine(); if (line == null) { reader.close(); throw new CivException("Invalid template file:"+filepath); } String split[] = line.split(";"); size_x = Integer.valueOf(split[0]); size_y = Integer.valueOf(split[1]); size_z = Integer.valueOf(split[2]); getTemplateBlocks(reader, size_x, size_y, size_z); this.filepath = filepath; reader.close(); }
Example #16
Source File: SubjectStorage.java From LuckPerms with MIT License | 6 votes |
/** * Loads a subject from a particular file * * @param file the file to load from * @return a loaded subject * @throws IOException if the read fails */ public LoadedSubject loadFromFile(Path file) throws IOException { if (!Files.exists(file)) { return null; } String fileName = file.getFileName().toString(); String subjectName = fileName.substring(0, fileName.length() - ".json".length()); try (BufferedReader reader = Files.newBufferedReader(file, StandardCharsets.UTF_8)) { JsonObject data = GsonProvider.prettyPrinting().fromJson(reader, JsonObject.class); SubjectDataContainer model = SubjectDataContainer.deserialize(this.service, data); return new LoadedSubject(subjectName, model); } catch (Exception e) { throw new IOException("Exception occurred whilst loading from " + file.toString(), e); } }
Example #17
Source File: TSPLibTour.java From jorlib with GNU Lesser General Public License v2.1 | 6 votes |
/** * Loads the contents of this tour from the given reader. * * @param reader the reader that defines this tour * @throws IOException if an I/O error occurred while reading the tour */ public void load(BufferedReader reader) throws IOException { String line = null; outer: while ((line = reader.readLine()) != null) { String[] tokens = line.trim().split("\\s+"); for (int i = 0; i < tokens.length; i++) { int id = Integer.parseInt(tokens[i]); if (id == -1) { break outer; } else { nodes.add(id-1); } } } }
Example #18
Source File: ServerSocketDemo.java From cs-summary-reflection with Apache License 2.0 | 6 votes |
public static void main(String[] args) throws IOException { // 创建服务器Socket对象,指定绑定22222这个端口,响应他 ServerSocket ss = new ServerSocket(22222); // 监听客户端连接 Socket s = ss.accept(); // 阻塞监听 // 包装通道内容的流 BufferedReader br = new BufferedReader(new InputStreamReader(s.getInputStream())); String line; while ((line = br.readLine()) != null) { System.out.println(line); } // br.close(); s.close(); ss.close(); }
Example #19
Source File: FileUtil.java From Aria with Apache License 2.0 | 6 votes |
public static long getTotalMemory() { String file_path = "/proc/meminfo";// 系统内存信息文件 String ram_info; String[] arrayOfRam; long initial_memory = 0L; try { FileReader fr = new FileReader(file_path); BufferedReader localBufferedReader = new BufferedReader(fr, 8192); // 读取meminfo第一行,系统总内存大小 ram_info = localBufferedReader.readLine(); arrayOfRam = ram_info.split("\\s+");// 实现多个空格切割的效果 initial_memory = Integer.valueOf(arrayOfRam[1]) * 1024;// 获得系统总内存,单位是KB,乘以1024转换为Byte localBufferedReader.close(); } catch (IOException e) { e.printStackTrace(); } return initial_memory; }
Example #20
Source File: CommandLine.java From openjdk-8 with GNU General Public License v2.0 | 6 votes |
private static void loadCmdFile(String name, ListBuffer<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.append(st.sval); } r.close(); }
Example #21
Source File: 11286 Confirmity.java From UVA with GNU General Public License v3.0 | 6 votes |
public static void main (String [] args) throws Exception { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); String s; while (!(s=br.readLine()).equals("0")){ int n=Integer.parseInt(s); HashMap<String,Integer> map=new HashMap<>(); for (int i=0;i<n;i++) { StringTokenizer st=new StringTokenizer(br.readLine()); TreeSet<String> set=new TreeSet<>(); for (int i2=0;i2<5;i2++) set.add(st.nextToken()); String key=set.toString(); map.put(key, map.getOrDefault(key,0)+1); } int max=Collections.max(map.values()); System.out.println(map.values().stream().filter(i -> i == max).count()*max); } }
Example #22
Source File: AutoTestAdjust.java From bestconf with Apache License 2.0 | 6 votes |
private double[] getPerf(String filePath){ double[] result = new double[2]; File res = new File(filePath); try { int tot=0; BufferedReader reader = new BufferedReader(new FileReader(res)); String readline = null; while ((readline = reader.readLine()) != null) { result[tot++] = Double.parseDouble(readline); } reader.close(); } catch (Exception e) { e.printStackTrace(); result = null; } return result; }
Example #23
Source File: StarsTransientMetricProvider.java From scava with Eclipse Public License 2.0 | 5 votes |
private JSONObject getRemainingResource(Project project) throws IOException { URL url = new URL("https://api.github.com/rate_limit"); HttpsURLConnection connection = (HttpsURLConnection) url.openConnection(); connection.setRequestProperty("Authorization", "token " + ((GitHubRepository) project).getToken()); connection.connect(); InputStream is = connection.getInputStream(); BufferedReader bufferReader = new BufferedReader(new InputStreamReader(is, Charset.forName(UTF8))); String jsonText = readAll(bufferReader); JSONObject obj = (JSONObject) JSONValue.parse(jsonText); return (JSONObject) obj.get("resources"); }
Example #24
Source File: JsonObjectGetter.java From HouseAds2 with MIT License | 5 votes |
@Override protected MyAd[] doInBackground(Void... voids) { try { URL url = new URL(jsonUrl); InputStream is = url.openStream(); BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(is, Charset.forName("UTF-8"))); StringBuilder sb = new StringBuilder(); int cp; while ((cp = bufferedReader.read()) != -1) { sb.append((char) cp); } JSONArray jsonArray = new JSONArray(sb.toString()); MyAd[] myAds = new MyAd[jsonArray.length()]; for (int i = 0; i < jsonArray.length(); i++) { JSONObject object = jsonArray.getJSONObject(i); myAds[i] = new MyAd( object.getString("appIcon"), object.getString("appName"), object.getString("appDescription"), object.getString("url") ); } return myAds; } catch (Exception e) { this.exception = e; } return null; }
Example #25
Source File: CertRenewApplet.java From swift-k with Apache License 2.0 | 5 votes |
private String loadFile(String fileName) throws FileNotFoundException, IOException { File f = new File(fileName); String data = ""; BufferedReader in = new BufferedReader( new InputStreamReader(new FileInputStream(f))); String sLine = in.readLine(); while (sLine != null) { data += sLine + "\n"; sLine = in.readLine(); } in.close(); return data; }
Example #26
Source File: VersionChecker.java From Explvs-AIO with MIT License | 5 votes |
private static Optional<JSONObject> getLatestGitHubReleaseJSON() { try { URL url = new URL(GITHUB_API_LATEST_RELEASE_URL); HttpURLConnection con = (HttpURLConnection) url.openConnection(); con.setRequestMethod("GET"); try (InputStreamReader inputStreamReader = new InputStreamReader(con.getInputStream()); BufferedReader bufferedReader = new BufferedReader(inputStreamReader)) { return Optional.of((JSONObject) (new JSONParser().parse(bufferedReader))); } } catch (IOException | ParseException e) { e.printStackTrace(); } return Optional.empty(); }
Example #27
Source File: SysFs.java From libcommon with Apache License 2.0 | 5 votes |
public String readString(@Nullable final String name) throws IOException { String result; mReadLock.lock(); try { final FileReader in = new FileReader(getPath(name)); try { result = new BufferedReader(in).readLine(); } finally { in.close(); } } finally { mReadLock.unlock(); } return result; }
Example #28
Source File: GraphQLFactory.java From dropwizard-graphql with Apache License 2.0 | 5 votes |
/** * Return a resource file name as a BufferedReader * * @param name Resource file name * @return BufferedReader for the file */ private static BufferedReader getResourceAsReader(final String name) { LOGGER.info("Loading GraphQL schema file: {}", name); final ClassLoader loader = MoreObjects.firstNonNull( Thread.currentThread().getContextClassLoader(), GraphQLFactory.class.getClassLoader()); final InputStream in = loader.getResourceAsStream(name); Objects.requireNonNull(in, String.format("resource not found: %s", name)); return new BufferedReader(new InputStreamReader(in, StandardCharsets.UTF_8)); }
Example #29
Source File: Solution.java From JavaRush with MIT License | 5 votes |
public static void main(String[] args) throws IOException { BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in)); String fileName = bufferedReader.readLine(); ArrayList<String> fileList = new ArrayList<>(); String input; BufferedReader fileReader = new BufferedReader(new FileReader(fileName)); while ((input = fileReader.readLine()) != null) { fileList.add(input); } fileReader.close(); for (String aFileList : fileList) { String[] stringArray = aFileList.split(" "); for (int i = 0; i < stringArray.length; i++) { for (Map.Entry<Integer, String> entry : map.entrySet()) { try { if (Integer.parseInt(stringArray[i]) == entry.getKey()) { stringArray[i] = entry.getValue(); } } catch (NumberFormatException ignored) { } } } for (String currentString : stringArray) { System.out.print(currentString + " "); } System.out.println(); } }
Example #30
Source File: DatabaseConnectController.java From incubator-iotdb with Apache License 2.0 | 5 votes |
/** * get request body JSON. * * @param request http request * @return request JSON * @throws JSONException JSONException */ public JSONObject getRequestBodyJson(HttpServletRequest request) throws JSONException { try { BufferedReader br = request.getReader(); StringBuilder sb = new StringBuilder(); String line; while ((line = br.readLine()) != null) { sb.append(line); } return JSON.parseObject(sb.toString()); } catch (IOException e) { logger.error("getRequestBodyJson failed", e); } return null; }