List of usage examples for java.io BufferedReader markSupported
public boolean markSupported()
From source file:Main.java
public static void main(String[] args) throws Exception { InputStream is = new FileInputStream("c:/test.txt"); InputStreamReader isr = new InputStreamReader(is); BufferedReader br = new BufferedReader(isr); boolean bool = false; bool = br.markSupported(); System.out.println("Buffered reader supports mark : " + bool); }
From source file:edu.lternet.pasta.gatekeeper.GatekeeperFilter.java
/** * dumpBody outputs the contents of the request message body to the * designated logger. Note that the use of this method will render the * request object inoperable for and subsequent calls. * //w w w . ja va 2s . com * @param req * the HttpServletRequest object. * @param contentLength * the content length that was specified in the * request headers, possibly null */ private void dumpBody(HttpServletRequest req, Integer contentLength) { if (contentLength != null) { try { BufferedReader br = req.getReader(); String line = null; logger.info("Request message body:\n"); if (br.markSupported()) { br.mark(contentLength + 1); while ((line = br.readLine()) != null) { System.out.println(line); } br.reset(); } br.close(); } catch (IOException e) { logger.error("dumpBody: " + e); e.printStackTrace(); } } }
From source file:edu.harvard.iq.dvn.ingest.statdataio.impl.plugins.por.PORFileReader.java
private void decodeSec2(BufferedReader reader) throws IOException { dbgLog.fine("***** decodeSec2(): start *****"); if (reader == null) { throw new IllegalArgumentException("decodeSec2: stream == null!"); }/*w w w .ja v a2 s. com*/ // Because a 64-bit machine may not save the first 40 // bytes of a POR file in a way as a 32-bit machine does, // the first 5 lines of a POR file is excluded from the read-back // file and the new 1st line contains the format mark "SPSSPORT" // somewhere in it. // mark the start position for the later rewind if (reader.markSupported()) { reader.mark(100000); } char[] sixthLineCharArray = new char[80]; int nbytes_sixthLine = reader.read(sixthLineCharArray); String sixthLine = new String(sixthLineCharArray); dbgLog.info("sixthLineCharArray=" + Arrays.deepToString(ArrayUtils.toObject(sixthLineCharArray))); int signatureLocation = sixthLine.indexOf(POR_MARK); if (signatureLocation >= 0) { dbgLog.info("format signature was found at:" + signatureLocation); } else { dbgLog.severe("signature string was not found"); throw new IOException("signature string was not found"); } // rewind the position to the beginning reader.reset(); // skip bytes up to the signature string long skippedBytes = reader.skip(signatureLocation); char[] sec2_leader = new char[POR_MARK.length()]; int nbytes_sec2_leader = reader.read(sec2_leader); String leader_string = new String(sec2_leader); dbgLog.info("format signature [SPSSPORT] detected=" + leader_string); if (leader_string.equals("SPSSPORT")) { dbgLog.info("signature was correctly detected"); } else { dbgLog.severe("the format signature is not found at the previously located column"); throw new IOException("decodeSec2: failed to find the signature string"); } int length_section_2 = LENGTH_SECTION_2; char[] Sec2_bytes = new char[length_section_2]; int nbytes_sec2 = reader.read(Sec2_bytes); if (nbytes_sec2 == 0) { dbgLog.severe("decodeSec2: reading error"); throw new IOException("decodeSec2: reading error"); } else { dbgLog.fine("bytes read=" + nbytes_sec2); } String sec2 = new String(Sec2_bytes); dbgLog.fine("sec2[creation date/time]=" + sec2); // sec2 // 0123456789012345678 // A8/YYYYMMDD6/HHMMSS // thus // section2 should has 3 elements String[] section2 = StringUtils.split(sec2, '/'); dbgLog.fine("section2=" + StringUtils.join(section2, "|")); String fileCreationDate = null; String fileCreationTime = null; if ((section2.length == 3) && (section2[0].startsWith("A"))) { fileCreationDate = section2[1].substring(0, 7); fileCreationTime = section2[2]; } else { dbgLog.severe("decodeSec2: file creation date/time were not correctly detected"); throw new IOException("decodeSec2: file creation date/time were not correctly detected"); } dbgLog.fine("fileCreationDate=" + fileCreationDate); dbgLog.fine("fileCreationTime=" + fileCreationTime); smd.getFileInformation().put("fileCreationDate", fileCreationDate); smd.getFileInformation().put("fileCreationTime", fileCreationTime); smd.getFileInformation().put("varFormat_schema", "SPSS"); }
From source file:edu.harvard.iq.dataverse.ingest.tabulardata.impl.plugins.por.PORFileReader.java
private void decodeSec2(BufferedReader reader) throws IOException { dbgLog.fine("decodeSec2(): start"); if (reader == null) { throw new IllegalArgumentException("decodeSec2: stream == null!"); }//from ww w.j av a2s . com // Because a 64-bit machine may not save the first 40 // bytes of a POR file in a way as a 32-bit machine does, // the first 5 lines of a POR file is excluded from the read-back // file and the new 1st line contains the format mark "SPSSPORT" // somewhere in it. // mark the start position for the later rewind if (reader.markSupported()) { reader.mark(100000); } char[] sixthLineCharArray = new char[80]; int nbytes_sixthLine = reader.read(sixthLineCharArray); String sixthLine = new String(sixthLineCharArray); dbgLog.fine("sixthLineCharArray=" + Arrays.deepToString(ArrayUtils.toObject(sixthLineCharArray))); int signatureLocation = sixthLine.indexOf(POR_MARK); if (signatureLocation >= 0) { dbgLog.fine("format signature was found at:" + signatureLocation); } else { dbgLog.severe("signature string was not found"); throw new IOException("signature string was not found"); } // rewind the position to the beginning reader.reset(); // skip bytes up to the signature string long skippedBytes = reader.skip(signatureLocation); char[] sec2_leader = new char[POR_MARK.length()]; int nbytes_sec2_leader = reader.read(sec2_leader); String leader_string = new String(sec2_leader); dbgLog.fine("format signature [SPSSPORT] detected=" + leader_string); if (leader_string.equals("SPSSPORT")) { dbgLog.fine("signature was correctly detected"); } else { dbgLog.severe("the format signature is not found at the previously located column"); throw new IOException("decodeSec2: failed to find the signature string"); } int length_section_2 = LENGTH_SECTION_2; char[] Sec2_bytes = new char[length_section_2]; int nbytes_sec2 = reader.read(Sec2_bytes); if (nbytes_sec2 == 0) { dbgLog.severe("decodeSec2: reading error"); throw new IOException("decodeSec2: reading error"); } else { dbgLog.fine("bytes read=" + nbytes_sec2); } String sec2 = new String(Sec2_bytes); dbgLog.fine("sec2[creation date/time]=" + sec2); // sec2 // 0123456789012345678 // A8/YYYYMMDD6/HHMMSS // thus // section2 should has 3 elements String[] section2 = StringUtils.split(sec2, '/'); dbgLog.fine("section2=" + StringUtils.join(section2, "|")); String fileCreationDate = null; String fileCreationTime = null; if ((section2.length == 3) && (section2[0].startsWith("A"))) { fileCreationDate = section2[1].substring(0, 7); fileCreationTime = section2[2]; } else { dbgLog.severe("decodeSec2: file creation date/time were not correctly detected"); throw new IOException("decodeSec2: file creation date/time were not correctly detected"); } dbgLog.fine("fileCreationDate=" + fileCreationDate); dbgLog.fine("fileCreationTime=" + fileCreationTime); ///smd.getFileInformation().put("fileCreationDate", fileCreationDate); ///smd.getFileInformation().put("fileCreationTime", fileCreationTime); ///smd.getFileInformation().put("varFormat_schema", "SPSS"); dbgLog.fine("decodeSec2(): end"); }
From source file:com.photon.phresco.framework.actions.applications.Build.java
public String readLogFile(Project project, String fromNodejs) { StringBuilder builder = new StringBuilder(Utility.getProjectHome()); builder.append(project.getProjectInfo().getCode()); builder.append(File.separator); builder.append(DO_NOT_CHECKIN_DIR);/*from w ww . ja v a 2 s . c o m*/ builder.append(File.separator); builder.append(NODEJS_LOG_DIR); builder.append(File.separator); builder.append(NODEJS_LOG_FILE); BufferedReader reader = null; StringBuffer contents = new StringBuffer(); try { File file = new File(builder.toString()); // It executed when file not exist and view method called if (!file.exists() && fromNodejs.equals(READ_LOG_VIEW)) { return ""; } // It executed when file exist and view method called if (file.exists() && fromNodejs.equals(READ_LOG_VIEW)) { reader = new BufferedReader(new FileReader(file)); String text = null; while ((text = reader.readLine()) != null) { contents.append(text).append(System.getProperty(LINE_SEPERATOR)); } return contents.toString(); } // It executed when file not exist and return reader if (!file.exists()) { StringReader sb = new StringReader("Server started successfully..."); reader = new BufferedReader(sb); // getHttpSession().setAttribute(REQ_READER, reader); getHttpSession().setAttribute(projectCode + REQ_READ_LOG_FILE, reader); getHttpRequest().setAttribute(REQ_PROJECT_CODE, projectCode); getHttpRequest().setAttribute(REQ_TEST_TYPE, REQ_READ_LOG_FILE); } // It executed when file existence and return reader if (file.exists()) { waitForTime(2); reader = new BufferedReader(new FileReader(file)); // getHttpSession().setAttribute(REQ_READER, reader); @SuppressWarnings("unused") String line = null; if (reader.markSupported()) { reader.mark(1); if ((line = reader.readLine()) == null) { reader = new BufferedReader(new StringReader("Server started successfully...")); } else { reader.reset(); } } getHttpSession().setAttribute(projectCode + REQ_READ_LOG_FILE, reader); getHttpRequest().setAttribute(REQ_PROJECT_CODE, projectCode); getHttpRequest().setAttribute(REQ_TEST_TYPE, REQ_READ_LOG_FILE); } } catch (FileNotFoundException e) { if (debugEnabled) { S_LOGGER.error( "Entered into catch block of Build.readLogFile()" + FrameworkUtil.getStackTraceAsString(e)); } } catch (IOException e) { if (debugEnabled) { S_LOGGER.error( "Entered into catch block of Build.readLogFile()" + FrameworkUtil.getStackTraceAsString(e)); } } return null; }
From source file:org.alfresco.repo.search.impl.lucene.analysis.VerbatimMLAnalayser.java
@Override public TokenStream tokenStream(String fieldName, Reader reader) { // We use read ahead to get the language info - if this does not exist we need to restart // an use the default - there foer we need mark and restore. if (!(reader instanceof BufferedReader)) { BufferedReader breader = new BufferedReader(reader); try {/* w w w . j av a 2 s.c o m*/ if (!breader.markSupported()) { throw new AnalysisException( "Multilingual tokenisation requires a reader that supports marks and reset"); } breader.mark(100); StringBuilder builder = new StringBuilder(); if (breader.read() == '\u0000') { String language = ""; String country = ""; String varient = ""; char c; int count = 0; while ((c = (char) breader.read()) != '\u0000') { if (count++ > 99) { breader.reset(); return getAnalyser().tokenStream(fieldName, breader); } if (c == '_') { if (language.length() == 0) { language = builder.toString(); } else if (country.length() == 0) { country = builder.toString(); } else if (varient.length() == 0) { varient = builder.toString(); } else { breader.reset(); return getAnalyser().tokenStream(fieldName, breader); } builder = new StringBuilder(); } else { builder.append(c); } } if (builder.length() > 0) { if (language.length() == 0) { language = builder.toString(); } else if (country.length() == 0) { country = builder.toString(); } else if (varient.length() == 0) { varient = builder.toString(); } else { breader.reset(); return getAnalyser().tokenStream(fieldName, breader); } } Locale locale = new Locale(language, country, varient); // leave the reader where it is .... return new MLTokenDuplicator(getAnalyser().tokenStream(fieldName, breader), locale, breader, mlAnalaysisMode); } else { breader.reset(); return getAnalyser().tokenStream(fieldName, breader); } } catch (IOException io) { try { breader.reset(); } catch (IOException e) { throw new AnalysisException("Failed to reset buffered reader - token stream will be invalid", e); } return getAnalyser().tokenStream(fieldName, breader); } } else { throw new AnalysisException("Multilingual tokenisation requires a buffered reader"); } }
From source file:uk.ac.sanger.cgp.dbcon.sqllibs.SqlLibraries.java
/** * Takes in a string and looks to see if it is an XML definition file *///from w w w . ja v a2s . c om private LibraryParser detectAndCreateParser(Reader reader) throws SqlLibraryRuntimeException { LibraryParser parser = null; try { BufferedReader br = new BufferedReader(reader); if (!br.markSupported()) { throw new SqlLibraryRuntimeException("Reader does not support marking - aborting"); } br.mark(50); char[] xmlDefArray = new char[6]; br.read(xmlDefArray, 0, 6); br.reset(); String xmlDef = new String(xmlDefArray); if (xmlDef.matches("^.*<\\?xml.*")) { if (log.isInfoEnabled()) log.info("Detected .xml sql library"); parser = new XMLLibraryParser(); } else { if (log.isInfoEnabled()) log.info("Detected .sqllib sql library"); parser = new SqlLibLibraryParser(); } } catch (IOException e) { throw new SqlLibraryRuntimeException("Error occured whilst testing the InputStream for XML syntax", e); } return parser; }