Example usage for java.io BufferedReader ready

List of usage examples for java.io BufferedReader ready

Introduction

In this page you can find the example usage for java.io BufferedReader ready.

Prototype

public boolean ready() throws IOException 

Source Link

Document

Tells whether this stream is ready to be read.

Usage

From source file:org.kuali.kfs.sys.service.impl.ReportAggregatorServiceTextImpl.java

protected int dumpFileContents(Writer outputWriter, File file, int currentPageNumber) {
    try {//w w  w.j a va2  s.  c o  m
        BufferedReader reader = new BufferedReader(new FileReader(file));
        while (reader.ready()) {
            String line = reader.readLine();
            while (line.contains(KFSConstants.REPORT_WRITER_SERVICE_PAGE_NUMBER_PLACEHOLDER)) {
                line = StringUtils.replaceOnce(line, KFSConstants.REPORT_WRITER_SERVICE_PAGE_NUMBER_PLACEHOLDER,
                        String.valueOf(currentPageNumber));
                currentPageNumber++;
            }
            outputWriter.write(line);
            outputWriter.write(newLineCharacter);
        }
        reader.close();
        return currentPageNumber;
    } catch (IOException e) {
        throw new RuntimeException("Error reading or writing file", e);
    }
}

From source file:gov.nih.nci.ncicb.tcga.dcc.qclive.common.util.FileListReader.java

public List<String> readFileWithList(InputStream is) throws IOException {
    Reader isr = new InputStreamReader(is);
    BufferedReader in = new BufferedReader(isr);
    try {/*from  www.ja va  2s .co  m*/
        while (in.ready()) {
            try {
                final String text = in.readLine().trim();
                if (text.trim().length() > 0 && !text.trim().equals("->")) {
                    fileToReadList.add(text.trim());
                }
            } catch (IOException e) {
                throw new IllegalArgumentException(e);
            }
        }
    } finally {
        try {
            in.close();
            isr.close();
            is.close();
            in = null;
            isr = null;
            is = null;
        } catch (IOException ignored) {
            //Do nothing here just keep going
        }
    }
    return fileToReadList;
}

From source file:org.wso2.carbon.registry.core.utils.MediaTypesUtils.java

private static void populateMediaTypeMappings() throws RegistryException {
    BufferedReader reader;
    humanReadableMediaTypeMap = new HashMap<String, String>();
    try {//w  w  w .  j a  v  a  2s .c o  m
        File mimeFile = getHumanMediaTypeMappingsFile();
        reader = new BufferedReader(new InputStreamReader(new FileInputStream(mimeFile)));
    } catch (Exception e) {
        String msg = FAILED_TO_READ_THE_THE_HUMAN_READABLE_MEDIA_TYPE_MIME_TYPE_MAPPINGS_FILE_MSG;
        log.warn(msg, e);
        return;
    }

    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.mappings 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.
                    humanReadableMediaTypeMap.put(parts[1], parts[0]);
                }
            }
        }
    } catch (IOException e) {
        String msg = FAILED_TO_READ_THE_THE_HUMAN_READABLE_MEDIA_TYPE_MIME_TYPE_MAPPINGS_FILE_MSG;
        log.error(msg, e);
        throw new RegistryException(msg);
    } finally {
        try {
            reader.close();
            if (humanReadableMediaTypeMap == null) {
                humanReadableMediaTypeMap = Collections.emptyMap();
            }
        } catch (IOException ignore) {
        }
    }
}

From source file:br.com.ant.system.util.ImportarArquivoCidades.java

private List<String[]> getListLinhas(File file) throws FileNotFoundException, IOException {
    FileReader fileReader;/*from   ww w  .j  a va  2  s.  c  om*/
    List<String[]> linhas = new ArrayList<String[]>();
    fileReader = new FileReader(file);
    BufferedReader bufferedReader = new BufferedReader(fileReader);
    while (bufferedReader.ready()) {
        linhas.add(bufferedReader.readLine().split(";"));
    }
    return linhas;
}

From source file:com.appglu.impl.AbstractAppGluApiTest.java

protected String readCompactedJsonResource(Resource resource) {
    StringBuilder resourceText = new StringBuilder();
    try {//from w w w. j  av  a  2 s  .com
        BufferedReader reader = new BufferedReader(new InputStreamReader(resource.getInputStream()));
        while (reader.ready()) {
            resourceText.append(reader.readLine().trim().replace("\n", ""));
        }
    } catch (IOException e) {
    }
    return resourceText.toString();
}

From source file:org.springframework.social.support.LoggingErrorHandler.java

@Override
public void handleError(ClientHttpResponse response) throws IOException {

    BufferingClientHttpResponse bufferedResponse = new BufferingClientHttpResponse(response);

    InputStream bodyStream = bufferedResponse.getBody();
    BufferedReader reader = new BufferedReader(new InputStreamReader(bodyStream));
    StringBuffer buffer = new StringBuffer();
    while (reader.ready()) {
        buffer.append(reader.readLine());
    }/* ww  w  .ja v  a2s  .com*/

    if (LOG.isErrorEnabled()) {
        LOG.error("Response body: " + buffer.toString());
    }

    super.handleError(bufferedResponse);
}

From source file:com.google.gplus.GooglePlusPersonSerDeTest.java

@Test
public void TestPersonObjects() {
    InputStream is = GooglePlusPersonSerDeTest.class.getResourceAsStream("/google_plus_person_jsons.txt");
    InputStreamReader isr = new InputStreamReader(is);
    BufferedReader br = new BufferedReader(isr);

    try {/* ww  w .  ja v  a2  s.co m*/
        while (br.ready()) {
            String line = br.readLine();
            if (!StringUtils.isEmpty(line)) {
                LOGGER.info("raw: {}", line);
                Activity activity = new Activity();

                Person person = objectMapper.readValue(line, Person.class);

                googlePlusActivityUtil.updateActivity(person, activity);
                LOGGER.info("activity: {}", activity);

                assertNotNull(activity);
                assert (activity.getId().contains("id:googleplus:update"));
                assertEquals(activity.getVerb(), "update");

                Provider provider = activity.getProvider();
                assertEquals(provider.getId(), "id:providers:googleplus");
                assertEquals(provider.getDisplayName(), "GooglePlus");

                Actor actor = activity.getActor();
                assertNotNull(actor.getImage());
                assert (actor.getId().contains("id:googleplus:"));
                assertNotNull(actor.getUrl());

                assertNotNull(activity.getPublished());
            }
        }
    } catch (Exception e) {
        LOGGER.error("Exception while testing serializability: {}", e);
    }
}

From source file:com.google.gplus.processor.GooglePlusTypeConverterTest.java

@Test
public void testProcessActivity() throws IOException, ActivitySerializerException {
    InputStream is = GooglePlusTypeConverterTest.class.getResourceAsStream("/google_plus_activity_jsons.txt");
    InputStreamReader isr = new InputStreamReader(is);
    BufferedReader br = new BufferedReader(isr);

    while (br.ready()) {
        String line = br.readLine();
        if (!StringUtils.isEmpty(line)) {
            LOGGER.info("raw: {}", line);
            Activity activity = new Activity();

            com.google.api.services.plus.model.Activity gPlusActivity = objectMapper.readValue(line,
                    com.google.api.services.plus.model.Activity.class);
            StreamsDatum streamsDatum = new StreamsDatum(gPlusActivity);

            assertNotNull(streamsDatum.getDocument());

            List<StreamsDatum> retList = googlePlusTypeConverter.process(streamsDatum);
            GooglePlusActivityUtil.updateActivity(gPlusActivity, activity);

            assertEquals(retList.size(), 1);
            assert (retList.get(0).getDocument() instanceof Activity);
            assertEquals(activity, retList.get(0).getDocument());
        }/*from w ww  . j a  v a  2 s . c o  m*/
    }
}

From source file:com.google.gplus.processor.GooglePlusTypeConverterTest.java

@Test
public void testProcessPerson() throws IOException, ActivitySerializerException {
    InputStream is = GooglePlusTypeConverterTest.class.getResourceAsStream("/google_plus_person_jsons.txt");
    InputStreamReader isr = new InputStreamReader(is);
    BufferedReader br = new BufferedReader(isr);

    while (br.ready()) {
        String line = br.readLine();
        if (!StringUtils.isEmpty(line)) {
            LOGGER.info("raw: {}", line);
            Activity activity = new Activity();

            Person person = objectMapper.readValue(line, Person.class);
            StreamsDatum streamsDatum = new StreamsDatum(person);

            assertNotNull(streamsDatum.getDocument());

            List<StreamsDatum> retList = googlePlusTypeConverter.process(streamsDatum);
            GooglePlusActivityUtil.updateActivity(person, activity);

            assertEquals(retList.size(), 1);

            activity.setPublished(((Activity) retList.get(0).getDocument()).getPublished());
            assert (retList.get(0).getDocument() instanceof Activity);
            assertEquals(activity, retList.get(0).getDocument());
        }//from   w  w w. java2s .  com
    }
}

From source file:com.google.gplus.GooglePlusPersonSerDeIT.java

@Test
public void testPersonObjects() {
    InputStream is = GooglePlusPersonSerDeIT.class.getResourceAsStream("/google_plus_person_jsons.txt");
    InputStreamReader isr = new InputStreamReader(is);
    BufferedReader br = new BufferedReader(isr);

    try {//  ww  w. java  2 s  . c o  m
        while (br.ready()) {
            String line = br.readLine();
            if (!StringUtils.isEmpty(line)) {
                LOGGER.info("raw: {}", line);
                Activity activity = new Activity();

                Person person = objectMapper.readValue(line, Person.class);

                GooglePlusActivityUtil.updateActivity(person, activity);
                LOGGER.info("activity: {}", activity);

                assertNotNull(activity);
                assertTrue(activity.getId().contains("id:googleplus:update"));
                assertEquals(activity.getVerb(), "update");

                Provider provider = activity.getProvider();
                assertEquals(provider.getId(), "id:providers:googleplus");
                assertEquals(provider.getDisplayName(), "GooglePlus");

                ActivityObject actor = activity.getActor();
                assertNotNull(actor.getImage());
                assertTrue(actor.getId().contains("id:googleplus:"));
                assertNotNull(actor.getUrl());

            }
        }
    } catch (Exception ex) {
        LOGGER.error("Exception while testing serializability: {}", ex);
    }
}