Example usage for java.io PrintStream append

List of usage examples for java.io PrintStream append

Introduction

In this page you can find the example usage for java.io PrintStream append.

Prototype

public PrintStream append(char c) 

Source Link

Document

Appends the specified character to this output stream.

Usage

From source file:Main.java

public static void main(String[] args) {
    String s = "from java2s.com. ";

    PrintStream ps = new PrintStream(System.out);

    // append our strings
    ps.append(s);
    ps.append("This is an example.");

    // print the result
    ps.flush();/*from ww w .  ja  v  a2  s .  co m*/
    ps.close();

}

From source file:Main.java

public static void main(String[] args) {
    char c = 'A';

    PrintStream ps = new PrintStream(System.out);

    // append our characters
    ps.append(c);
    ps.append('y');
    ps.append('m');

    // print the result
    ps.flush();//from w w  w.ja v  a2  s  .  c o  m
    ps.close();

}

From source file:dataflow.examples.DockerClientExample.java

public static void main(String[] args) throws IOException, DockerException, InterruptedException {
    String localTempDir = createLocalTempDir();
    String dockerAddress = "unix:///var/run/docker.sock";
    String dockerImage = "ubuntu:latest";
    DockerClient dockerClient = new DefaultDockerClient(dockerAddress);
    String localInput = FilenameUtils.concat(localTempDir, "file_on_host.txt");

    PrintStream stream = new PrintStream(localInput);
    stream.append("\nHello from the host machine.\n");
    stream.close();//from  w  w w. j  ava2  s. co  m

    // Run a simple command in the container to demonstrate we can read the
    // file mounted from the host.
    ArrayList<String> command = new ArrayList<String>();
    command.add("cat");
    command.add("/mounted/file_on_host.txt");

    DockerProcessBuilder builder = new DockerProcessBuilder(command, dockerClient);
    builder.addVolumeMapping(localTempDir, "/mounted");
    builder.setImage(dockerImage);

    // Start and run the container.
    builder.start();
}

From source file:org.apache.sshd.SshServerDevelopment.java

private static final void waitForExit(BufferedReader in, PrintStream out, SshServer sshd) throws IOException {
    out.append("Listening on ").println(sshd.getPort());

    for (sshd.start();;) {
        String ans = getval(out, in, "(q)uit");
        if (isQuit(ans)) {
            break;
        }//ww w  .  j av a 2 s .  co m
    }
}

From source file:org.bml.util.errorconsumer.ParseErrorTable.java

/**
 * <p>/*  w ww  . j  a v a2s.  com*/
 * Returns a log printable report on the variables found in this class.
 * Helpful when modifying the table.
 * </p>
 *
 * @return A {@link String} report on the variables in this class
 */
private static final String report() {
    //Prefer Writer for MapUtils.
    ByteArrayOutputStream oStream = new ByteArrayOutputStream();
    PrintStream pStream = new PrintStream(oStream);
    //StringWriter buff = new StringWriter();
    String nl = CharacterUtils.NL;
    //Class Info
    pStream.append("Class : ").append(ParseErrorTable.class.getCanonicalName()).append(nl);
    //Type Info
    pStream.append("Type : mini ORM").append(nl);
    //Table Name
    pStream.append("TABLE_NAME : ").append(TABLE_NAME).append(nl);
    //Table Name
    pStream.append("Prepared Insert Statement : ").append(PREPARED_INSERT_SQL).append(nl);
    //COLUMN_TYPE_MAP
    MapUtils.debugPrint(pStream, "Colum To Class Map", COLUMN_TYPE_MAP);
    //COLUMN_PS_OFFSET_MAP
    MapUtils.debugPrint(pStream, "Colum To PreparedStatement Offset Map", COLUMN_PS_OFFSET_MAP);
    return oStream.toString();
}

From source file:it.mb.whatshare.PairOutboundActivity.java

/**
 * Saves the argument <tt>device</tt> as the (only) configured outbound
 * device.//from ww  w . j av  a 2  s  .  co m
 * 
 * <p>
 * If <tt>device</tt> is <code>null</code>, the currently configured device
 * is deleted.
 * 
 * @param device
 *            the device to be stored, or <code>null</code> if the current
 *            association must be discarded
 * @param context
 *            the application's context (used to open the association file
 *            with)
 * @throws IOException
 *             in case something is wrong with the file
 * @throws JSONException
 *             in case something is wrong with the argument <tt>device</tt>
 */
public static void savePairing(PairedDevice device, Context context) throws IOException, JSONException {
    if (device == null) {
        Utils.debug("deleting outbound device... %s",
                context.deleteFile(PAIRING_FILE_NAME) ? "success" : "fail");
    } else {
        FileOutputStream fos = context.openFileOutput(PAIRING_FILE_NAME, Context.MODE_PRIVATE);
        // @formatter:off
        JSONObject json = new JSONObject().put("name", device.name).put("type", device.type).put("assignedID",
                device.id);
        // @formatter:on
        PrintStream writer = new PrintStream(fos);
        writer.append(json.toString());
        writer.flush();
        writer.close();
    }
}

From source file:org.apache.any23.extractor.microdata.MicrodataParser.java

/**
 * Returns a <i>JSON</i> containing the list of all extracted Microdata,
 * as described at <a href="http://www.w3.org/TR/microdata/#json">Microdata JSON Specification</a>.
 *
 * @param document document to be processed.
 * @param ps the {@link java.io.PrintStream} to write JSON to
 *//* w  ww. j  a  v a  2 s  . c om*/
public static void getMicrodataAsJSON(Document document, PrintStream ps) {
    final MicrodataParserReport report = getMicrodata(document);
    final ItemScope[] itemScopes = report.getDetectedItemScopes();
    final MicrodataParserException[] errors = report.getErrors();

    ps.append("{ ");

    // Results.
    ps.append("\"result\" : [");
    for (int i = 0; i < itemScopes.length; i++) {
        if (i > 0) {
            ps.print(", ");
        }
        ps.print(itemScopes[i].toJSON());
    }
    ps.append("] ");

    // Errors.
    if (errors != null && errors.length > 0) {
        ps.append(", ");
        ps.append("\"errors\" : [");
        for (int i = 0; i < errors.length; i++) {
            if (i > 0) {
                ps.print(", ");
            }
            ps.print(errors[i].toJSON());
        }
        ps.append("] ");
    }

    ps.append("}");
}

From source file:org.hyperic.hq.stats.AbstractStatsWriter.java

public static void gzipFile(final String filename) {
    new Thread() {
        public void run() {
            FileOutputStream gfile = null;
            GZIPOutputStream gstream = null;
            PrintStream pstream = null;
            BufferedReader reader = null;
            boolean succeed = false;
            try {
                gfile = new FileOutputStream(filename + ".gz");
                gstream = new GZIPOutputStream(gfile);
                pstream = new PrintStream(gstream);
                reader = new BufferedReader(new FileReader(filename));
                String tmp;//from www. j a  v a2 s .com
                while (null != (tmp = reader.readLine())) {
                    pstream.append(tmp).append("\n");
                }
                gstream.finish();
                succeed = true;
            } catch (IOException e) {
                log.warn(e.getMessage(), e);
            } finally {
                close(gfile);
                close(gstream);
                close(pstream);
                close(reader);
                if (succeed) {
                    new File(filename).delete();
                } else {
                    new File(filename + ".gz").delete();
                }
            }
        }

        private void close(Closeable s) {
            if (s != null) {
                try {
                    s.close();
                } catch (IOException e) {
                    log.warn(e.getMessage(), e);
                }
            }
        }
    }.start();
}

From source file:edu.cornell.med.icb.goby.alignments.filters.PercentMismatchesQualityFilter.java

public void printUsage(final PrintStream out) {
    out.append("This quality filter rejects alignment entries that have more than a "
            + "certain threshold of differences with the target sequence. Base "
            + "mismatches, as well as insertion or deletion differences "
            + "are counted towards the difference count. The threshold is set by default "
            + "to 5% (0.05), but can be changed with the threshold parameter. Use "
            + "syntax threshold=value.\n");

}

From source file:org.efaps.util.EFapsException.java

/**
 * If a caused exception is a {@link SQLException}, also all next
 * exceptions of the {@link SQLException}'s are printed into the stack
 * trace.//  w ww. j a v a  2s.c  om
 *
 * @param _stream <code>PrintStream</code> to use for output
 * @see #makeInfo() to get all information about this EFapsException
 */
@Override
public void printStackTrace(final PrintStream _stream) {
    _stream.append(makeInfo());
    super.printStackTrace(_stream);
    if (getCause() != null && getCause() instanceof SQLException) {
        SQLException ex = (SQLException) getCause();
        ex = ex.getNextException();
        while (ex != null) {
            _stream.append("Next SQL Exception is: ");
            ex.printStackTrace(_stream);
            ex = ex.getNextException();
        }
    }
}