Example usage for java.io PrintStream print

List of usage examples for java.io PrintStream print

Introduction

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

Prototype

public void print(Object obj) 

Source Link

Document

Prints an object.

Usage

From source file:key.access.manager.HttpHandler.java

public String connect(String url, ArrayList data) throws IOException {
    try {//from   w w w . j  a va2 s  .  co  m
        // open a connection to the site
        URL connectionUrl = new URL(url);
        URLConnection con = connectionUrl.openConnection();
        // activate the output
        con.setDoOutput(true);
        PrintStream ps = new PrintStream(con.getOutputStream());
        // send your parameters to your site
        for (int i = 0; i < data.size(); i++) {
            ps.print(data.get(i));
            //System.out.println(data.get(i));
            if (i != data.size() - 1) {
                ps.print("&");
            }
        }

        // we have to get the input stream in order to actually send the request
        InputStream inStream = con.getInputStream();
        Scanner s = new Scanner(inStream).useDelimiter("\\A");
        String result = s.hasNext() ? s.next() : "";
        System.out.println(result);

        // close the print stream
        ps.close();
        return result;
    } catch (MalformedURLException e) {
        e.printStackTrace();
        return "error";
    } catch (IOException e) {
        e.printStackTrace();
        return "error";
    }
}

From source file:com.panet.imeta.shared.SharedObjects.java

public void saveToFile() throws IOException, KettleException {
    OutputStream outputStream = KettleVFS.getOutputStream(filename, false);

    PrintStream out = new PrintStream(outputStream);

    out.print(XMLHandler.getXMLHeader(Const.XML_ENCODING));
    out.println("<" + XML_TAG + ">");

    Collection<SharedObjectInterface> collection = objectsMap.values();
    for (SharedObjectInterface sharedObject : collection) {
        out.println(sharedObject.getXML());
    }/*from   w ww. j  a va2 s  .c o m*/

    out.println("</" + XML_TAG + ">");

    out.flush();
    out.close();
    outputStream.close();
}

From source file:com.bigdata.dastor.tools.SSTableExport.java

/**
 * Export specific rows from an SSTable and write the resulting JSON to a PrintStream.
 * /*from   ww w.j  a v  a  2 s .c  om*/
 * @param ssTableFile the SSTable to export the rows from
 * @param outs PrintStream to write the output to
 * @param keys the keys corresponding to the rows to export
 * @throws IOException on failure to read/write input/output
 */
public static void export(String ssTableFile, PrintStream outs, String[] keys, String[] excludes)
        throws IOException {
    SSTableReader reader = SSTableReader.open(ssTableFile);
    SSTableScanner scanner = reader.getScanner(INPUT_FILE_BUFFER_SIZE);
    IPartitioner<?> partitioner = DatabaseDescriptor.getPartitioner();
    Set<String> excludeSet = new HashSet();
    int i = 0;

    if (excludes != null)
        excludeSet = new HashSet<String>(Arrays.asList(excludes));

    outs.println("{");

    for (String key : keys) {
        if (excludeSet.contains(key))
            continue;
        DecoratedKey<?> dk = partitioner.decorateKey(key);
        scanner.seekTo(dk);

        i++;

        if (scanner.hasNext()) {
            IteratingRow row = scanner.next();
            try {
                String jsonOut = serializeRow(row);
                if (i != 1)
                    outs.println(",");
                outs.print("  " + jsonOut);
            } catch (IOException ioexc) {
                System.err.println("WARNING: Corrupt row " + key + " (skipping).");
                continue;
            } catch (OutOfMemoryError oom) {
                System.err.println("ERROR: Out of memory deserializing row " + key);
                continue;
            }
        }
    }

    outs.println("\n}");
    outs.flush();
}

From source file:io.horizondb.model.core.fields.ByteField.java

/**
 * {@inheritDoc}//from w ww.ja  v  a 2 s.  c o  m
 */
@Override
public void writePrettyPrint(PrintStream stream) {
    stream.print(this.value);
}

From source file:org.nuxeo.client.internals.spi.NuxeoClientException.java

@Override
public void printStackTrace(PrintStream s) {
    if (status == INTERNAL_ERROR_STATUS) {
        super.printStackTrace(s);
    }//from   w w w  .j a v a2  s.  com
    s.println("Exception:");
    s.print(getRemoteStackTrace());
}

From source file:jeeves.utils.Xml.java

/**
 * Loads an xml file from a URL after posting content to the URL.
 *
 * @param url//from  ww  w.  ja va  2  s.c  o  m
 * @param xmlQuery
 * @return
 * @throws IOException
 * @throws JDOMException
 */
public static Element loadFile(URL url, Element xmlQuery) throws IOException, JDOMException {
    Element result = null;
    try {
        HttpURLConnection connection = (HttpURLConnection) url.openConnection();
        connection.setRequestMethod("POST");
        connection.setRequestProperty("Content-Type", "application/xml");
        connection.setRequestProperty("Content-Length",
                "" + Integer.toString(getString(xmlQuery).getBytes("UTF-8").length));
        connection.setRequestProperty("Content-Language", "en-US");
        connection.setDoOutput(true);
        PrintStream out = new PrintStream(connection.getOutputStream(), true, "UTF-8");
        out.print(getString(xmlQuery));
        out.close();

        SAXBuilder builder = getSAXBuilderWithoutXMLResolver(false);//new SAXBuilder();
        Document jdoc = builder.build(connection.getInputStream());

        result = (Element) jdoc.getRootElement().detach();
    } catch (Exception e) {
        Log.error(Log.ENGINE, "Error loading URL " + url.getPath() + " .Threw exception " + e);
        e.printStackTrace();
    }
    return result;
}

From source file:com.recomdata.datasetexplorer.proxy.HttpClient.java

/**
 * posts data to the inputstream and returns the InputStream.
 * @param postData data to be posted. must be url-encoded already.
 * @param contentType allows you to set the contentType of the request.
 * @return InputStream input stream from URLConnection
 *///from  w  ww . ja  v a 2 s  . c  o m
public InputStream doPost(String postData, String contentType) {

    //   System.out.println("postdata:"+postData);
    //    System.out.println("ct:"+contentType);
    this.urlConnection.setDoOutput(true);
    if (contentType != null)
        this.urlConnection.setRequestProperty("Content-type", contentType);

    OutputStream os = this.getOutputStream();
    PrintStream ps = new PrintStream(os);
    ps.print(postData);
    ps.close();
    return (this.getInputStream());
}

From source file:playground.dgrether.events.handlers.DgGeoFilteredLegHistogram.java

/**
 * Writes the gathered data tab-separated into a text stream.
 *
 * @param stream The data stream where to write the gathered data.
 *//* w ww  . j  a  va 2s .  c o m*/
public void write(final PrintStream stream) {
    stream.print("time\ttime\tdepartures_all\tarrivals_all\tstuck_all\ten-route_all");
    stream.print("\n");
    int allEnRoute = 0;
    for (int i = 0; i < this.allModesData.countsDep.length; i++) {
        // data about all modes
        allEnRoute = allEnRoute + this.allModesData.countsDep[i] - this.allModesData.countsArr[i]
                - this.allModesData.countsStuck[i];
        stream.print(Time.writeTime(i * this.binSizeSeconds) + "\t" + i * this.binSizeSeconds);
        stream.print("\t" + this.allModesData.countsDep[i] + "\t" + this.allModesData.countsArr[i] + "\t"
                + this.allModesData.countsStuck[i] + "\t" + allEnRoute);
        // new line
        stream.print("\n");
    }
}

From source file:net.sf.vntconverter.VntConverter.java

/**
 * Dekodiert eine vNote-Datei in eine UTF-8-Textdatei.
 *//*from ww w . j ava  2 s  .co m*/
private void decode(File in, File out) {
    FileInputStream inStream = null;
    try {
        inStream = new FileInputStream(in);
        BufferedReader br = new BufferedReader(new InputStreamReader(inStream, "UTF-8"));
        String line = null;
        String content = "";
        while ((line = br.readLine()) != null) {
            if (line.startsWith("BEGIN:")) {
            } else if (line.startsWith("VERSION:")) {
            } else if (line.startsWith("DCREATED:")) {
            } else if (line.startsWith("LAST-MODIFIED:")) {
            } else if (line.startsWith("END:VNOTE")) {
            } else if (line.startsWith("BODY;CHARSET=UTF-8;ENCODING=QUOTED-PRINTABLE:")) {
                content = line.substring("BODY;CHARSET=UTF-8;ENCODING=QUOTED-PRINTABLE:".length());
            } else {
                content += line;
            }
            if (content.endsWith("=")) {
                content = content.substring(0, content.length() - 1);
            }
        }
        br.close();
        PrintStream ps = new PrintStream(out, "UTF-8");
        ps.print(decode(content));
        ps.close();
    } catch (Exception e) {
        throw new RuntimeException("Exception caught in VntConverter.decode(in, out):", e);
    } finally {
        if (inStream != null) {
            try {
                inStream.close();
            } catch (IOException e) {
                // Einfach ignorieren ist hier ok
            }
        }
    }
}

From source file:admin.controller.ServletAddHtmlTemplate.java

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods.//www  .  ja  v a 2  s .  co m
 *
 * @param request servlet request
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
public void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    super.processRequest(request, response);
    response.setContentType("text/html;charset=UTF-8");
    PrintWriter out = response.getWriter();
    Layout layout = new Layout();
    String fileName = null, filePath = null, fieldName = null, uploadPath = null, uploadType = null;
    StringBuffer string_buffer = new StringBuffer();

    try {
        /* TODO output your page here. You may use following sample code. */
        uploadPath = AppConstants.BASE_HTML_TEMPLATE_UPLOAD_PATH;
        BufferedReader reader = request.getReader();
        String line = null;
        while ((line = reader.readLine()) != null) {
            string_buffer.append(line);
        }

        JSONParser parser = new JSONParser();
        JSONObject json_html_template = null;
        json_html_template = (JSONObject) parser.parse(string_buffer.toString());
        String type = (String) json_html_template.get("type");

        //            BufferedReader txtfile = new BufferedReader(new FileReader("c:\\test.txt"));
        String model_id = (String) json_html_template.get("model_id");
        String model_name = (String) json_html_template.get("model_name");
        String html_content = (String) json_html_template.get("html_content");

        fileName = model_name + ".html";
        filePath = uploadPath + File.separator + fileName;
        File uploadDir = new File(uploadPath);
        if (!uploadDir.exists()) {
            uploadDir.mkdirs();
        }
        OutputStream htmlfile = new FileOutputStream(new File(filePath));

        PrintStream printhtml = new PrintStream(htmlfile);

        layout.editModel(Integer.parseInt(model_id), fileName);

        printhtml.print(html_content);

        printhtml.close();
        htmlfile.close();
        out.write("true");
    } catch (Exception ex) {
        logger.log(Level.SEVERE, "", ex);
        out.write(getSqlMethodsInstance().error);
    }
}