Example usage for java.io PrintStream checkError

List of usage examples for java.io PrintStream checkError

Introduction

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

Prototype

public boolean checkError() 

Source Link

Document

Flushes the stream and checks its error state.

Usage

From source file:Main.java

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

    // create a new PrintStream
    PrintStream ps = new PrintStream(System.out);

    // print a string
    ps.println(s);// w w  w . j a v a 2  s .  c  o m

    // check for errors and print
    ps.print(ps.checkError());
    ps.flush();
    ps.close();

}

From source file:com.sap.prd.mobile.ios.mios.Forker.java

private static void handleLog(final InputStream is, final PrintStream out) throws IOException {

    if (out.checkError())
        throw new IOException(
                "Cannot handle log output. PrintStream that should be used for log handling is damaged.");

    byte[] buff = new byte[1024];
    for (int i; (i = is.read(buff)) != -1;) {
        out.write(buff, 0, i);/*  ww w  . ja v a2 s. com*/
        if (out.checkError())
            throw new IOException(
                    "Cannot handle log output from xcodebuild. Underlying PrintStream indicates problems.");
    }

    out.flush();
}

From source file:org.apache.jxtadoop.io.IOUtils.java

/**
 * Copies from one stream to another./*from   w  ww  . java 2s  .  c  o m*/
 * @param in InputStrem to read from
 * @param out OutputStream to write to
 * @param buffSize the size of the buffer 
 * @param close whether or not close the InputStream and 
 * OutputStream at the end. The streams are closed in the finally clause.  
 */
public static void copyBytes(InputStream in, OutputStream out, int buffSize, boolean close) throws IOException {

    PrintStream ps = out instanceof PrintStream ? (PrintStream) out : null;
    byte buf[] = new byte[buffSize];
    try {
        int bytesRead = in.read(buf);
        while (bytesRead >= 0) {
            out.write(buf, 0, bytesRead);
            if ((ps != null) && ps.checkError()) {
                throw new IOException("Unable to write to output stream.");
            }
            bytesRead = in.read(buf);
        }
    } finally {
        if (close) {
            out.close();
            in.close();
            out = null;
            in = null;
        }
    }
}

From source file:eu.stratosphere.nephele.util.IOUtils.java

/**
 * Copies from one stream to another./*ww w.  j  av a  2  s.  co m*/
 * 
 * @param in
 *        InputStream to read from
 * @param out
 *        OutputStream to write to
 * @param buffSize
 *        the size of the buffer
 * @param close
 *        whether or not close the InputStream and OutputStream at the end. The streams are closed in the finally
 *        clause.
 * @throws IOException
 *         thrown if an error occurred while writing to the output stream
 */
public static void copyBytes(final InputStream in, final OutputStream out, final int buffSize,
        final boolean close) throws IOException {

    final PrintStream ps = out instanceof PrintStream ? (PrintStream) out : null;
    final byte[] buf = new byte[buffSize];
    try {
        int bytesRead = in.read(buf);
        while (bytesRead >= 0) {
            out.write(buf, 0, bytesRead);
            if ((ps != null) && ps.checkError()) {
                throw new IOException("Unable to write to output stream.");
            }
            bytesRead = in.read(buf);
        }
    } finally {
        if (close) {
            out.close();
            in.close();
        }
    }
}

From source file:com.ery.ertc.estorm.util.IOUtils.java

/**
 * Copies from one stream to another.//from  www .  j a v  a2 s. c om
 * 
 * @param in
 *            InputStrem to read from
 * @param out
 *            OutputStream to write to
 * @param buffSize
 *            the size of the buffer
 */
public static void copyBytes(InputStream in, OutputStream out, int buffSize) throws IOException {

    PrintStream ps = out instanceof PrintStream ? (PrintStream) out : null;
    byte buf[] = new byte[buffSize];
    int bytesRead = in.read(buf);
    while (bytesRead >= 0) {
        out.write(buf, 0, bytesRead);
        if ((ps != null) && ps.checkError()) {
            throw new IOException("Unable to write to output stream.");
        }
        bytesRead = in.read(buf);
    }
}

From source file:org.apache.flink.runtime.util.IOUtils.java

/**
 * Copies from one stream to another./* ww w .  jav  a2  s  .  c o  m*/
 * 
 * @param in
 *        InputStream to read from
 * @param out
 *        OutputStream to write to
 * @param buffSize
 *        the size of the buffer
 * @param close
 *        whether or not close the InputStream and OutputStream at the end. The streams are closed in the finally
 *        clause.
 * @throws IOException
 *         thrown if an error occurred while writing to the output stream
 */
public static void copyBytes(final InputStream in, final OutputStream out, final int buffSize,
        final boolean close) throws IOException {

    @SuppressWarnings("resource")
    final PrintStream ps = out instanceof PrintStream ? (PrintStream) out : null;
    final byte[] buf = new byte[buffSize];
    try {
        int bytesRead = in.read(buf);
        while (bytesRead >= 0) {
            out.write(buf, 0, bytesRead);
            if ((ps != null) && ps.checkError()) {
                throw new IOException("Unable to write to output stream.");
            }
            bytesRead = in.read(buf);
        }
    } finally {
        if (close) {
            out.close();
            in.close();
        }
    }
}

From source file:com.buaa.cfs.utils.IOUtils.java

/**
 * Copies from one stream to another.//from   w  w  w. j  a  v a2s  .  co  m
 *
 * @param in       InputStrem to read from
 * @param out      OutputStream to write to
 * @param buffSize the size of the buffer
 */
public static void copyBytes(InputStream in, OutputStream out, int buffSize) throws IOException {
    PrintStream ps = out instanceof PrintStream ? (PrintStream) out : null;
    byte buf[] = new byte[buffSize];
    int bytesRead = in.read(buf);
    while (bytesRead >= 0) {
        out.write(buf, 0, bytesRead);
        if ((ps != null) && ps.checkError()) {
            throw new IOException("Unable to write to output stream.");
        }
        bytesRead = in.read(buf);
    }
}

From source file:org.apache.orc.tools.PrintData.java

static void printJsonData(PrintStream printStream, Reader reader) throws IOException, JSONException {
    OutputStreamWriter out = new OutputStreamWriter(printStream, "UTF-8");
    RecordReader rows = reader.rows();//from   ww w.ja v  a 2 s .c  o m
    try {
        TypeDescription schema = reader.getSchema();
        VectorizedRowBatch batch = schema.createRowBatch();
        while (rows.nextBatch(batch)) {
            for (int r = 0; r < batch.size; ++r) {
                JSONWriter writer = new JSONWriter(out);
                printRow(writer, batch, schema, r);
                out.write("\n");
                out.flush();
                if (printStream.checkError()) {
                    throw new IOException("Error encountered when writing to stdout.");
                }
            }
        }
    } finally {
        rows.close();
    }
}

From source file:org.apache.hadoop.hive.ql.io.orc.FileDump.java

static void printJsonData(Configuration conf, String filename) throws IOException, JSONException {
    Path path = new Path(filename);
    Reader reader = OrcFile.createReader(path.getFileSystem(conf), path);
    PrintStream printStream = System.out;
    OutputStreamWriter out = new OutputStreamWriter(printStream, "UTF-8");
    RecordReader rows = reader.rows(null);
    Object row = null;//from  w  w  w . ja v  a 2 s .c om
    List<OrcProto.Type> types = reader.getTypes();
    while (rows.hasNext()) {
        row = rows.next(row);
        JSONWriter writer = new JSONWriter(out);
        printObject(writer, row, types, 0);
        out.write("\n");
        out.flush();
        if (printStream.checkError()) {
            throw new IOException("Error encountered when writing to stdout.");
        }
    }
}

From source file:org.apache.tuscany.sca.implementation.bpel.ode.BPELODEDeployFile.java

/**
 * Writes the deploy file into the same directory as the BPEL process file, with the name
 * "deploy.xml"/*w w w .  j  a  v  a 2  s.  c om*/
 */
public void writeDeployfile() throws IOException {

    File theDirectory = getDirectory();

    File deployFile = new File(theDirectory, DEPLOY_FILENAME);
    new FileOutputStream(deployFile);
    //if( !deployFile.canWrite() ) throw new IOException( "Unable to write to deploy file" +
    //                                                   deployFile.getPath() );

    // Create a stream for the data and write the data to the file
    PrintStream theStream = new PrintStream(new FileOutputStream(deployFile));
    try {
        constructDeployXML(theStream);
        if (theStream.checkError())
            throw new IOException();
    } catch (Exception e) {
        throw new IOException("Unable to write data to deploy file" + deployFile.getPath());
    } finally {
        theStream.close();
    } // end try

}