Example usage for java.io PrintWriter println

List of usage examples for java.io PrintWriter println

Introduction

In this page you can find the example usage for java.io PrintWriter println.

Prototype

public void println(Object x) 

Source Link

Document

Prints an Object and then terminates the line.

Usage

From source file:com.momab.dstool.DSTool.java

static void printErrorMessage(String message, OutputStream out) {
    PrintWriter writer = new PrintWriter(out);
    writer.println(String.format("Error: %s", message));
    writer.flush();/*from   ww  w  .  ja v a2s .co  m*/
}

From source file:edu.isi.karma.util.FileUtil.java

/**
 * Saves a string to a file.//from  w w w . j  a va 2s  . c  om
 *
 * @param str
 * @param fileName
 * @throws FileNotFoundException
 * @throws UnsupportedEncodingException
 */
public static void writeStringToFile(String str, String fileName)
        throws UnsupportedEncodingException, FileNotFoundException {
    OutputStreamWriter fw = new OutputStreamWriter(new FileOutputStream(fileName), "UTF-8");
    BufferedWriter bw = new BufferedWriter(fw);
    PrintWriter outWriter = new PrintWriter(bw);
    outWriter.println(str);
    outWriter.close();
}

From source file:com.momab.dstool.DSTool.java

static void printHelp(Options options, OutputStream out) {
    PrintWriter writer = new PrintWriter(out);
    writer.println(String.format("%s version %s, Copyright Jonas Andreasson under the MIT license.", TOOLNAME,
            getVersionString()));//from   w  w  w. j  av  a 2 s . co  m
    writer.println();
    writer.flush();
    HelpFormatter formatter = new HelpFormatter();
    formatter.printHelp(CMDLINE_SYNTAX, options, true);
    writer.flush();
}

From source file:com.unresyst.DealRecommender.java

private static String runCommand(String... commands) throws IOException, InterruptedException {
    // generate a script file containg the command to run
    final File scriptFile = new File("/tmp/runcommand.sh");
    PrintWriter w = new PrintWriter(scriptFile);
    w.println("#!/bin/sh");
    for (String command : commands) {
        w.println(command);//from ww w . j ava  2  s.com
    }
    w.close();

    // make the script executable
    //System.out.println("absolute path: " + scriptFile.getAbsolutePath());
    Process p = Runtime.getRuntime().exec("chmod +x " + scriptFile.getAbsolutePath());
    p.waitFor();

    // execute the script
    p = Runtime.getRuntime().exec(scriptFile.getAbsolutePath());
    p.waitFor();
    BufferedReader stdin = new BufferedReader(new InputStreamReader(p.getInputStream()));
    BufferedReader stderr = new BufferedReader(new InputStreamReader(p.getErrorStream()));
    String toReturn = "";
    String line = "";
    while ((line = stdin.readLine()) != null) {
        toReturn += line + "\n";
    }
    while ((line = stderr.readLine()) != null) {
        toReturn += "err: " + line + "\n";
    }

    scriptFile.delete();
    return toReturn;
}

From source file:de.tudarmstadt.ukp.dkpro.core.api.discourse.DiscourseDumpWriter.java

/**
 * Debugs discourse relation to String//from   w  ww.jav a 2 s . co m
 *
 * @param relation relation
 */
public static String debugRelation(DiscourseRelation relation) {

    //        StringWriter out = new StringWriter();
    StringWriter stringWriter = new StringWriter();
    PrintWriter out = new PrintWriter(stringWriter);

    out.println("---- discourse relation " + relation.getRelationId());
    out.println(" relation class: " + relation.getClass().getSimpleName());
    out.println(" coveredText: " + relation.getCoveredText());
    for (DiscourseArgument argument : Arrays.asList(relation.getArg1(), relation.getArg2())) {
        out.println("   -- arg" + argument.getArgumentNumber() + ": ");
        out.println("      argumentType: "
                + (argument.getArgumentType() != null ? argument.getArgumentType() : "-"));
        out.println("      coveredText: " + argument.getCoveredText());

    }

    if (relation instanceof ExplicitDiscourseRelation) {
        ExplicitDiscourseRelation explicitRelation = (ExplicitDiscourseRelation) relation;

        for (DiscourseConnective connective : Arrays.asList(explicitRelation.getDiscourseConnective1(),
                explicitRelation.getDiscourseConnective2())) {
            if (connective != null) {
                out.println("   -- connectiveType: " + connective.getConnectiveType());
                out.println("      coveredText: " + connective.getCoveredText());
            }
        }
    }

    for (DiscourseAttribution attribution : JCasUtil.selectCovered(DiscourseAttribution.class, relation)) {
        out.println("   -- attribution " + attribution.getAttributeId());
        out.println("      coveredText: " + attribution.getCoveredText());
    }

    out.println("---- end of relation " + relation.getRelationId());
    out.flush();

    return stringWriter.toString();
}

From source file:bammerbom.ultimatecore.bukkit.resources.classes.ErrorLogger.java

public static void log(Throwable t, String s) {
    String time = new SimpleDateFormat("yyyy-MM-dd_HH-mm-ss-SSS").format(Calendar.getInstance().getTime());
    File dir = new File(Bukkit.getPluginManager().getPlugin("UltimateCore").getDataFolder() + "/Errors");
    if (!dir.exists()) {
        dir.mkdir();// w  ww . ja v  a2 s .  c o  m
    }
    File file = new File(Bukkit.getPluginManager().getPlugin("UltimateCore").getDataFolder() + "/Errors",
            time + ".txt");
    if (!file.exists()) {
        try {
            file.createNewFile();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    FileWriter outFile;
    try {
        outFile = new FileWriter(file);
    } catch (IOException e) {
        e.printStackTrace();
        return;
    }
    PrintWriter out = new PrintWriter(outFile);
    out.println("=======================================");
    out.println("UltimateCore has run into an error ");
    out.println("Please report your error on dev.bukkit.org/bukkit-plugins/ultimate_core/create-ticket");
    out.println("Bukkit version: " + Bukkit.getServer().getVersion());
    out.println("UltimateCore version: " + r.getUC().getDescription().getVersion());
    out.println("Plugins loaded (" + Bukkit.getPluginManager().getPlugins().length + "): "
            + Arrays.asList(Bukkit.getPluginManager().getPlugins()));
    out.println("Java version: " + System.getProperty("java.version"));
    out.println("OS info: " + System.getProperty("os.arch") + ", " + System.getProperty("os.name") + ", "
            + System.getProperty("os.version"));
    out.println("Time: " + time);
    out.println("Error message: " + t.getMessage());
    out.println("UltimateCore message: " + s);
    out.println("=======================================");
    out.println("Stacktrace: \n" + ExceptionUtils.getStackTrace(t));
    out.println("=======================================");
    out.close();
    try {
        outFile.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
    //
    Bukkit.getConsoleSender().sendMessage(" ");
    r.log(ChatColor.DARK_RED + "=========================================================");
    r.log(ChatColor.RED + "UltimateCore has run into an error ");
    r.log(ChatColor.RED + "Please report your error on ");
    r.log(ChatColor.YELLOW + "http://dev.bukkit.org/bukkit-plugins/ultimate_core/create-ticket");
    r.log(ChatColor.RED + "Include the file: ");
    r.log(ChatColor.YELLOW + "plugins/UltimateCore/Errors/" + time + ".txt ");
    /*r.log(ChatColor.RED + "Bukkit version: " + Bukkit.getServer().getVersion());
     r.log(ChatColor.RED + "UltimateCore version: " + Bukkit.getPluginManager().getPlugin("UltimateCore").getDescription().getVersion());
     r.log(ChatColor.RED + "Plugins loaded (" + Bukkit.getPluginManager().getPlugins().length + "): " + Arrays.asList(Bukkit.getPluginManager().getPlugins()));
     r.log(ChatColor.RED + "Java version: " + System.getProperty("java.version"));
     r.log(ChatColor.RED + "OS info: " + System.getProperty("os.arch") + ", " + System.getProperty("os.name") + ", " + System.getProperty("os.version"));
     r.log(ChatColor.RED + "Error message: " + t.getMessage());
     r.log(ChatColor.RED + "UltimateCore message: " + s);*/
    r.log(ChatColor.DARK_RED + "=========================================================");
    if (t instanceof Exception) {
        r.log(ChatColor.RED + "Stacktrace: ");
        t.printStackTrace();
        r.log(ChatColor.DARK_RED + "=========================================================");
    }
    Bukkit.getConsoleSender().sendMessage(" ");
}

From source file:NewFingerServer.java

private static void readPlan(String userName, PrintWriter pw) throws Exception {
    FileReader file = new FileReader(userName + ".plan");
    BufferedReader buff = new BufferedReader(file);
    boolean eof = false;
    pw.println("\nUser name: " + userName + "\n");
    while (!eof) {
        String line = buff.readLine();
        if (line == null)
            eof = true;//from   w  w  w .  jav a 2 s.co  m
        else
            pw.println(line);
    }
    buff.close();
}

From source file:org.elegosproject.romupdater.DownloadManager.java

public static boolean sendAnonymousData() {
    String link = "http://www.elegosproject.org/android/upload.php";
    String data;// ww w  . jav  a  2  s.co  m

    SharedData shared = SharedData.getInstance();
    String romName = shared.getRepositoryROMName();
    String romVersion = shared.getDownloadVersion();
    String romPhone = shared.getRepositoryModel();
    String romRepository = shared.getRepositoryUrl();

    if (romName.equals("") || romVersion.equals("") || romPhone.equals("") || romRepository.equals("")) {
        Log.e(TAG, "Internal error - missing system variables.");
        return false;
    }

    if (!checkHttpFile(link))
        return false;
    try {
        data = URLEncoder.encode("phone", "UTF-8") + "=" + URLEncoder.encode(romPhone, "UTF-8");
        data += "&" + URLEncoder.encode("rom_name", "UTF-8") + "=" + URLEncoder.encode(romName, "UTF-8");
        data += "&" + URLEncoder.encode("rom_version", "UTF-8") + "=" + URLEncoder.encode(romVersion, "UTF-8");
        data += "&" + URLEncoder.encode("rom_repository", "UTF-8") + "="
                + URLEncoder.encode(romRepository, "UTF-8");

        HttpParams httpParameters = new BasicHttpParams();
        HttpConnectionParams.setConnectionTimeout(httpParameters, 3000);

        URL url = new URL(link);
        url.openConnection();
        HttpURLConnection conn = (HttpURLConnection) url.openConnection();
        conn.setRequestMethod("POST");
        conn.setRequestProperty("User-Agent", "ROMUpdater");
        conn.setDoOutput(true);
        PrintWriter out = new PrintWriter(conn.getOutputStream());
        out.println(data);
        out.close();

        int status = Integer.parseInt(conn.getHeaderField("ROMUpdater-status"));
        if (status == 1)
            return true;

        Log.e(TAG, "It was impossible to send data to the stastistics server ("
                + conn.getHeaderField("ROMUpdater-error") + ").");
        return false;

    } catch (Exception e) {
        Log.e(TAG, "It was impossible to send data to the stastistics server.");
        Log.e(TAG, "Error: " + e.toString());
        return false;
    }
}

From source file:org.apache.hadoop.util.ServletUtil.java

/**
 * Initial HTML header//from  w  w w .ja  va  2s.com
 */
public static PrintWriter initHTML(ServletResponse response, String title) throws IOException {
    response.setContentType("text/html");
    PrintWriter out = response.getWriter();
    out.println("<html>\n" + "<link rel='stylesheet' type='text/css' href='/static/hadoop.css'>\n" + "<title>"
            + title + "</title>\n" + "<body>\n" + "<h1>" + title + "</h1>\n");
    return out;
}

From source file:bammerbom.ultimatecore.spongeapi.resources.classes.ErrorLogger.java

public static void log(Throwable t, String s) {
    String time = new SimpleDateFormat("yyyy-MM-dd_HH-mm-ss-SSS").format(Calendar.getInstance().getTime());
    File dir = new File(r.getUC().getDataFolder() + "/Errors");
    if (!dir.exists()) {
        dir.mkdir();//from   ww  w . j a  v a 2s.c o m
    }
    File file = new File(r.getUC().getDataFolder() + "/Errors", time + ".txt");
    if (!file.exists()) {
        try {
            file.createNewFile();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    FileWriter outFile;
    try {
        outFile = new FileWriter(file);
    } catch (IOException e) {
        e.printStackTrace();
        return;
    }
    PrintWriter out = new PrintWriter(outFile);
    out.println("=======================================");
    out.println("UltimateCore has run into an error ");
    out.println("Please report your error on dev.bukkit.org/bukkit-plugins/ultimate_core/create-ticket");
    out.println("Spongeapi version: " + r.getGame().getMinecraftVersion() + " - "
            + r.getGame().getImplementationVersion());
    out.println("UltimateCore version: "
            + r.getGame().getPluginManager().getPlugin("UltimateCore").get().getVersion());
    out.println("Plugins loaded (" + r.getGame().getPluginManager().getPlugins().size() + "): "
            + Arrays.asList(r.getGame().getPluginManager().getPlugins()));
    out.println("Java version: " + System.getProperty("java.version"));
    out.println("OS info: " + System.getProperty("os.arch") + ", " + System.getProperty("os.name") + ", "
            + System.getProperty("os.version"));
    if (r.getGame().getServer().isPresent()) {
        out.println("Online mode: " + r.getGame().getServer().get().getOnlineMode());
    }
    out.println("Time: " + time);
    out.println("Error message: " + t.getMessage());
    out.println("UltimateCore message: " + s);
    out.println("=======================================");
    out.println("Stacktrace: \n" + ExceptionUtils.getStackTrace(t));
    out.println("=======================================");
    out.close();
    try {
        outFile.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
    //
    r.log(" ");
    r.log(TextColors.DARK_RED + "=========================================================");
    r.log(TextColors.RED + "UltimateCore has run into an error ");
    r.log(TextColors.RED + "Please report your error on ");
    r.log(TextColors.YELLOW + "http://dev.bukkit.org/bukkit-plugins/ultimate_core/create-ticket");
    r.log(TextColors.RED + "Include the file: ");
    r.log(TextColors.YELLOW + "plugins/UltimateCore/Errors/" + time + ".txt ");
    /*r.log(TextColors.RED + "Sponge version: " + Bukkit.getServer().getVersion());
     r.log(TextColors.RED + "UltimateCore version: " + Bukkit.getPluginManager().getPlugin("UltimateCore").getDescription().getVersion());
     r.log(TextColors.RED + "Plugins loaded (" + Bukkit.getPluginManager().getPlugins().length + "): " + Arrays.asList(Bukkit.getPluginManager().getPlugins()));
     r.log(TextColors.RED + "Java version: " + System.getProperty("java.version"));
     r.log(TextColors.RED + "OS info: " + System.getProperty("os.arch") + ", " + System.getProperty("os.name") + ", " + System.getProperty("os.version"));
     r.log(TextColors.RED + "Error message: " + t.getMessage());
     r.log(TextColors.RED + "UltimateCore message: " + s);*/
    r.log(TextColors.DARK_RED + "=========================================================");
    if (t instanceof Exception) {
        r.log(TextColors.RED + "Stacktrace: ");
        t.printStackTrace();
        r.log(TextColors.DARK_RED + "=========================================================");
    }
    r.log(" ");
}