List of usage examples for java.io BufferedReader ready
public boolean ready() throws IOException
From source file:com.bagdemir.eboda.ext.MimeDictionary.java
/** * parses mime types data file and builds a new file extension-to-mime type map. *//*from ww w.j av a 2s .c om*/ private void initMimeTypes() { final InputStream resourceAsStream = getClass().getClassLoader().getResourceAsStream(MIME_TYPES_FILE); BufferedReader reader = null; try { reader = new BufferedReader(new InputStreamReader(resourceAsStream)); while (reader.ready()) { final String line = reader.readLine(); if (StringUtils.isNotBlank(line)) { // ignore commented lines. if (isCommentLine(line)) { continue; } processLine(line); } } } catch (FileNotFoundException e) { LOGGER.error(e); } catch (IOException e) { LOGGER.error(e); closeReader(reader); } }
From source file:br.com.verificanf.bo.NotaBO.java
public void buscar() { /*Inicio - Pegar Configuraes de email do arquivo*/ try {//from ww w. j a va 2s .c o m String local = new File("./email.txt").getCanonicalFile().toString(); File arq = new File(local); boolean existe = arq.exists(); if (existe) { FileReader fr = new FileReader(arq); BufferedReader br = new BufferedReader(fr); while (br.ready()) { String linha = br.readLine(); if (linha.contains("host:")) { hostEmail = linha.replace("host:", "").replace(" ", ""); } if (linha.contains("port:")) { portEmail = linha.replace("port:", "").replace(" ", ""); } if (linha.contains("user:")) { userEmail = linha.replace("user:", "").replace(" ", ""); } if (linha.contains("pass:")) { passEmail = linha.replace("pass:", "").replace(" ", ""); } if (linha.contains("from:")) { fromEmail = linha.replace("from:", "").replace(" ", ""); } if (linha.contains("to:")) { toEmail = linha.replace("to:", "").replace(" ", ""); } } } } catch (FileNotFoundException ex) { Logger.getLogger(NotaBO.class.getName()).log(Level.SEVERE, null, ex); StackTraceElement st[] = ex.getStackTrace(); String erro = ""; for (int i = 0; i < st.length; i++) { erro += st[i].toString() + "\n"; } } catch (IOException ex) { Logger.getLogger(NotaBO.class.getName()).log(Level.SEVERE, null, ex); StackTraceElement st[] = ex.getStackTrace(); String erro2 = ""; for (int i = 0; i < st.length; i++) { erro2 += st[i].toString() + "\n"; } } /*FIM - Pegar Configuraes de email do arquivo*/ NotaDAO notaDAO = new NotaDAO(); try { ultimasAtual = notaDAO.getUltimaNotaMesAtual(); ultimasAnterior = notaDAO.getUltimaNotaMesAnterior(); naoEncontradas = new ArrayList<>(); for (Nota notaAnterior : ultimasAnterior) { for (Nota notaAtual : ultimasAtual) { if (notaAnterior.getLoja() == notaAtual.getLoja()) { //System.out.println("Anterior Loja: "+notaAnterior.getLoja()+" Nota: "+notaAnterior.getNumero()); //System.out.println("Atual Loja: "+notaAtual.getLoja()+" Nota: "+notaAtual.getNumero()); Integer numero = 0; for (Integer i = notaAnterior.getNumero(); i <= notaAtual.getNumero(); i++) { numero = i; Nota notacorrente = new Nota(); notacorrente.setLoja(notaAnterior.getLoja()); notacorrente.setNumero(numero); notacorrente.setSerie(notaAnterior.getSerie()); //System.out.println("Corrente Loja: "+notacorrente.getLoja()+" Nota: "+notacorrente.getNumero()); if (!notaDAO.notaIsValida(notacorrente)) { System.out.println("Loja " + notaAnterior.getLoja() + " Numero: " + numero); naoEncontradas.add(notacorrente); msg = msg.concat(" Loja: " + notacorrente.getLoja() + " Nota: " + notacorrente.getNumero() + " Serie: " + notacorrente.getSerie() + " \n"); } } } } } if (naoEncontradas.size() > 0) { Email email = new SimpleEmail(); email.setHostName(hostEmail); email.setSmtpPort(Integer.parseInt(portEmail)); email.setAuthentication(userEmail, passEmail); email.setFrom(fromEmail); email.setSubject("Alerta Nerus!!"); email.setMsg(msg); email.addTo(toEmail); email.send(); } } catch (Exception ex) { Logger.getLogger(NotaBO.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:com.lyonsdensoftware.vanitymirror.PythonConnectionThread.java
@Override public void run() { // Try connecting to the master server try {/*from w ww . j a va 2s . c o m*/ // Create a socket to connect to the server this.socket = new Socket(this.mainWindow.getConfigFile().getHostname(), this.mainWindow.getConfigFile().getPort()); // Note it in the log log.info("LOG", "Connect to MasterServer at IP: " + socket.getInetAddress().getHostAddress() + " on PORT: " + socket.getPort()); connectedToServer = true; // Create an input stream to receive data from the server mainWindow.setFromServer(new DataInputStream(socket.getInputStream())); // Create an output stream to send data to the server mainWindow.setToServer(new DataOutputStream(socket.getOutputStream())); // Main Loop while (runThread) { // Check for data from the server BufferedReader in = new BufferedReader(new InputStreamReader(mainWindow.getFromServer())); if (in.ready()) { // Convert in data to json Gson gson = new Gson(); JSONObject json = new JSONObject(gson.fromJson(in.readLine(), JSONObject.class)); if (json.keys().hasNext()) { // handle the data handleDataFromServer(json); } else { System.out.println(json.toString()); } } } // Loop not running now so close connection socket.close(); mainWindow.getFromServer().close(); mainWindow.getToServer().close(); } catch (IOException ex) { log.error("ERROR", ex.toString()); } }
From source file:com.civprod.writerstoolbox.NaturalLanguage.util.RegexStringTokenizer.java
public List<String> TokenizeFileAsOneLine(File inFile) { List<String> ReturnList = new java.util.ArrayList<String>(0); try {//from w w w. j av a2 s . c om java.io.BufferedReader fin = new java.io.BufferedReader(new java.io.FileReader(inFile)); try { while (fin.ready()) { String Line = fin.readLine(); ReturnList.addAll(tokenize(Line)); } } catch (IOException ex) { Logger.getLogger(RegexStringTokenizer.class.getName()).log(Level.SEVERE, null, ex); } finally { try { fin.close(); } catch (IOException ex) { Logger.getLogger(RegexStringTokenizer.class.getName()).log(Level.SEVERE, null, ex); } } } catch (FileNotFoundException ex) { Logger.getLogger(RegexStringTokenizer.class.getName()).log(Level.SEVERE, null, ex); } return ReturnList; }
From source file:di.uniba.it.tee2.text.TextDirIndex.java
private void processFile(File inFile) throws IOException, InterruptedException { if (inFile.isDirectory()) { File[] files = inFile.listFiles(); for (File file : files) { processFile(file);/*from w w w . jav a 2 s.com*/ } } else { BufferedReader reader = new BufferedReader(new FileReader(inFile)); String title = ""; StringBuilder content = new StringBuilder(); if (reader.ready()) { title = reader.readLine(); } while (reader.ready()) { content.append(reader.readLine()).append("\n"); } pages.put(new TxtDoc(title, content.toString(), inFile.getName())); } }
From source file:fi.uta.infim.usaproxylogparser.UsaProxyHTTPTrafficLogParser.java
/** * Seeks the http traffic log file until the actual document is found. * @param traffic the http traffic object * @return a reader object with the file contents seeked to the beginning of the actual document. * @throws IOException// ww w . ja v a 2 s. c o m */ private Reader getSeekedLogReader(UsaProxyHTTPTraffic traffic) throws IOException { FileInputStream fis = new FileInputStream(handler.findHTTPTrafficLog(traffic)); BufferedReader fileReader = new BufferedReader(new InputStreamReader(fis)); int emptyLinesFound = 0; while (fileReader.ready()) { // Actual document start after the 2nd empty line if (fileReader.readLine().trim().length() == 0) emptyLinesFound++; if (emptyLinesFound == 2) break; } return fileReader; }
From source file:org.dishevelled.cluster.examples.ConnectedComponentsExample.java
/** * Read values one per line from standard in. * * @return values read from standard in/*from w ww . ja va2s. c om*/ */ private List<String> readValues() { List<String> values = new ArrayList<String>(10000); BufferedReader reader = null; try { reader = new BufferedReader(new InputStreamReader(System.in)); while (reader.ready()) { String line = reader.readLine(); values.add(line); } } catch (IOException e) { e.printStackTrace(); } finally { try { if (reader != null) { reader.close(); } } catch (Exception e) { // ignore } } return values; }
From source file:org.talend.dataquality.email.checkerImpl.CallbackMailServerCheckerImpl.java
/** * // w ww .j a va 2s .com * Get response status's code, 250 means OK, queuing for node node started. Requested mail action okay, completed. * See more details at http://email.about.com/cs/standards/a/smtp_error_code_2.htm * * @param in * @return * @throws IOException */ private static int getResponse(BufferedReader in) throws IOException, TalendSMTPRuntimeException { String line = null; int res = 0; do { try { line = in.readLine(); } catch (IOException e) { line = e.getMessage(); LOG.warn(line, e); continue; } if (LOG.isInfoEnabled()) { LOG.info(line); } // Make sure the input stream is over and not effect next one read if (line == null) { break; } if (res != 0 && line.charAt(3) != '-') { continue; } // if in.ready() is true then line will not be null String pfx = line.substring(0, 3); try { res = Integer.parseInt(pfx); } catch (NumberFormatException ex) { res = -1; } } while (in.ready()); // line.contains("authentication is required") judge whether authentication is required(for example 139.com) if (res != 250 && res != 221 && res != 220 || line.contains("authentication is required")) { //$NON-NLS-1$ throw new TalendSMTPRuntimeException(line); } return res; }
From source file:org.wso2.carbon.repository.core.utils.MediaTypesUtils.java
/** * Method to obtain the resource media types. * * @param configSystemRegistry a configuration system registry instance. * * @return a String of resource media types, in the format extension:type,extension:type,... * @throws RepositoryException if the operation failed. *//*from w w w . ja v a 2 s .c om*/ public static String getResourceMediaTypeMappings(Repository configSystemRegistry) throws RepositoryException { String resourceMediaTypeMappings = configSystemRegistry.getResourceMediaTypes(); if (resourceMediaTypeMappings != null) { return resourceMediaTypeMappings; } Resource resource; String mediaTypeString = null; String resourcePath = MIME_TYPE_COLLECTION + RepositoryConstants.PATH_SEPARATOR + RESOURCE_MIME_TYPE_INDEX; if (!configSystemRegistry.resourceExists(resourcePath)) { resource = configSystemRegistry.newCollection(); } else { resource = configSystemRegistry.get(resourcePath); for (String key : resource.getPropertyKeys()) { if (RepositoryUtils.isHiddenProperty(key)) { continue; } String value = resource.getPropertyValue(key); String mediaTypeMapping = key + ":" + value; if (mediaTypeString == null) { mediaTypeString = mediaTypeMapping; } else { mediaTypeString = mediaTypeString + "," + mediaTypeMapping; } } configSystemRegistry.setResourceMediaTypes(mediaTypeString); MediaTypesUtils.setResourceMediaTypes(mediaTypeString); return mediaTypeString; } BufferedReader reader; try { File mimeFile = getMediaTypesFile(); reader = new BufferedReader(new InputStreamReader(new FileInputStream(mimeFile))); } catch (Exception e) { String msg = "Failed to read the the media type definitions file. Only a limited " + "set of media type definitions will be populated. "; log.error(msg, e); mediaTypeString = "txt:text/plain,jpg:image/jpeg,gif:image/gif"; configSystemRegistry.setResourceMediaTypes(mediaTypeString); return mediaTypeString; } try { while (reader.ready()) { String mediaTypeData = reader.readLine().trim(); if (mediaTypeData.startsWith("#")) { // ignore the comments continue; } if (mediaTypeData.length() == 0) { // ignore the blank lines continue; } // mime.type file delimits media types:extensions by tabs. if there is no // extension associated with a media type, there are no tabs in the line. so we // don't need such lines. if (mediaTypeData.indexOf('\t') > 0) { String[] parts = mediaTypeData.split("\t+"); if (parts.length == 2 && parts[0].length() > 0 && parts[1].length() > 0) { // there can multiple extensions associated with a single media type. in // that case, extensions are delimited by a space. String[] extensions = parts[1].trim().split(" "); for (String extension : extensions) { if (extension.length() > 0) { String mediaTypeMapping = extension + ":" + parts[0]; resource.setProperty(extension, parts[0]); if (mediaTypeString == null) { mediaTypeString = mediaTypeMapping; } else { mediaTypeString = mediaTypeString + "," + mediaTypeMapping; } } } } } } resource.setDescription("This collection contains the media Types available for " + "resources on the Registry. Add, Edit or Delete properties to Manage Media " + "Types."); Resource collection = configSystemRegistry.newCollection(); collection.setDescription("This collection lists the media types available on the " + "Registry Server. Before changing an existing media type, please make sure " + "to alter existing resources/collections and related configuration details."); configSystemRegistry.put(MIME_TYPE_COLLECTION, collection); configSystemRegistry.put(resourcePath, resource); } catch (IOException e) { String msg = "Could not read the media type mappings file from the location: "; throw new RepositoryUserContentException(msg, e, RepositoryErrorCodes.UNAVAILABLE_FILE_REFERRED); } finally { try { reader.close(); } catch (IOException ignore) { } } configSystemRegistry.setResourceMediaTypes(mediaTypeString); MediaTypesUtils.setResourceMediaTypes(mediaTypeString); return mediaTypeString; }