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:jp.go.aist.six.util.core.web.spring.StringRequestCallback.java

public void doWithRequest(final ClientHttpRequest request) throws IOException {
    HttpHeaders headers = request.getHeaders();
    headers.setContentType(_mediaType);//from   w  ww.  j  a  va2s .  c  o m

    long size = IoUtil.copy(new StringReader(_string.toString()), new OutputStreamWriter(request.getBody()));
    headers.setContentLength(size);
}

From source file:com.msopentech.odatajclient.engine.data.Serializer.java

/**
 * Writes <tt>EntryResource</tt> object onto the given stream.
 *
 * @param <T> entry resource type.
 * @param obj object to be streamed.//from  www .  j a  v a 2s.c o m
 * @param out output stream.
 */
public static <T extends EntryResource> void entry(final T obj, final OutputStream out) {
    entry(obj, new OutputStreamWriter(out));
}

From source file:lapispaste.Main.java

private static void paster(Map<String, String> pastemap, StringBuffer pdata) {
    try {/*from  w  w  w.j  a v  a 2s . c  o  m*/
        URL url = new URL("http://paste.linux-sevenler.org/index.php");
        HttpURLConnection conn = (HttpURLConnection) url.openConnection();

        // set connection 'writeable'
        conn.setDoOutput(true);
        conn.setDoInput(true);
        conn.setRequestMethod("POST");

        // construct the data...
        String data;
        String pdataString = pdata.toString();
        data = URLEncoder.encode("language", "ISO-8859-9") + "="
                + URLEncoder.encode(pastemap.get("format"), "ISO-8859-9");
        data += "&" + URLEncoder.encode("source", "ISO-8859-9") + "="
                + URLEncoder.encode(pdataString, "ISO-8859-9");
        data += "&" + URLEncoder.encode("submit", "ISO-8859-9") + "="
                + URLEncoder.encode(" Kaydet ", "ISO-8859-9");

        OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream());
        wr.write(data);
        wr.flush();

        // get new url where the paste is
        conn.getInputStream();
        System.out.println(conn.getURL());
        conn.disconnect();
    } catch (IOException ex) {
        ex.printStackTrace();
    }
}

From source file:com.silverpeas.export.ExportDescriptor.java

/**
 * Creates and initializes a new descriptor on an export process with the specified output stream.
 * The writer is initialized with the specified output stream.
 * @param outputStream the output stream to use for exporting the serializable resources.
 * @return an export descriptor.//w ww .ja  v  a 2  s . co  m
 */
public static ExportDescriptor withOutputStream(final OutputStream outputStream) {
    ExportDescriptor descriptor = new ExportDescriptor();
    if (outputStream == null) {
        throw new IllegalArgumentException("The output stream cannot be null!");
    }
    descriptor.setOutputStream(outputStream);
    descriptor.setWriter(new OutputStreamWriter(outputStream));
    return descriptor;
}

From source file:de.undercouch.gradle.tasks.download.CompressionTest.java

@Override
protected Handler[] makeHandlers() throws IOException {
    ContextHandler compressionHandler = new ContextHandler("/" + COMPRESSED) {
        @Override/*  w  w w.ja v  a  2  s  .  c  om*/
        public void handle(String target, HttpServletRequest request, HttpServletResponse response,
                int dispatch) throws IOException, ServletException {
            String acceptEncoding = request.getHeader("Accept-Encoding");
            boolean acceptGzip = "gzip".equals(acceptEncoding);

            response.setStatus(200);
            OutputStream os = response.getOutputStream();
            if (acceptGzip) {
                response.setHeader("Content-Encoding", "gzip");
                GZIPOutputStream gos = new GZIPOutputStream(os);
                OutputStreamWriter osw = new OutputStreamWriter(gos);
                osw.write("Compressed");
                osw.close();
                gos.flush();
                gos.close();
            } else {
                OutputStreamWriter osw = new OutputStreamWriter(os);
                osw.write("Uncompressed");
                osw.close();
            }
            os.close();
        }
    };
    return new Handler[] { compressionHandler };
}

From source file:de.instantouch.model.io.SnakeJSONWriter.java

public SnakeJSONWriter(OutputStream output) {
    writer = new OutputStreamWriter(output);
    printWriter = new PrintWriter(writer);
}

From source file:com.enioka.jqm.tools.MulticastPrintStream.java

MulticastPrintStream(OutputStream out, String rootLogDir) {
    super(out);//  w w w  .j  a va2  s  .  c om
    this.original = new BufferedWriter(new OutputStreamWriter(out));
    this.rootLogDir = rootLogDir;

    File d = new File(this.rootLogDir);
    if (!d.isDirectory() && !d.mkdir()) {
        throw new JqmInitError("could not create log dir " + this.rootLogDir);
    }
}

From source file:com.norconex.jefmon.ws.JobSuiteProgressJsonPage.java

@Override
public void renderPage() {
    JEFMonConfig monitorConfig = ((JEFMonSession) getSession()).getConfig();
    if (monitorConfig == null) {
        return;//from  w w  w  .  ja  va2  s . c  om
    }
    try {
        Response response = getRequestCycle().getResponse();
        OutputStreamWriter out = new OutputStreamWriter(response.getOutputStream());

        InstanceSummary instance = InstancesManager.createThisJefMonInstance();
        JSONWriter writer = new JSONWriter(out).object().key("name").value(instance.getName()).key("total")
                .value(instance.getTotalRoots()).key("statuses").object();
        for (JobState status : instance.getStatuses().keySet()) {
            MutableInt value = instance.getStatuses().get(status);
            if (status == null) {
                writer.key("").value(value);
            } else {
                writer.key(status.toString()).value(value);
            }
        }
        writer.endObject();
        writer.endObject();
        out.flush();
    } catch (IOException e) {
        throw new WicketRuntimeException("Cannot flush JSON response.", e);
    } catch (JSONException e) {
        throw new WicketRuntimeException("Cannot create JSON response.", e);
    }
}

From source file:LoginClient.java

private void runServer() {
    while (true) {
        try {/*from   w  w  w .j a  v a2 s  . co  m*/
            System.err.println("Waiting for connection...");
            SSLSocket socket = (SSLSocket) serverSocket.accept();
            BufferedReader input = new BufferedReader(new InputStreamReader(socket.getInputStream()));
            PrintWriter output = new PrintWriter(new OutputStreamWriter(socket.getOutputStream()));
            String userName = input.readLine();
            String password = input.readLine();

            if (userName.equals(CORRECT_USER_NAME) && password.equals(CORRECT_PASSWORD)) {
                output.println("Welcome, " + userName);
            } else {
                output.println("Login Failed.");
            }
            output.close();
            input.close();
            socket.close();

        } catch (IOException ioException) {
            ioException.printStackTrace();
        }
    }
}

From source file:com.yahoo.glimmer.util.BySubjectRecordTest.java

@Before
public void before() {
    byteArrayOutputStream.reset();// w  w  w . j  a va 2 s. c  o m
    writer = new OutputStreamWriter(byteArrayOutputStream);
    record = new BySubjectRecord();
}