Example usage for java.io BufferedReader read

List of usage examples for java.io BufferedReader read

Introduction

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

Prototype

public int read() throws IOException 

Source Link

Document

Reads a single character.

Usage

From source file:au.org.ands.vocabs.toolkit.provider.harvest.HarvestProvider.java

/** Get the contents of an InputStream as a String.
 * @param is The InputStream/* ww w . ja va 2  s. co  m*/
 * @return The contenxt of the InputStream as a String
 * @throws IOException An IOException
 */
public final String getFragment(final InputStream is) throws IOException {
    BufferedReader data = new BufferedReader(new InputStreamReader(is));
    StringBuffer buf = new StringBuffer();

    int aChar = -1;

    while ((aChar = data.read()) != -1) {
        buf.append((char) aChar);
    }

    data.close();

    return buf.toString();
}

From source file:com.sarm.lonelyplanet.common.GeoUtils.java

/**
 * This method parses a destination and creates an HTML file for that
 * destination. Steps involved in creating an HTML file for a destination
 *
 * 1 - Initialize the HTML Template - This defaultTemplate is a generic
 * structure of the required html file. It has place holders for the
 * different portions of texts. 2 - Create a navigation string with links
 * referencing to parents and all children under the destination 3 - Fill
 * the place holders with he appropriate texts and heading tags. 4 - Create
 * an HTML file using the destination title and converting spaces into
 * underscores and make the name of the file as in lowercase.
 *
 * @param destination/* ww  w. j av  a2s  . co  m*/
 * @param node
 * @param targetLocation
 * @throws IOException
 */
public static void createHtmlFromTemplate(Destination destination, Node node, String targetLocation)
        throws IOException, NullPointerException {
    StringBuilder breaker = new StringBuilder(LonelyConstants.BREAKER);
    File htmlTemplateFile = null;
    String htmlString;
    try {

        Reader reader = null;
        InputStream is = GeoUtils.class.getResourceAsStream("/" + LonelyConstants.defaultTemplate);
        if (null != is) {
            reader = new InputStreamReader(is);
        }
        BufferedReader bufRead = new BufferedReader(reader);
        StringBuilder htmlFileString = new StringBuilder();
        StringBuilder htmlFilefrString = new StringBuilder();
        int nextchar;
        while ((nextchar = bufRead.read()) != -1) {
            htmlFileString.append((char) nextchar);
        }

        htmlString = new String(htmlFileString);
        //            logger.debug("found template on Path on location" + LonelyConstants.defaultTemplate);

    } catch (FileNotFoundException ex) {
        logger.debug("Could not find template on Path, Getting Static HTML template"
                + htmlTemplateFile.getAbsolutePath());
        htmlString = LonelyConstants.destinationTemplateHtml;
    }

    String navigation = createNavigation(destination, node);
    htmlString = htmlString.replace("$navigation", navigation);

    String title = destination.getTitle();
    htmlString = htmlString.replace("$title", title);
    htmlString = htmlString.replace("$destinationName", destination.getTitle());

    String overview = (null != destination.getIntroduction() ? destination.getIntroduction()
            : new String(breaker));
    htmlString = htmlString.replace("$introduction", overview);

    StringBuilder sb = new StringBuilder();
    if (null != destination.getHistoryOverview()) {
        sb = getStringBuilderwithHeader(LonelyConstants.HEADER_TYPE_3, "historyOverview", "Overview");

        sb = sb.append(destination.getHistoryOverview());
        htmlString = htmlString.replace("$historyOverview", new String(sb));

    } else {
        htmlString = htmlString.replace("$historyOverview", breaker);

    }
    if (null != destination.getHistories() && destination.getHistories().size() != 0) {

        sb = getStringBuilderwithHeader(LonelyConstants.HEADER_TYPE_3, "history", " Background History");
        sb = formatList(destination.getHistories(), sb);
        htmlString = htmlString.replace("$histories", new String(sb));

    } else {

        htmlString = htmlString.replace("$histories", breaker);
    }

    if (null != destination.getBeforeYouGo()) {
        sb = getStringBuilderwithHeader(LonelyConstants.HEADER_TYPE_3, "beforeYouGo", "Before You Go");
        sb = formatList(destination.getBeforeYouGo(), sb);
        htmlString = htmlString.replace("$beforeYouGo", new String(sb));
    } else {
        htmlString = htmlString.replace("$beforeYouGo", breaker);
    }

    if (null != destination.getDangersAndAnnoyances()) {
        sb = getStringBuilderwithHeader(LonelyConstants.HEADER_TYPE_3, "dangersAndAnnoyances",
                "Dangers And Annoyances");
        sb = formatList(destination.getDangersAndAnnoyances(), sb);
        htmlString = htmlString.replace("$dangersAndAnnoyances", new String(sb));
    } else {
        htmlString = htmlString.replace("$dangersAndAnnoyances", breaker);

    }

    if (null != destination.getWhileYouAreThere()) {
        sb = getStringBuilderwithHeader(LonelyConstants.HEADER_TYPE_3, "whileyouarethere",
                "While You Are There");

        sb = formatList(destination.getWhileYouAreThere(), sb);
        htmlString = htmlString.replace("$whileYourArethere", new String(sb));
    } else {
        htmlString = htmlString.replace("$whileYourArethere", breaker);

    }

    if (null != destination.getCosts()) {
        sb = getStringBuilderwithHeader(LonelyConstants.HEADER_TYPE_3, "costs", "Costs");

        sb = formatList(destination.getCosts(), sb);
        htmlString = htmlString.replace("$costs", new String(sb));
    } else {
        htmlString = htmlString.replace("$costs", breaker);

    }
    if (null != destination.getGettingAroundAir()) {
        sb = getStringBuilderwithHeader(LonelyConstants.HEADER_TYPE_3, "gettingAroundAir", "Air");
        sb = formatList(destination.getGettingAroundAir(), sb);
        htmlString = htmlString.replace("$gettingAroundAir", new String(sb));
    } else {
        htmlString = htmlString.replace("$gettingAroundAir", breaker);

    }

    if (null != destination.getGettingAroundBicycle()) {
        sb = getStringBuilderwithHeader(LonelyConstants.HEADER_TYPE_3, "gettingAroundBicycle", "Bicycle");

        sb = formatList(destination.getGettingAroundBicycle(), sb);
        htmlString = htmlString.replace("$gettingAroundBicycle", new String(sb));
    } else {
        htmlString = htmlString.replace("$gettingAroundBicycle", breaker);

    }

    if (null != destination.getGettingAroundBoat()) {
        sb = getStringBuilderwithHeader(LonelyConstants.HEADER_TYPE_3, "gettingAroundBoat", "Boat");

        sb = formatList(destination.getGettingAroundBoat(), sb);
        htmlString = htmlString.replace("$gettingAroundBoat", new String(sb));
    } else {
        htmlString = htmlString.replace("$gettingAroundBoat", breaker);

    }

    if (null != destination.getGettingAroundBusnTram()) {
        sb = getStringBuilderwithHeader(LonelyConstants.HEADER_TYPE_3, "gettingAroundBusnTram", "Bus And Tram");

        sb = formatList(destination.getGettingAroundBusnTram(), sb);
        htmlString = htmlString.replace("$gettingAroundBusnTram", new String(sb));
    } else {
        htmlString = htmlString.replace("$gettingAroundBusnTram", breaker);

    }

    if (null != destination.getGettingAroundCarAndMotorCycle()) {
        sb = getStringBuilderwithHeader(LonelyConstants.HEADER_TYPE_3, "gettingAroundCarAndMotorCycle",
                "Car And MotorCycle");

        sb = formatList(destination.getGettingAroundCarAndMotorCycle(), sb);
        htmlString = htmlString.replace("$gettingAroundCarAndMotorCycle", new String(sb));
    } else {
        htmlString = htmlString.replace("$gettingAroundCarAndMotorCycle", breaker);

    }

    if (null != destination.getGettingAroundHitching()) {
        sb = getStringBuilderwithHeader(LonelyConstants.HEADER_TYPE_3, "gettingAroundHitching", "Hitching");

        sb = formatList(destination.getGettingAroundHitching(), sb);
        htmlString = htmlString.replace("$gettingAroundHitching", new String(sb));
    } else {
        htmlString = htmlString.replace("$gettingAroundHitching", breaker);

    }
    if (null != destination.getGettingAroundLocal()) {
        sb = getStringBuilderwithHeader(LonelyConstants.HEADER_TYPE_3, "getGettingAroundLocal",
                "Local Transport");

        sb = formatList(destination.getGettingAroundLocal(), sb);
        htmlString = htmlString.replace("$gettingAroundLocal", new String(sb));
    } else {
        htmlString = htmlString.replace("$gettingAroundLocal", breaker);

    }
    if (null != destination.getGettingAroundTrain()) {
        sb = getStringBuilderwithHeader(LonelyConstants.HEADER_TYPE_3, "getGettingAroundTrain", "Train");

        sb = formatList(destination.getGettingAroundTrain(), sb);
        htmlString = htmlString.replace("$gettingAroundTrain", new String(sb));
    } else {
        htmlString = htmlString.replace("$gettingAroundTrain", breaker);

    }

    if (null != destination.getGettingAroundOverview()) {
        sb = getStringBuilderwithHeader(LonelyConstants.HEADER_TYPE_3, "getGettingAroundOverview", "Overview");

        sb = sb.append(destination.getGettingAroundOverview());
        htmlString = htmlString.replace("$gettingAroundOverview", new String(sb));
    } else {
        htmlString = htmlString.replace("$gettingAroundOverview", breaker);

    }

    if (null != destination.getGettingThereAndAwayOverview()) {
        sb = getStringBuilderwithHeader(LonelyConstants.HEADER_TYPE_3, "getGettingThereAndAwayOverview",
                "Overview");

        sb = sb.append(destination.getGettingThereAndAwayOverview());
        htmlString = htmlString.replace("$gettingThereAndAwayOverview", new String(sb));
    } else {
        htmlString = htmlString.replace("$gettingThereAndAwayOverview", breaker);
    }

    if (null != destination.getGettingThereAir()) {
        sb = getStringBuilderwithHeader(LonelyConstants.HEADER_TYPE_3, "getGettingThereAir", "Air");

        sb = formatList(destination.getGettingThereAir(), sb);
        htmlString = htmlString.replace("$gettingThereAir", new String(sb));
    } else {
        htmlString = htmlString.replace("$gettingThereAir", breaker);

    }

    if (null != destination.getGettingThereBusnTram()) {
        sb = getStringBuilderwithHeader(LonelyConstants.HEADER_TYPE_3, "getGettingThereBusnTram",
                "Bus and Tram");

        sb = formatList(destination.getGettingThereBusnTram(), sb);
        htmlString = htmlString.replace("$gettingThereBusnTram", new String(sb));
    } else {
        htmlString = htmlString.replace("$gettingThereBusnTram", breaker);

    }

    if (null != destination.getGettingThereBicycle()) {
        sb = getStringBuilderwithHeader(LonelyConstants.HEADER_TYPE_3, "getGettingThereBicycle", "Bicycle");

        sb = formatList(destination.getGettingThereBicycle(), sb);
        htmlString = htmlString.replace("$gettingThereBicycle", new String(sb));
    } else {
        htmlString = htmlString.replace("$gettingThereBicycle", breaker);

    }
    if (null != destination.getGettingThereBoat()) {
        sb = getStringBuilderwithHeader(LonelyConstants.HEADER_TYPE_3, "getGettingThereBoat", "Boat");

        sb = formatList(destination.getGettingThereBoat(), sb);
        htmlString = htmlString.replace("$gettingThereBoat", new String(sb));
    } else {
        htmlString = htmlString.replace("$gettingThereBoat", breaker);

    }
    if (null != destination.getGettingThereCarAndMotorCycle()) {
        sb = getStringBuilderwithHeader(LonelyConstants.HEADER_TYPE_3, "getGettingThereCarAndMotorCycle",
                "Car and MotorCycle");

        sb = formatList(destination.getGettingThereCarAndMotorCycle(), sb);
        htmlString = htmlString.replace("$gettingThereCarAndMotorCycle", new String(sb));
    } else {
        htmlString = htmlString.replace("$gettingThereCarAndMotorCycle", breaker);

    }
    if (null != destination.getGettingThereLocal()) {
        sb = getStringBuilderwithHeader(LonelyConstants.HEADER_TYPE_3, "getGettingThereLocal",
                "Local Transport");

        sb = formatList(destination.getGettingThereLocal(), sb);
        htmlString = htmlString.replace("$gettingThereLocal", new String(sb));
    } else {
        htmlString = htmlString.replace("$gettingThereLocal", breaker);

    }

    if (null != destination.getGettingThereTrain()) {
        sb = getStringBuilderwithHeader(LonelyConstants.HEADER_TYPE_3, "getGettingThereTrain", "Train");

        sb = formatList(destination.getGettingThereTrain(), sb);
        htmlString = htmlString.replace("$gettingThereTrain", new String(sb));
    } else {
        htmlString = htmlString.replace("$gettingThereTrain", breaker);

    }
    if (null != destination.getGettingThereHitching()) {
        sb = getStringBuilderwithHeader(LonelyConstants.HEADER_TYPE_3, "getGettingThereHitching", "Hitching");

        sb = formatList(destination.getGettingThereHitching(), sb);
        htmlString = htmlString.replace("$gettingThereHitching", new String(sb));
    } else {
        htmlString = htmlString.replace("$gettingThereHitching", breaker);

    }
    if (null != destination.getInTransit()) {
        sb = getStringBuilderwithHeader(LonelyConstants.HEADER_TYPE_3, "getInTransit", "In Transit");

        sb = formatList(destination.getInTransit(), sb);
        htmlString = htmlString.replace("$inTransit", new String(sb));
    } else {
        htmlString = htmlString.replace("$inTransit", breaker);

    }
    if (null != destination.getMoney()) {
        sb = getStringBuilderwithHeader(LonelyConstants.HEADER_TYPE_3, "money", "Money");

        sb = formatList(destination.getMoney(), sb);
        htmlString = htmlString.replace("$money", new String(sb));
    } else {
        htmlString = htmlString.replace("$money", breaker);

    }
    if (null != destination.getVisasOther()) {
        sb = getStringBuilderwithHeader(LonelyConstants.HEADER_TYPE_3, "visasOther", "Visa");

        sb = formatList(destination.getVisasOther(), sb);
        htmlString = htmlString.replace("$visasOther", new String(sb));
    } else {
        htmlString = htmlString.replace("$visasOther", breaker);

    }
    if (null != destination.getPermits()) {
        sb = getStringBuilderwithHeader(LonelyConstants.HEADER_TYPE_3, "permits", "Permits");

        sb = formatList(destination.getPermits(), sb);
        htmlString = htmlString.replace("$permits", new String(sb));
    } else {
        htmlString = htmlString.replace("$permits", breaker);

    }

    if (null != destination.getVisasOverview()) {
        sb = getStringBuilderwithHeader(LonelyConstants.HEADER_TYPE_3, "VisasOverview", "Overview");

        sb = formatList(destination.getVisasOverview(), sb);
        htmlString = htmlString.replace("$visasOverview", new String(sb));
    } else {
        htmlString = htmlString.replace("$visasOverview", breaker);

    }

    if (null != destination.getWhenToGoClimate()) {
        sb = getStringBuilderwithHeader(LonelyConstants.HEADER_TYPE_3, "getWhenToGoClimate", "Climate");

        sb = formatList(destination.getWhenToGoClimate(), sb);
        htmlString = htmlString.replace("$whenToGoClimate", new String(sb));
    } else {
        htmlString = htmlString.replace("$whenToGoClimate", breaker);

    }
    if (null != destination.getWhenToGoOverview()) {
        sb = getStringBuilderwithHeader(LonelyConstants.HEADER_TYPE_3, "getWhenToGoOverview", "Overview");

        sb = formatList(destination.getWhenToGoOverview(), sb);
        htmlString = htmlString.replace("$whenToGoOverview", new String(sb));
    } else {
        htmlString = htmlString.replace("$whenToGoOverview", breaker);

    }
    if (null != destination.getWhileYouAreThere()) {
        sb = getStringBuilderwithHeader(LonelyConstants.HEADER_TYPE_3, "getWhileYouAreThere",
                "While You Are There");

        sb = formatList(destination.getWhileYouAreThere(), sb);
        htmlString = htmlString.replace("$whileYouAreThere", new String(sb));
    } else {
        htmlString = htmlString.replace("$whileYouAreThere", breaker);

    }
    if (null != destination.getWorkBusiness()) {
        sb = getStringBuilderwithHeader(LonelyConstants.HEADER_TYPE_3, "getWorkBusiness", "Business");

        sb = formatList(destination.getWorkBusiness(), sb);
        htmlString = htmlString.replace("$workBusiness", new String(sb));
    } else {
        htmlString = htmlString.replace("$workBusiness", breaker);

    }
    if (null != destination.getWorkOverview()) {
        sb = getStringBuilderwithHeader(LonelyConstants.HEADER_TYPE_3, "getWorkOverview", "Overview");

        sb = formatList(destination.getWorkOverview(), sb);
        htmlString = htmlString.replace("$workOverview", new String(sb));
    } else {
        htmlString = htmlString.replace("$workOverview", breaker);

    }
    if (null != destination.getGettingAroundHitching()) {
        sb = getStringBuilderwithHeader(LonelyConstants.HEADER_TYPE_3, "getGettingAroundHitching", "Hitching");

        sb = formatList(destination.getGettingAroundHitching(), sb);
        htmlString = htmlString.replace("$gettingAroundHitching", new String(sb));
    } else {
        htmlString = htmlString.replace("$gettingAroundHitching", breaker);

    }

    String fileName = GeoUtils.replaceSpaces(destination.getTitle()) + ".html";
    //        logger.info(" fileName of html file to be created  :  " + fileName);
    File newHtmlFile = new File(targetLocation + fileName);
    FileUtils.writeStringToFile(newHtmlFile, htmlString, "UTF-8");
}

From source file:com.sarm.Travelogue.common.PostMarshalUtilities.java

/**
 * This method parses a destination and creates an HTML file for that
 * destination. Steps involved in creating an HTML file for a destination
 *
 * 1 - Initialize the HTML Template - This defaultTemplate is a generic
 * structure of the required html file. It has place holders for the
 * different portions of texts. 2 - Create a navigation string with links
 * referencing to parents and all children under the destination 3 - Fill
 * the place holders with he appropriate texts and heading tags. 4 - Create
 * an HTML file using the destination title and converting spaces into
 * underscores and make the name of the file as in lowercase.
 *
 * @param destination/*w ww .  ja  v a2  s  .  co m*/
 * @param node
 * @param targetLocation
 * @throws IOException
 */
public static void createHtmlFromTemplate(Destination destination, Node node, String targetLocation)
        throws IOException, NullPointerException {
    StringBuilder breaker = new StringBuilder(LonelyConstants.BREAKER);
    File htmlTemplateFile = null;
    String htmlString;
    try {

        Reader reader = null;
        InputStream is = PostMarshalUtilities.class.getResourceAsStream("/" + LonelyConstants.defaultTemplate);
        if (null != is) {
            reader = new InputStreamReader(is);
        }
        BufferedReader bufRead = new BufferedReader(reader);
        StringBuilder htmlFileString = new StringBuilder();
        StringBuilder htmlFilefrString = new StringBuilder();
        int nextchar;
        while ((nextchar = bufRead.read()) != -1) {
            htmlFileString.append((char) nextchar);
        }

        htmlString = new String(htmlFileString);
        //            logger.debug("found template on Path on location" + LonelyConstants.defaultTemplate);

    } catch (FileNotFoundException ex) {
        logger.debug("Could not find template on Path, Getting Static HTML template"
                + htmlTemplateFile.getAbsolutePath());
        htmlString = LonelyConstants.destinationTemplateHtml;
    }

    String navigation = createNavigation(destination, node);
    htmlString = htmlString.replace("$navigation", navigation);

    String title = destination.getTitle();
    htmlString = htmlString.replace("$title", title);
    htmlString = htmlString.replace("$destinationName", destination.getTitle());

    String overview = (null != destination.getIntroduction() ? destination.getIntroduction()
            : new String(breaker));
    htmlString = htmlString.replace("$introduction", overview);

    StringBuilder sb = new StringBuilder();
    if (null != destination.getHistoryOverview()) {
        sb = getStringBuilderwithHeader(LonelyConstants.HEADER_TYPE_3, "historyOverview", "Overview");

        sb = sb.append(destination.getHistoryOverview());
        htmlString = htmlString.replace("$historyOverview", new String(sb));

    } else {
        htmlString = htmlString.replace("$historyOverview", breaker);

    }
    if (null != destination.getHistories() && destination.getHistories().size() != 0) {

        sb = getStringBuilderwithHeader(LonelyConstants.HEADER_TYPE_3, "history", " Background History");
        sb = formatList(destination.getHistories(), sb);
        htmlString = htmlString.replace("$histories", new String(sb));

    } else {

        htmlString = htmlString.replace("$histories", breaker);
    }

    if (null != destination.getBeforeYouGo()) {
        sb = getStringBuilderwithHeader(LonelyConstants.HEADER_TYPE_3, "beforeYouGo", "Before You Go");
        sb = formatList(destination.getBeforeYouGo(), sb);
        htmlString = htmlString.replace("$beforeYouGo", new String(sb));
    } else {
        htmlString = htmlString.replace("$beforeYouGo", breaker);
    }

    if (null != destination.getDangersAndAnnoyances()) {
        sb = getStringBuilderwithHeader(LonelyConstants.HEADER_TYPE_3, "dangersAndAnnoyances",
                "Dangers And Annoyances");
        sb = formatList(destination.getDangersAndAnnoyances(), sb);
        htmlString = htmlString.replace("$dangersAndAnnoyances", new String(sb));
    } else {
        htmlString = htmlString.replace("$dangersAndAnnoyances", breaker);

    }

    if (null != destination.getWhileYouAreThere()) {
        sb = getStringBuilderwithHeader(LonelyConstants.HEADER_TYPE_3, "whileyouarethere",
                "While You Are There");

        sb = formatList(destination.getWhileYouAreThere(), sb);
        htmlString = htmlString.replace("$whileYourArethere", new String(sb));
    } else {
        htmlString = htmlString.replace("$whileYourArethere", breaker);

    }

    if (null != destination.getCosts()) {
        sb = getStringBuilderwithHeader(LonelyConstants.HEADER_TYPE_3, "costs", "Costs");

        sb = formatList(destination.getCosts(), sb);
        htmlString = htmlString.replace("$costs", new String(sb));
    } else {
        htmlString = htmlString.replace("$costs", breaker);

    }
    if (null != destination.getGettingAroundAir()) {
        sb = getStringBuilderwithHeader(LonelyConstants.HEADER_TYPE_3, "gettingAroundAir", "Air");
        sb = formatList(destination.getGettingAroundAir(), sb);
        htmlString = htmlString.replace("$gettingAroundAir", new String(sb));
    } else {
        htmlString = htmlString.replace("$gettingAroundAir", breaker);

    }

    if (null != destination.getGettingAroundBicycle()) {
        sb = getStringBuilderwithHeader(LonelyConstants.HEADER_TYPE_3, "gettingAroundBicycle", "Bicycle");

        sb = formatList(destination.getGettingAroundBicycle(), sb);
        htmlString = htmlString.replace("$gettingAroundBicycle", new String(sb));
    } else {
        htmlString = htmlString.replace("$gettingAroundBicycle", breaker);

    }

    if (null != destination.getGettingAroundBoat()) {
        sb = getStringBuilderwithHeader(LonelyConstants.HEADER_TYPE_3, "gettingAroundBoat", "Boat");

        sb = formatList(destination.getGettingAroundBoat(), sb);
        htmlString = htmlString.replace("$gettingAroundBoat", new String(sb));
    } else {
        htmlString = htmlString.replace("$gettingAroundBoat", breaker);

    }

    if (null != destination.getGettingAroundBusnTram()) {
        sb = getStringBuilderwithHeader(LonelyConstants.HEADER_TYPE_3, "gettingAroundBusnTram", "Bus And Tram");

        sb = formatList(destination.getGettingAroundBusnTram(), sb);
        htmlString = htmlString.replace("$gettingAroundBusnTram", new String(sb));
    } else {
        htmlString = htmlString.replace("$gettingAroundBusnTram", breaker);

    }

    if (null != destination.getGettingAroundCarAndMotorCycle()) {
        sb = getStringBuilderwithHeader(LonelyConstants.HEADER_TYPE_3, "gettingAroundCarAndMotorCycle",
                "Car And MotorCycle");

        sb = formatList(destination.getGettingAroundCarAndMotorCycle(), sb);
        htmlString = htmlString.replace("$gettingAroundCarAndMotorCycle", new String(sb));
    } else {
        htmlString = htmlString.replace("$gettingAroundCarAndMotorCycle", breaker);

    }

    if (null != destination.getGettingAroundHitching()) {
        sb = getStringBuilderwithHeader(LonelyConstants.HEADER_TYPE_3, "gettingAroundHitching", "Hitching");

        sb = formatList(destination.getGettingAroundHitching(), sb);
        htmlString = htmlString.replace("$gettingAroundHitching", new String(sb));
    } else {
        htmlString = htmlString.replace("$gettingAroundHitching", breaker);

    }
    if (null != destination.getGettingAroundLocal()) {
        sb = getStringBuilderwithHeader(LonelyConstants.HEADER_TYPE_3, "getGettingAroundLocal",
                "Local Transport");

        sb = formatList(destination.getGettingAroundLocal(), sb);
        htmlString = htmlString.replace("$gettingAroundLocal", new String(sb));
    } else {
        htmlString = htmlString.replace("$gettingAroundLocal", breaker);

    }
    if (null != destination.getGettingAroundTrain()) {
        sb = getStringBuilderwithHeader(LonelyConstants.HEADER_TYPE_3, "getGettingAroundTrain", "Train");

        sb = formatList(destination.getGettingAroundTrain(), sb);
        htmlString = htmlString.replace("$gettingAroundTrain", new String(sb));
    } else {
        htmlString = htmlString.replace("$gettingAroundTrain", breaker);

    }

    if (null != destination.getGettingAroundOverview()) {
        sb = getStringBuilderwithHeader(LonelyConstants.HEADER_TYPE_3, "getGettingAroundOverview", "Overview");

        sb = sb.append(destination.getGettingAroundOverview());
        htmlString = htmlString.replace("$gettingAroundOverview", new String(sb));
    } else {
        htmlString = htmlString.replace("$gettingAroundOverview", breaker);

    }

    if (null != destination.getGettingThereAndAwayOverview()) {
        sb = getStringBuilderwithHeader(LonelyConstants.HEADER_TYPE_3, "getGettingThereAndAwayOverview",
                "Overview");

        sb = sb.append(destination.getGettingThereAndAwayOverview());
        htmlString = htmlString.replace("$gettingThereAndAwayOverview", new String(sb));
    } else {
        htmlString = htmlString.replace("$gettingThereAndAwayOverview", breaker);
    }

    if (null != destination.getGettingThereAir()) {
        sb = getStringBuilderwithHeader(LonelyConstants.HEADER_TYPE_3, "getGettingThereAir", "Air");

        sb = formatList(destination.getGettingThereAir(), sb);
        htmlString = htmlString.replace("$gettingThereAir", new String(sb));
    } else {
        htmlString = htmlString.replace("$gettingThereAir", breaker);

    }

    if (null != destination.getGettingThereBusnTram()) {
        sb = getStringBuilderwithHeader(LonelyConstants.HEADER_TYPE_3, "getGettingThereBusnTram",
                "Bus and Tram");

        sb = formatList(destination.getGettingThereBusnTram(), sb);
        htmlString = htmlString.replace("$gettingThereBusnTram", new String(sb));
    } else {
        htmlString = htmlString.replace("$gettingThereBusnTram", breaker);

    }

    if (null != destination.getGettingThereBicycle()) {
        sb = getStringBuilderwithHeader(LonelyConstants.HEADER_TYPE_3, "getGettingThereBicycle", "Bicycle");

        sb = formatList(destination.getGettingThereBicycle(), sb);
        htmlString = htmlString.replace("$gettingThereBicycle", new String(sb));
    } else {
        htmlString = htmlString.replace("$gettingThereBicycle", breaker);

    }
    if (null != destination.getGettingThereBoat()) {
        sb = getStringBuilderwithHeader(LonelyConstants.HEADER_TYPE_3, "getGettingThereBoat", "Boat");

        sb = formatList(destination.getGettingThereBoat(), sb);
        htmlString = htmlString.replace("$gettingThereBoat", new String(sb));
    } else {
        htmlString = htmlString.replace("$gettingThereBoat", breaker);

    }
    if (null != destination.getGettingThereCarAndMotorCycle()) {
        sb = getStringBuilderwithHeader(LonelyConstants.HEADER_TYPE_3, "getGettingThereCarAndMotorCycle",
                "Car and MotorCycle");

        sb = formatList(destination.getGettingThereCarAndMotorCycle(), sb);
        htmlString = htmlString.replace("$gettingThereCarAndMotorCycle", new String(sb));
    } else {
        htmlString = htmlString.replace("$gettingThereCarAndMotorCycle", breaker);

    }
    if (null != destination.getGettingThereLocal()) {
        sb = getStringBuilderwithHeader(LonelyConstants.HEADER_TYPE_3, "getGettingThereLocal",
                "Local Transport");

        sb = formatList(destination.getGettingThereLocal(), sb);
        htmlString = htmlString.replace("$gettingThereLocal", new String(sb));
    } else {
        htmlString = htmlString.replace("$gettingThereLocal", breaker);

    }

    if (null != destination.getGettingThereTrain()) {
        sb = getStringBuilderwithHeader(LonelyConstants.HEADER_TYPE_3, "getGettingThereTrain", "Train");

        sb = formatList(destination.getGettingThereTrain(), sb);
        htmlString = htmlString.replace("$gettingThereTrain", new String(sb));
    } else {
        htmlString = htmlString.replace("$gettingThereTrain", breaker);

    }
    if (null != destination.getGettingThereHitching()) {
        sb = getStringBuilderwithHeader(LonelyConstants.HEADER_TYPE_3, "getGettingThereHitching", "Hitching");

        sb = formatList(destination.getGettingThereHitching(), sb);
        htmlString = htmlString.replace("$gettingThereHitching", new String(sb));
    } else {
        htmlString = htmlString.replace("$gettingThereHitching", breaker);

    }
    if (null != destination.getInTransit()) {
        sb = getStringBuilderwithHeader(LonelyConstants.HEADER_TYPE_3, "getInTransit", "In Transit");

        sb = formatList(destination.getInTransit(), sb);
        htmlString = htmlString.replace("$inTransit", new String(sb));
    } else {
        htmlString = htmlString.replace("$inTransit", breaker);

    }
    if (null != destination.getMoney()) {
        sb = getStringBuilderwithHeader(LonelyConstants.HEADER_TYPE_3, "money", "Money");

        sb = formatList(destination.getMoney(), sb);
        htmlString = htmlString.replace("$money", new String(sb));
    } else {
        htmlString = htmlString.replace("$money", breaker);

    }
    if (null != destination.getVisasOther()) {
        sb = getStringBuilderwithHeader(LonelyConstants.HEADER_TYPE_3, "visasOther", "Visa");

        sb = formatList(destination.getVisasOther(), sb);
        htmlString = htmlString.replace("$visasOther", new String(sb));
    } else {
        htmlString = htmlString.replace("$visasOther", breaker);

    }
    if (null != destination.getPermits()) {
        sb = getStringBuilderwithHeader(LonelyConstants.HEADER_TYPE_3, "permits", "Permits");

        sb = formatList(destination.getPermits(), sb);
        htmlString = htmlString.replace("$permits", new String(sb));
    } else {
        htmlString = htmlString.replace("$permits", breaker);

    }

    if (null != destination.getVisasOverview()) {
        sb = getStringBuilderwithHeader(LonelyConstants.HEADER_TYPE_3, "VisasOverview", "Overview");

        sb = formatList(destination.getVisasOverview(), sb);
        htmlString = htmlString.replace("$visasOverview", new String(sb));
    } else {
        htmlString = htmlString.replace("$visasOverview", breaker);

    }

    if (null != destination.getWhenToGoClimate()) {
        sb = getStringBuilderwithHeader(LonelyConstants.HEADER_TYPE_3, "getWhenToGoClimate", "Climate");

        sb = formatList(destination.getWhenToGoClimate(), sb);
        htmlString = htmlString.replace("$whenToGoClimate", new String(sb));
    } else {
        htmlString = htmlString.replace("$whenToGoClimate", breaker);

    }
    if (null != destination.getWhenToGoOverview()) {
        sb = getStringBuilderwithHeader(LonelyConstants.HEADER_TYPE_3, "getWhenToGoOverview", "Overview");

        sb = formatList(destination.getWhenToGoOverview(), sb);
        htmlString = htmlString.replace("$whenToGoOverview", new String(sb));
    } else {
        htmlString = htmlString.replace("$whenToGoOverview", breaker);

    }
    if (null != destination.getWhileYouAreThere()) {
        sb = getStringBuilderwithHeader(LonelyConstants.HEADER_TYPE_3, "getWhileYouAreThere",
                "While You Are There");

        sb = formatList(destination.getWhileYouAreThere(), sb);
        htmlString = htmlString.replace("$whileYouAreThere", new String(sb));
    } else {
        htmlString = htmlString.replace("$whileYouAreThere", breaker);

    }
    if (null != destination.getWorkBusiness()) {
        sb = getStringBuilderwithHeader(LonelyConstants.HEADER_TYPE_3, "getWorkBusiness", "Business");

        sb = formatList(destination.getWorkBusiness(), sb);
        htmlString = htmlString.replace("$workBusiness", new String(sb));
    } else {
        htmlString = htmlString.replace("$workBusiness", breaker);

    }
    if (null != destination.getWorkOverview()) {
        sb = getStringBuilderwithHeader(LonelyConstants.HEADER_TYPE_3, "getWorkOverview", "Overview");

        sb = formatList(destination.getWorkOverview(), sb);
        htmlString = htmlString.replace("$workOverview", new String(sb));
    } else {
        htmlString = htmlString.replace("$workOverview", breaker);

    }
    if (null != destination.getGettingAroundHitching()) {
        sb = getStringBuilderwithHeader(LonelyConstants.HEADER_TYPE_3, "getGettingAroundHitching", "Hitching");

        sb = formatList(destination.getGettingAroundHitching(), sb);
        htmlString = htmlString.replace("$gettingAroundHitching", new String(sb));
    } else {
        htmlString = htmlString.replace("$gettingAroundHitching", breaker);

    }

    String fileName = PostMarshalUtilities.replaceSpaces(destination.getTitle()) + ".html";
    //        logger.info(" fileName of html file to be created  :  " + fileName);
    File newHtmlFile = new File(targetLocation + fileName);
    FileUtils.writeStringToFile(newHtmlFile, htmlString, "UTF-8");
}

From source file:org.apache.axis.transport.mail.MailServer.java

/**
 * Accept requests from a given TCP port and send them through the
 * Axis engine for processing./* w  w  w .j  a  v a2s  . com*/
 */
public void run() {
    log.info(Messages.getMessage("start00", "MailServer", host + ":" + port));

    // Accept and process requests from the socket
    while (!stopped) {
        try {
            pop3.connect(host, port);
            pop3.login(userid, password);

            POP3MessageInfo[] messages = pop3.listMessages();
            if (messages != null && messages.length > 0) {
                for (int i = 0; i < messages.length; i++) {
                    Reader reader = pop3.retrieveMessage(messages[i].number);
                    if (reader == null) {
                        continue;
                    }

                    StringBuffer buffer = new StringBuffer();
                    BufferedReader bufferedReader = new BufferedReader(reader);
                    int ch;
                    while ((ch = bufferedReader.read()) != -1) {
                        buffer.append((char) ch);
                    }
                    bufferedReader.close();
                    ByteArrayInputStream bais = new ByteArrayInputStream(buffer.toString().getBytes());
                    Properties prop = new Properties();
                    Session session = Session.getDefaultInstance(prop, null);

                    MimeMessage mimeMsg = new MimeMessage(session, bais);
                    pop3.deleteMessage(messages[i].number);
                    if (mimeMsg != null) {
                        MailWorker worker = new MailWorker(this, mimeMsg);
                        if (doThreads) {
                            Thread thread = new Thread(worker);
                            thread.setDaemon(true);
                            thread.start();
                        } else {
                            worker.run();
                        }
                    }
                }
            }
        } catch (java.io.InterruptedIOException iie) {
        } catch (Exception e) {
            log.debug(Messages.getMessage("exception00"), e);
            break;
        } finally {
            try {
                pop3.logout();
                pop3.disconnect();
                Thread.sleep(3000);
            } catch (Exception e) {
                log.error(Messages.getMessage("exception00"), e);
            }
        }
    }
    log.info(Messages.getMessage("quit00", "MailServer"));
}

From source file:org.opendaylight.usc.test.manager.UscServiceTest.java

public String sendPost(String baseURL, String requestBody) {
    // attaching authentication information
    String authString = "admin:admin";
    byte[] authEncBytes = Base64.encodeBase64(authString.getBytes());
    String authStringEnc = new String(authEncBytes);
    URL url;//from  w ww  .j  av a  2s.c  o m
    StringBuilder sb = new StringBuilder();

    try {
        url = new URL(baseURL);
    } catch (MalformedURLException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        return e.getMessage();
    }
    // creating the URLConnection
    HttpURLConnection connection;
    try {
        connection = (HttpURLConnection) url.openConnection();
        connection.setRequestMethod("POST");
        connection.setRequestProperty("Authorization", "Basic " + authStringEnc);
        connection.setRequestProperty("Content-Type", "application/json");
        connection.setRequestProperty("Content-Length", requestBody.length() + "");
        connection.setRequestProperty("Accept", "application/json");
        // now add the request body
        connection.setDoOutput(true);
        OutputStreamWriter wr = new OutputStreamWriter(connection.getOutputStream());
        wr.write(requestBody);
        wr.flush();
        connection.connect();

        // getting the result, first check response code
        Integer httpResponseCode = connection.getResponseCode();
        if (httpResponseCode > 299)
            System.out.println("ResponseCode = " + httpResponseCode);
        // get the result string from the inputstream.
        InputStream is = connection.getInputStream();
        BufferedReader rd = new BufferedReader(new InputStreamReader(is, Charset.forName("UTF-8")));

        int cp;
        while ((cp = rd.read()) != -1) {
            sb.append((char) cp);
        }
        System.out.println("Content = " + sb.toString());
        is.close();
        connection.disconnect();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        // e.printStackTrace();
        return e.getMessage();
    }
    return sb.toString();
}

From source file:gov.nasa.arc.geocam.memo.service.SiteAuthCookieImplementation.java

@Override
public String get(String relativePath, Map<String, String> params)
        throws AuthenticationFailedException, IOException, ClientProtocolException {
    ensureAuthenticated();//from ww w.ja  v a 2 s  . c om
    httpClient = new DefaultHttpClient();

    HttpGet get = new HttpGet(this.serverRootUrl + "/" + appPath + "/" + relativePath);

    // TODO: add param parsing and query string construction as necessary

    httpClient.getCookieStore().addCookie(sessionIdCookie);
    //get.setHeader("Cookie", sessionIdCookie.toString());

    HttpResponse r = httpClient.execute(get);
    // TODO: check for redirect to login and call login if is the case

    InputStream content = r.getEntity().getContent();

    BufferedReader br = new BufferedReader(new InputStreamReader(content));
    StringBuilder sb = new StringBuilder();

    int c = 0;
    while ((c = br.read()) != -1) {
        sb.append((char) c);
    }

    br.close();
    return sb.toString();
}

From source file:com.adp.marketplace.product.userinfo.core.UserInfoHelper.java

/**
 * Returns a response after processing {@link CloseableHttpResponse} and throws exception
 * /*from   w  w  w. j  ava  2 s  .c o  m*/
 * @param response           
 * @return StringBuilder
 * @throws IOException
 * @throws APIException
 */
private StringBuilder processAPIResponse(CloseableHttpResponse response) throws IOException, APIException {

    StringBuilder stringBuilder = null;
    int value = -1;

    try {

        if (response != null) {

            stringBuilder = new StringBuilder();

            InputStreamReader inputStreamReader = new InputStreamReader(response.getEntity().getContent());
            BufferedReader bufferedReader = new BufferedReader(inputStreamReader);

            // reads to the end of the stream 
            while ((value = bufferedReader.read()) != -1) {
                // add character
                stringBuilder.append((char) value);
            }
        }
    } catch (IOException e) {
        throw new APIException("Error: Unable to get API response.");
    } finally {
        if (response != null) {
            response.close();
        }
    }

    return stringBuilder;
}

From source file:mamo.vanillaVotifier.LanguagePack.java

public String getString(String key, Entry<String, Object>... substitutions) {
    String string = null;/*from w  w w .ja  v a 2  s . c  o m*/
    if (bundle.containsKey(key)) {
        string = bundle.getString(key).replaceAll(
                "\\u000D\\u000A|[\\u000A\\u000B\\u000C\\u000D\\u0085\\u2028\\u2029]",
                System.getProperty("line.separator"));
    } else if (bundle.containsKey(key + "-location")) {
        String resource = getString(key + "-location");
        if (resource == null) {
            return null;
        }
        if (!resource.startsWith("/")) {
            resource = "/mamo/vanillaVotifier/lang/" + resource;
        }
        BufferedReader in = new BufferedReader(
                new InputStreamReader(LanguagePack.class.getResourceAsStream(resource)));
        StringBuilder stringBuilder = new StringBuilder();
        int i;
        try {
            while ((i = in.read()) != -1) {
                stringBuilder.append((char) i);
            }
            in.close();
        } catch (IOException e) {
            // Can't happen.
        }
        string = stringBuilder.toString().replaceAll(
                "\\u000D\\u000A|[\\u000A\\u000B\\u000C\\u000D\\u0085\\u2028\\u2029]",
                System.getProperty("line.separator"));
    }
    if (substitutions == null || string == null) {
        return string;
    } else {
        HashMap<String, Object> substitutionsMap = new HashMap<String, Object>();
        for (Entry<String, Object> substitution : substitutions) {
            if (substitution.getValue() != null) {
                if (!(substitution.getValue() instanceof Throwable)) {
                    substitutionsMap.put(substitution.getKey(), substitution.getValue());
                } else {
                    substitutionsMap.put(substitution.getKey(),
                            ((Throwable) substitution.getValue()).toString());
                }
            } else {
                substitutionsMap.put(substitution.getKey(), "");
            }
        }
        return new StrSubstitutor(substitutionsMap).replace(string);
    }
}

From source file:net.itransformers.topologyviewer.fulfilmentfactory.impl.TelnetCLIInterface.java

public String readUntil(String regexp) throws IOException {
    BufferedReader reader = new BufferedReader(new InputStreamReader(in));
    logger.info("looking for : " + regexp);
    int chInt;//  ww w . ja  v a 2s.  c  o  m
    StringBuffer sb = new StringBuffer();
    while ((chInt = reader.read()) != -1) {
        char ch = (char) chInt;
        if (ch == '\n') {
            logger.info(sb.toString());
            sb.setLength(0);
            continue;
        }
        sb.append(ch);
        String st = sb.toString();
        if (st.matches(regexp)) {
            logger.info("### Found match: " + sb);
            return st;
        }
        if (!reader.ready()) {
            logger.info("Buffer is not ready. Read characters until now: " + sb.toString());
        }
    }
    return null;
}

From source file:dk.netarkivet.common.utils.FileUtils.java

/**
 * Load file content into text string.//w w  w  . j  a  v a2  s  .  c o m
 *
 * @param file The file to load
 * @return file content loaded into text string
 * @throws java.io.IOException If any IO trouble occurs while reading
 *  the file, or the file cannot be found.
 */
public static String readFile(File file) throws IOException {
    ArgumentNotValid.checkNotNull(file, "File file");
    StringBuffer sb = new StringBuffer();

    BufferedReader br = new BufferedReader(new FileReader(file));

    try {
        int i;

        while ((i = br.read()) != -1) {
            sb.append((char) i);
        }
    } finally {
        br.close();
    }

    return sb.toString();
}