Example usage for java.io PrintWriter print

List of usage examples for java.io PrintWriter print

Introduction

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

Prototype

public void print(Object obj) 

Source Link

Document

Prints an object.

Usage

From source file:dk.netarkivet.archive.arcrepositoryadmin.ArcRepositoryEntry.java

/** Write this object to persistent storage.
*
* @param o A stream to write to./*from w w  w . j a  v  a2 s.c o m*/
*/
void output(PrintWriter o) {
    o.print(filename + GENERAL_DELIMITER);
    o.print(md5sum);
    o.print(GENERAL_DELIMITER + getGeneralStoreState().toString());

    for (Map.Entry<String, ArchiveStoreState> entry : storeStates.entrySet()) {
        o.print(ENTRY_COMPONENT_SEPARATOR_STRING + entry.getKey() + GENERAL_DELIMITER + entry.getValue());
    }
}

From source file:io.github.gsteckman.rpi_rest.SsdpHandler.java

private String generateSearchResponse() throws IOException {
    StringWriter sw = new StringWriter();
    PrintWriter pw = new PrintWriter(sw);
    pw.print("HTTP/1.1 200 OK\r\n");
    pw.printf("CACHE-CONTROL: max-age=%d\r\n", MAX_AGE);
    pw.print("EXT:\r\n");
    pw.printf("LOCATION: http://%s:8080\r\n", getServerAddress());
    pw.print("SERVER: " + System.getProperty("os.name") + "/" + System.getProperty("os.version")
            + ", UPnP/1.1, rpi-rest/0.1\r\n");
    pw.printf("ST: %s\r\n", ST);
    pw.printf("USN: uuid:%s\r\n", getUuid().toString());
    pw.printf("BOOTID.UPNP.ORG: %d\r\n", BOOTID);
    pw.printf("CONFIGID.UPNP.ORG: %d\r\n", CONFIGID);
    pw.printf("\r\n");
    pw.flush();//w w  w .j  a  v a2  s .  co m
    String resp = sw.toString();
    pw.close();
    sw.close();
    return resp;
}

From source file:io.milton.cloud.server.apps.contacts.ContactResource.java

public void writeData(OutputStream out) {
    String s = contactManager.getContactAsCarddav(contact);
    PrintWriter pw = new PrintWriter(out);
    pw.print(s);
    pw.flush();//from  w  w w .j  av  a  2s.  c om

}

From source file:net.sourceforge.mavenhippo.gen.BeanGeneratorTest.java

private File generateClass(BeanGenerator beanGenerator, String xmlFileName)
        throws IOException, FileNotFoundException, ContentTypeException, TemplateException {
    ContentTypeBean contentType = getContentTypeBean(xmlFileName);
    File myCompound = new File(
            beansFolder.getAbsoluteFile() + File.separator + beanGenerator.getClassName(contentType) + ".java");
    myCompound.createNewFile();/*from   ww w .j  a  v  a2s. com*/
    PrintWriter out = new PrintWriter(myCompound);
    String generateBean = beanGenerator.generateBean(contentType);
    out.print(generateBean);
    out.close();
    return myCompound;
}

From source file:org.clothocad.phagebook.controllers.AutoCompleteController.java

@RequestMapping(value = "/autoCompleteProjects", method = RequestMethod.GET)
protected void autoCompleteProjects(@RequestParam Map<String, String> params, HttpServletResponse response)
        throws ServletException, IOException {

    //I WILL RETURN THE MAP AS A JSON OBJECT.. it is client side's issue to parse all data for what they need!
    //they could check over there if the schema matches what they are querying for and so i can do this generically!
    //user should be logged in so I will log in as that user.
    String name = params.get("name") != null ? params.get("name") : "";
    boolean isValid = false;
    System.out.println("Name is: " + name);
    if (!name.equals("")) {
        isValid = true;//from  w w  w.ja v  a 2s. co  m
    }

    if (isValid) {
        ClothoConnection conn = new ClothoConnection(Args.clothoLocation);
        Clotho clothoObject = new Clotho(conn);
        //TODO: we need to have an authentication token at some point

        String username = this.backendPhagebookUser;
        String password = this.backendPhagebookPassword;

        Map loginMap = new HashMap();
        loginMap.put("username", username);
        loginMap.put("credentials", password);

        clothoObject.login(loginMap);
        Map query = new HashMap();

        query.put("query", name); // the value for which we are querying.
        query.put("key", "name"); // the key of the object we are querying

        List<Project> projects = ClothoAdapter.queryProject(query, clothoObject,
                ClothoAdapter.QueryMode.STARTSWITH);
        org.json.JSONArray responseArray = new org.json.JSONArray();
        for (Project proj : projects) {
            JSONObject obj = new JSONObject();
            obj.put("id", proj.getId());
            obj.put("name", proj.getName());
            responseArray.put(obj);
        }

        response.setStatus(HttpServletResponse.SC_ACCEPTED);
        response.setContentType("application/json");
        PrintWriter out = response.getWriter();
        out.print(responseArray);
        out.flush();
        out.close();

        clothoObject.logout();
        conn.closeConnection();

    }
    response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
    response.setContentType("application/json");
    JSONObject reply = new JSONObject();
    reply.put("message", "Auto Complete requires a query parameter");
    PrintWriter out = response.getWriter();
    out.print(reply);
    out.flush();
    out.close();
}

From source file:br.com.atmatech.sac.webService.WebServiceCadastro.java

public PessoaBeans postWebService(String cnpj) throws IOException {
    PessoaBeans pb = new PessoaBeans();
    HttpPost post = new HttpPost("http://appasp.sefaz.go.gov.br/Sintegra/Consulta/consultar.asp");
    List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
    nameValuePairs.add(new BasicNameValuePair("rTipoDoc", "2"));
    nameValuePairs.add(new BasicNameValuePair("tDoc", cnpj));
    nameValuePairs.add(new BasicNameValuePair("tCCE", ""));
    nameValuePairs.add(new BasicNameValuePair("tCNPJ", cnpj));
    nameValuePairs.add(new BasicNameValuePair("tCPF", ""));
    nameValuePairs.add(new BasicNameValuePair("btCGC", "Consultar"));
    nameValuePairs.add(new BasicNameValuePair("zion.SystemAction", "consultarSintegra()"));
    nameValuePairs.add(new BasicNameValuePair("zion.OnSubmited", ""));
    nameValuePairs.add(new BasicNameValuePair("zion.FormElementPosted", "zionFormID_1"));
    nameValuePairs.add(new BasicNameValuePair("zionPostMethod", ""));
    nameValuePairs.add(new BasicNameValuePair("zionRichValidator", "true"));
    post.setEntity(new UrlEncodedFormEntity(nameValuePairs, Consts.UTF_8));
    HttpResponse response;/*  w  w w.  ja va  2  s .co  m*/

    response = client.execute(post);

    BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
    String inputLine;
    // Grava pagina no arquivo
    // BufferedWriter out = new BufferedWriter(new FileWriter("./pagina.txt"));
    //        while ((inputLine = rd.readLine()) != null) {
    //            out.write(inputLine);
    //            out.newLine();
    //        }
    // Grava pagina no arquivo
    FileWriter out = new FileWriter("./pagina.txt");
    PrintWriter gravarArq = new PrintWriter(out);
    while ((inputLine = rd.readLine()) != null) {
        gravarArq.print(inputLine + "\n");
    }
    out.close();

    String insc = searchTableWeb("Estadual - CCE :", new BufferedReader(new FileReader("./pagina.txt")));
    if (insc != null) {
        pb.setIe(insc.replaceAll("[.-]", ""));
    }
    pb.setRazao(searchTableWeb("Nome Empresarial:", new BufferedReader(new FileReader("./pagina.txt"))));
    pb.setEndereco(searchTableWeb("Logradouro:", new BufferedReader(new FileReader("./pagina.txt"))));
    pb.setNumero(searchTableWeb("mero:", new BufferedReader(new FileReader("./pagina.txt"))));
    pb.setBairro(searchTableWeb("Bairro:", new BufferedReader(new FileReader("./pagina.txt"))));
    pb.setDistrito(searchTableWeb("pio:", new BufferedReader(new FileReader("./pagina.txt"))));
    String tel = searchTableWeb("Telefone:", new BufferedReader(new FileReader("./pagina.txt")));
    if (tel != null) {
        pb.setTelefone1(tel.replaceAll("[()]", "").replaceAll(" ", ""));
    }
    return pb;
}

From source file:br.com.atmatech.sac.webService.WebServiceCadastro.java

public EmpresaBeans postWebServiceEmp(String cnpj) throws IOException {
    EmpresaBeans pb = new EmpresaBeans();
    HttpPost post = new HttpPost("http://appasp.sefaz.go.gov.br/Sintegra/Consulta/consultar.asp");
    List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
    nameValuePairs.add(new BasicNameValuePair("rTipoDoc", "2"));
    nameValuePairs.add(new BasicNameValuePair("tDoc", cnpj));
    nameValuePairs.add(new BasicNameValuePair("tCCE", ""));
    nameValuePairs.add(new BasicNameValuePair("tCNPJ", cnpj));
    nameValuePairs.add(new BasicNameValuePair("tCPF", ""));
    nameValuePairs.add(new BasicNameValuePair("btCGC", "Consultar"));
    nameValuePairs.add(new BasicNameValuePair("zion.SystemAction", "consultarSintegra()"));
    nameValuePairs.add(new BasicNameValuePair("zion.OnSubmited", ""));
    nameValuePairs.add(new BasicNameValuePair("zion.FormElementPosted", "zionFormID_1"));
    nameValuePairs.add(new BasicNameValuePair("zionPostMethod", ""));
    nameValuePairs.add(new BasicNameValuePair("zionRichValidator", "true"));
    post.setEntity(new UrlEncodedFormEntity(nameValuePairs, Consts.UTF_8));
    HttpResponse response;//from  w w  w  . j  a va  2s . com

    response = client.execute(post);

    BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
    String inputLine;
    // Grava pagina no arquivo
    // BufferedWriter out = new BufferedWriter(new FileWriter("./pagina.txt"));
    //        while ((inputLine = rd.readLine()) != null) {
    //            out.write(inputLine);
    //            out.newLine();
    //        }
    // Grava pagina no arquivo
    FileWriter out = new FileWriter("./pagina.txt");
    PrintWriter gravarArq = new PrintWriter(out);
    while ((inputLine = rd.readLine()) != null) {
        gravarArq.print(inputLine + "\n");
    }
    out.close();

    String insc = searchTableWeb("Estadual - CCE :", new BufferedReader(new FileReader("./pagina.txt")));
    if (insc != null) {
        pb.setIe(insc.replaceAll("[.-]", ""));
    }
    pb.setRazao(searchTableWeb("Nome Empresarial:", new BufferedReader(new FileReader("./pagina.txt"))));
    pb.setEndereco(searchTableWeb("Logradouro:", new BufferedReader(new FileReader("./pagina.txt"))));
    pb.setNumero(searchTableWeb("mero:", new BufferedReader(new FileReader("./pagina.txt"))));
    pb.setBairro(searchTableWeb("Bairro:", new BufferedReader(new FileReader("./pagina.txt"))));
    pb.setDistrito(searchTableWeb("pio:", new BufferedReader(new FileReader("./pagina.txt"))));
    String tel = searchTableWeb("Telefone:", new BufferedReader(new FileReader("./pagina.txt")));
    if (tel != null) {
        pb.setTelefone1(tel.replaceAll("[()]", "").replaceAll(" ", ""));
    }
    return pb;
}

From source file:net.yacy.grid.http.AbstractAPIHandler.java

private void process(HttpServletRequest request, HttpServletResponse response, Query query)
        throws ServletException, IOException {

    long startTime = System.currentTimeMillis();

    // extract standard query attributes
    String callback = query.get("callback", "");
    boolean jsonp = callback.length() > 0;
    boolean minified = query.get("minified", false);

    try {/*from ww  w . j  a v a 2 s  .  c  o m*/
        ServiceResponse serviceResponse = serviceImpl(query, response);
        if (serviceResponse == null) {
            String message = "your request does not contain the required data";
            logClient(startTime, query, 400, message);
            response.sendError(400, message);
            return;
        }
        if (serviceResponse.allowCORS()) {
            setCORS(response);
        }

        // write json
        query.setResponse(response, serviceResponse.getMimeType());
        response.setCharacterEncoding("UTF-8");
        if (serviceResponse.isObject() || serviceResponse.isArray()) {
            PrintWriter sos = response.getWriter();
            if (jsonp)
                sos.print(callback + "(");
            String out = serviceResponse.toString(minified);
            sos.print(out);
            if (jsonp)
                sos.println(");");
            sos.println();
            logClient(startTime, query, 200, "ok: " + (minified ? out : serviceResponse.toString(true)));
        } else if (serviceResponse.isString()) {
            PrintWriter sos = response.getWriter();
            String out = serviceResponse.toString(false);
            sos.print(out);
            logClient(startTime, query, 200, "ok: " + out);
        } else if (serviceResponse.isByteArray()) {
            response.getOutputStream().write(serviceResponse.getByteArray());
            response.setHeader("Access-Control-Allow-Origin", "*");
            logClient(startTime, query, 200, "ok (ByteArray)");
        }
    } catch (APIException e) {
        String message = e.getMessage();
        logClient(startTime, query, e.getStatusCode(), message);
        response.sendError(e.getStatusCode(), message);
        return;
    }
}

From source file:net.mohatu.bloocoin.miner.RegCustom.java

private void saveBloostamp() {
    File bloocoinFolder = new File(System.getProperty("user.home") + "/.bloocoin");
    if (!bloocoinFolder.exists()) {
        System.out.println("Creating " + System.getProperty("user.home") + "/.bloocoin" + " directory");
        boolean result = bloocoinFolder.mkdir();
        if (result) {
            System.out.println("bloocoin folder created");
        }/*w w  w  . ja v  a2 s.  c  o m*/
    }
    try {
        PrintWriter out = new PrintWriter(new BufferedWriter(
                new FileWriter(System.getProperty("user.home") + "/.bloocoin/bloostamp" + addr)));
        out.print(addr + ":" + key);
        Main.updateStatusText("bloostamp" + addr + " created.", Color.blue);
        out.close();
        Main.loadDataPub();

    } catch (IOException e) {
        System.out.println("Saving failed:");
        e.printStackTrace();
    }
}

From source file:LocaleInformationServlet.java

public void doGet(HttpServletRequest request, HttpServletResponse response)
        throws IOException, ServletException {

    response.setContentType("text/html");
    PrintWriter out = response.getWriter();

    Locale userPreferredLocale = request.getLocale();
    Enumeration userPreferredLocales = request.getLocales();

    out.println("Preferred Locale: " + userPreferredLocale.toString());
    out.println("");
    out.print("Preferred Locales: ");

    while (userPreferredLocales.hasMoreElements()) {
        userPreferredLocale = (Locale) userPreferredLocales.nextElement();
        out.print(userPreferredLocale.toString() + ", ");
    }//from   w  w  w  . j  ava2  s  . c  om
    out.println();
    out.println("");
}