Example usage for java.io OutputStreamWriter OutputStreamWriter

List of usage examples for java.io OutputStreamWriter OutputStreamWriter

Introduction

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

Prototype

public OutputStreamWriter(OutputStream out) 

Source Link

Document

Creates an OutputStreamWriter that uses the default character encoding.

Usage

From source file:java2typescript.jaxrs.DescriptorGeneratorTest.java

@Before
public void setUp() {
    out = new OutputStreamWriter(System.out);
}

From source file:ar.com.zauber.labs.kraken.providers.wikipedia.apps.administrative.TabseparatedValueArgentinaWikiSecondLevelClosureTest.java

/** test */
@Test/* ww w .  ja  va 2  s  .c o m*/
public final void testFoo() throws Exception {
    new TabseparatedValueArgentinaWikiSecondLevelClosure(new OutputStreamWriter(System.out)).execute(l);
}

From source file:com.adaptris.core.AbstractMarshaller.java

/**
 * @see AdaptrisMarshaller#marshal(java.lang.Object, OutputStream)
 *//*ww w.  j  av  a2 s. c om*/
@Override
public void marshal(Object obj, OutputStream outputStream) throws CoreException {
    this.marshal(obj, new OutputStreamWriter(outputStream));
}

From source file:com.wavemaker.tools.webapp.WebXmlSupportTest.java

public void testReadWrite() throws Exception {

    File f = new ClassPathResource("com/wavemaker/tools/webapp/" + ProjectConstants.WEB_XML).getFile();
    assertTrue(f.exists());//  w w w  .  j ava 2  s.com

    WebAppType wat = WebXmlSupport.readWebXml(new FileSystemResource(f));

    for (Object o : wat.getDescriptionAndDisplayNameAndIcon()) {
        if (o instanceof DisplayNameType) {
            DisplayNameType dnt = (DisplayNameType) o;
            assertEquals("ActiveGrid Studio", dnt.getValue());
        } else if (o instanceof ServletType) {
            ServletType st = (ServletType) o;
            assertEquals("springapp", st.getServletName().getValue());
        } else {
            // System.out.println("o: "+o);
        }
    }

    File fp = File.createTempFile("TestWebXmlSupport_testReadWrite", ".xml");
    fp.deleteOnExit();

    try {
        OutputStreamWriter osw = new OutputStreamWriter(new FileOutputStream(fp));
        WebXmlSupport.writeWebXml(wat, osw);
        String fpContents = FileUtils.readFileToString(fp);

        assertTrue(fpContents.contains("ActiveGrid Studio"));
        assertTrue(fpContents.contains("springapp"));

        WebXmlSupport.readWebXml(new FileSystemResource(fp));
    } finally {
        fp.delete();
    }
}

From source file:com.votingcentral.services.maxmind.MaxMindGeoLocationService.java

public MaxMindLocationTO getLocation(String ipAddress) {
    MaxMindLocationTO mto = new MaxMindLocationTO();
    String specificData = data + FastURLEncoder.encode(ipAddress, "UTF-8");
    URL url;/*from  w ww .j  a  v a2s .c om*/
    OutputStreamWriter wr = null;
    BufferedReader rd = null;
    try {
        url = new URL(surl);
        URLConnection conn = url.openConnection();
        conn.setDoOutput(true);
        wr = new OutputStreamWriter(conn.getOutputStream());
        wr.write(specificData);
        wr.flush();
        // Get the response
        rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
        String line;
        while ((line = rd.readLine()) != null) {
            String[] values = StringUtils.split(line, ",");
            int maxIndex = values.length - 1;
            if (maxIndex >= 0) {
                mto.setISO3166TwoLetterCountryCode(values[0]);
            }
            if (maxIndex >= 1) {
                mto.setRegionCode(values[1]);
            }
            if (maxIndex >= 2) {
                mto.setCity(values[2]);
            }
            if (maxIndex >= 3) {
                mto.setPostalCode(values[3]);
            }
            if (maxIndex >= 4) {
                mto.setLatitude(values[4]);
            }
            if (maxIndex >= 5) {
                mto.setLongitude(values[5]);
            }
            if (maxIndex >= 6) {
                mto.setMetropolitanCode(values[6]);
            }
            if (maxIndex >= 7) {
                mto.setAreaCode(values[7]);
            }
            if (maxIndex >= 8) {
                mto.setIsp(values[8]);
            }
            if (maxIndex >= 9) {
                mto.setOranization(values[9]);
            }
            if (maxIndex >= 10) {
                mto.setError(MaxMindErrorsEnum.get(values[10]));
            }
        }
    } catch (MalformedURLException e) {
        log.fatal("Issue calling Maxmind", e);
        mto.setError(MaxMindErrorsEnum.VC_INTERNAL_ERROR);
    } catch (IOException e) {
        log.fatal("Issue reading Maxmind", e);
        mto.setError(MaxMindErrorsEnum.VC_INTERNAL_ERROR);
    } finally {
        if (wr != null) {
            try {
                wr.close();
            } catch (IOException e1) {
                log.fatal("Issue closing Maxmind", e1);
                mto.setError(MaxMindErrorsEnum.VC_INTERNAL_ERROR);
            }
        }
        if (rd != null) {
            try {
                rd.close();
            } catch (IOException e1) {
                log.fatal("Issue closing Maxmind", e1);
                mto.setError(MaxMindErrorsEnum.VC_INTERNAL_ERROR);
            }
        }
    }
    return mto;
}

From source file:edu.harvard.hms.dbmi.bd2k.irct.ws.rs.resultconverter.CSVTabularDataConverter.java

@Override
public StreamingOutput createStream(final Result result) {
    StreamingOutput stream = new StreamingOutput() {
        @Override//w w w. ja va 2 s. com
        public void write(OutputStream outputStream) throws IOException, WebApplicationException {
            ResultSet rs = null;
            CSVPrinter printer = null;
            try {
                rs = (ResultSet) result.getData();
                rs.load(result.getResultSetLocation());

                printer = new CSVPrinter(new OutputStreamWriter(outputStream), CSVFormat.DEFAULT);

                String[] columnHeaders = new String[rs.getColumnSize()];
                for (int i = 0; i < rs.getColumnSize(); i++) {
                    columnHeaders[i] = rs.getColumn(i).getName();
                }
                printer.printRecord((Object[]) columnHeaders);

                rs.beforeFirst();
                while (rs.next()) {
                    String[] row = new String[rs.getColumnSize()];
                    for (int i = 0; i < rs.getColumnSize(); i++) {
                        row[i] = rs.getString(i);
                    }
                    printer.printRecord((Object[]) row);
                }
                printer.flush();

            } catch (ResultSetException | PersistableException e) {
                log.info("Error creating CSV Stream: " + e.getMessage());
            } finally {
                if (printer != null) {
                    printer.close();
                }

                if (rs != null && !rs.isClosed()) {
                    try {
                        rs.close();
                    } catch (ResultSetException e) {
                        e.printStackTrace();
                    }
                }
                if (outputStream != null) {
                    outputStream.close();
                }
            }

        }
    };
    return stream;
}

From source file:net.mindengine.oculus.frontend.web.controllers.test.AjaxParameterSearchController.java

@Override
public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception {

    OutputStream os = response.getOutputStream();
    response.setContentType("text/xml");

    String rId = request.getParameter("id");

    OutputStreamWriter w = new OutputStreamWriter(os);

    String rootId = rId;/*from   w ww .j av  a2 s  . co  m*/
    w.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
    w.write("<tree id=\"" + rootId + "\" >");

    List<Project> projects = null;
    List<TestGroup> groups = null;
    List<Test> tests = null;
    List<TestParameter> parameters = null;
    if (rId.equals("0")) {
        // Fetching a list of projects
        projects = projectDAO.getRootProjects();
    } else if (rId.startsWith("p")) {
        Long projectId = Long.parseLong(rId.substring(1));
        projects = projectDAO.getSubprojects(projectId);

        tests = testDAO.getTestsByProjectId(projectId, 0L);
        groups = testDAO.getProjectTestGroups(projectId);
    } else if (rId.startsWith("g")) {
        // g123_456 where 123 - id of a group and 456 - id of a project
        int dash = rId.indexOf("_");
        Long groupId = Long.parseLong(rId.substring(1, dash));
        Long projectId = Long.parseLong(rId.substring(dash + 1));

        tests = testDAO.getTestsByProjectId(projectId, groupId);
    } else if (rId.startsWith("t")) {
        Long testId = Long.parseLong(rId.substring(1));
        parameters = testDAO.getTestInputParameters(testId);
        parameters.addAll(testDAO.getTestOutputParameters(testId));
    }

    if (projects != null) {
        for (Project project : projects) {
            w.write("<item text=\"" + XmlUtils.escapeXml(project.getName()) + "\" " + "id=\"p" + project.getId()
                    + "\" im0=\"tombs.gif\" im1=\"tombs_open.gif\" im2=\"tombs.gif\" child=\"1\" "
                    + " nocheckbox=\"1\" >");
            w.write("</item>");
        }
    }
    if (groups != null) {
        for (TestGroup group : groups) {
            w.write("<item ");
            w.write("text=\"" + XmlUtils.escapeXml(group.getName()) + "\" ");
            w.write("id=\"g" + group.getId() + "_" + group.getProjectId() + "\" ");
            w.write("im0=\"folderClosed.gif\" im1=\"folderOpen.gif\" im2=\"folderClosed.gif\" ");
            w.write("child=\"1\" nocheckbox=\"1\"  >");
            w.write("</item>");
        }
    }
    if (tests != null) {
        for (Test test : tests) {
            w.write("<item ");
            w.write("text=\"" + XmlUtils.escapeXml(test.getName()) + "\" ");
            w.write("id=\"t" + test.getId() + "\" ");
            w.write("im0=\"iconTest.png\" im1=\"iconTest.png\" im2=\"iconTest.png\" ");
            w.write("child=\"1\" nocheckbox=\"1\"  >");
            w.write("</item>");
        }
    }
    if (parameters != null) {
        for (TestParameter parameter : parameters) {
            w.write("<item ");
            w.write("text=\"" + XmlUtils.escapeXml(parameter.getName()) + "\" ");
            w.write("id=\"tp" + parameter.getId() + "\" ");

            if (parameter.getType().equals(TestParameter.TYPE_INPUT)) {
                w.write("im0=\"iconParameterInput.png\" im1=\"iconParameterInput.png\" im2=\"iconParameterInput.png\" ");
            } else
                w.write("im0=\"iconParameterOutput.png\" im1=\"iconParameterOutput.png\" im2=\"iconParameterOutput.png\" ");
            w.write(" >");
            w.write("</item>");
        }
    }

    w.write("</tree>");
    w.flush();
    os.flush();
    os.close();
    return null;
}

From source file:com.ait.tooling.server.core.json.binder.JSONBinder.java

@Override
public void send(final OutputStream stream, final Object object) throws ParserException {
    Objects.requireNonNull(object);

    try {//from w  w  w.  j  a  va2s .com
        if (object instanceof JSONObject) {
            ((JSONObject) object).writeJSONString(new OutputStreamWriter(stream), isStrict());
        } else {
            super.send(stream, object);
        }
    } catch (Exception e) {
        throw new ParserException(e);
    }
}

From source file:edu.pitt.dbmi.ipm.service.EntityStreamingOutput.java

/**
 * Writes to stream.//from  w  ww  . j  av a 2s  .c  om
 */
@Override
public void write(OutputStream output) throws IOException, WebApplicationException {

    byte[] buffer = new byte[1024];
    int read = -1;
    InputStream instream = null;

    try {

        instream = entity.getContent();
        BufferedReader br = new BufferedReader(new InputStreamReader(instream));
        Writer writer = new BufferedWriter(new OutputStreamWriter(output));

        String line = null;
        while ((line = br.readLine()) != null) {
            line = line.replaceAll("\"", "");
            writer.write(line + "\n");
            writer.flush();
        }

    } catch (IOException e) {
        throw new RuntimeException(e);
    } finally {

        if (instream != null)
            instream.close();

        if (output != null)
            output.close();

        httpclient.getConnectionManager().shutdown();
    }

}

From source file:org.talend.components.webtest.JsonIo2HttpMessageConverter.java

/**
 * Serializes specified Object and writes JSON to HTTP message body 
 * //from  w  w w  .  ja  va 2 s  .  co  m
 * @param t Object to serialize
 * @param outputMessage the HTTP output message to write to
 */
@Override
protected void writeInternal(Object t, HttpOutputMessage outputMessage)
        throws IOException, HttpMessageNotWritableException {
    OutputStreamWriter outputStreamWriter = new OutputStreamWriter(outputMessage.getBody());
    String objectToJson = JsonWriter.objectToJson(t);
    outputStreamWriter.write(objectToJson);
    outputStreamWriter.flush();
    outputStreamWriter.close();
}