HOCRFileReader { public String readHOCRFile(final String pathOfHOCRFile) throws DCMAApplicationException { final StringBuffer infoHOCRFile = new StringBuffer(); synchronized (object) { String errMsg = null; if (null == pathOfHOCRFile || RegexConstants.EMPTY.equals(pathOfHOCRFile)) { errMsg = "Invalid HOCR file path."; throw new DCMAApplicationException(errMsg); } FileInputStream fstream = null; DataInputStream dataInStr = null; BufferedReader bufReader = null; try { fstream = new FileInputStream(pathOfHOCRFile); dataInStr = new DataInputStream(fstream); bufReader = new BufferedReader(new InputStreamReader(dataInStr)); String strLine = bufReader.readLine(); while (strLine != null) { infoHOCRFile.append(strLine); strLine = bufReader.readLine(); } } catch (Exception e) { LOGGER.error("Error: " + e.getMessage()); throw new DCMAApplicationException(e.getMessage(), e); } finally { if (fstream != null) { try { fstream.close(); } catch (IOException e) { LOGGER.error("Problem in closing input stream: " + e.getMessage(), e); } } if (dataInStr != null) { try { dataInStr.close(); } catch (IOException e) { LOGGER.error("Problem in closing input stream: " + e.getMessage(), e); } } if (bufReader != null) { try { bufReader.close(); } catch (IOException e) { LOGGER.error("Problem in closing input stream: " + e.getMessage(), e); } } } } return infoHOCRFile.toString(); } private  HOCRFileReader(); static HOCRFileReader getInstance(); String readHOCRFile(final String pathOfHOCRFile);  }
@Test public void testReadHOCRFile() { Boolean isSuccess = Boolean.FALSE; try { String hicrReaderObj = HOCRFileReader.getInstance().readHOCRFile( "E:\\file\\111\\output1024.html"); if (null == hicrReaderObj || "".equals(hicrReaderObj)) { isSuccess = Boolean.FALSE; } else { isSuccess = Boolean.TRUE; } } catch (DCMAApplicationException e) { LOGGER.error("Exception in execute method " + e.getMessage()); assertTrue(e.getMessage(), false); } assertTrue(isSuccess.booleanValue()); }