Search in sources :

Example 66 with OutputStreamWriter

use of java.io.OutputStreamWriter in project camel by apache.

the class CamelSalesforceMojo method processDescription.

void processDescription(File pkgDir, SObjectDescription description, GeneratorUtility utility, String generatedDate) throws IOException {
    // generate a source file for SObject
    final VelocityContext context = new VelocityContext();
    context.put("packageName", packageName);
    context.put("utility", utility);
    context.put("esc", StringEscapeUtils.class);
    context.put("desc", description);
    context.put("generatedDate", generatedDate);
    context.put("useStringsForPicklists", useStringsForPicklists);
    final String pojoFileName = description.getName() + JAVA_EXT;
    final File pojoFile = new File(pkgDir, pojoFileName);
    try (final Writer writer = new OutputStreamWriter(new FileOutputStream(pojoFile), StandardCharsets.UTF_8)) {
        final Template pojoTemplate = engine.getTemplate(SOBJECT_POJO_VM, UTF_8);
        pojoTemplate.merge(context, writer);
    }
    if (useOptionals) {
        final String optionalFileName = description.getName() + "Optional" + JAVA_EXT;
        final File optionalFile = new File(pkgDir, optionalFileName);
        try (final Writer writer = new OutputStreamWriter(new FileOutputStream(optionalFile), StandardCharsets.UTF_8)) {
            final Template optionalTemplate = engine.getTemplate(SOBJECT_POJO_OPTIONAL_VM, UTF_8);
            optionalTemplate.merge(context, writer);
        }
    }
    // write required Enumerations for any picklists
    for (SObjectField field : description.getFields()) {
        if (utility.isPicklist(field) || utility.isMultiSelectPicklist(field)) {
            final String enumName = description.getName() + "_" + utility.enumTypeName(field.getName());
            final String enumFileName = enumName + JAVA_EXT;
            final File enumFile = new File(pkgDir, enumFileName);
            context.put("field", field);
            context.put("enumName", enumName);
            final Template enumTemplate = engine.getTemplate(SOBJECT_PICKLIST_VM, UTF_8);
            try (final Writer writer = new OutputStreamWriter(new FileOutputStream(enumFile), StandardCharsets.UTF_8)) {
                enumTemplate.merge(context, writer);
            }
        }
    }
    // write the QueryRecords class
    final String queryRecordsFileName = "QueryRecords" + description.getName() + JAVA_EXT;
    final File queryRecordsFile = new File(pkgDir, queryRecordsFileName);
    final Template queryTemplate = engine.getTemplate(SOBJECT_QUERY_RECORDS_VM, UTF_8);
    try (final Writer writer = new OutputStreamWriter(new FileOutputStream(queryRecordsFile), StandardCharsets.UTF_8)) {
        queryTemplate.merge(context, writer);
    }
    if (useOptionals) {
        // write the QueryRecords Optional class
        final String queryRecordsOptionalFileName = "QueryRecords" + description.getName() + "Optional" + JAVA_EXT;
        final File queryRecordsOptionalFile = new File(pkgDir, queryRecordsOptionalFileName);
        final Template queryRecordsOptionalTemplate = engine.getTemplate(SOBJECT_QUERY_RECORDS_OPTIONAL_VM, UTF_8);
        try (final Writer writer = new OutputStreamWriter(new FileOutputStream(queryRecordsOptionalFile), StandardCharsets.UTF_8)) {
            queryRecordsOptionalTemplate.merge(context, writer);
        }
    }
}
Also used : SObjectField(org.apache.camel.component.salesforce.api.dto.SObjectField) VelocityContext(org.apache.velocity.VelocityContext) FileOutputStream(java.io.FileOutputStream) OutputStreamWriter(java.io.OutputStreamWriter) File(java.io.File) Writer(java.io.Writer) OutputStreamWriter(java.io.OutputStreamWriter) Template(org.apache.velocity.Template)

Example 67 with OutputStreamWriter

use of java.io.OutputStreamWriter in project storm-json by rapportive-oss.

the class SimpleJSONSerializer method serialize.

/**
     * Serialise a JSON object or array to the stream.
     *
     * @throws IllegalArgumentException  if <tt>object</tt> is not a JSON
     *           object or array
     * @throws IOException  if there is an error writing to the stream.
     */
@Override
public void serialize(Object object, DataOutputStream stream) throws IOException {
    final Writer writer = new OutputStreamWriter(stream, ENCODING);
    if (object instanceof JSONObject) {
        ((JSONObject) object).writeJSONString(writer);
    } else if (object instanceof JSONArray) {
        ((JSONArray) object).writeJSONString(writer);
    } else {
        throw new IllegalArgumentException("Unexpected class " + object.getClass().getCanonicalName());
    }
    writer.flush();
}
Also used : JSONObject(org.json.simple.JSONObject) JSONArray(org.json.simple.JSONArray) OutputStreamWriter(java.io.OutputStreamWriter) Writer(java.io.Writer) OutputStreamWriter(java.io.OutputStreamWriter)

Example 68 with OutputStreamWriter

use of java.io.OutputStreamWriter in project retrofit by square.

the class GsonRequestBodyConverter method convert.

@Override
public RequestBody convert(T value) throws IOException {
    Buffer buffer = new Buffer();
    Writer writer = new OutputStreamWriter(buffer.outputStream(), UTF_8);
    JsonWriter jsonWriter = gson.newJsonWriter(writer);
    adapter.write(jsonWriter, value);
    jsonWriter.close();
    return RequestBody.create(MEDIA_TYPE, buffer.readByteString());
}
Also used : Buffer(okio.Buffer) OutputStreamWriter(java.io.OutputStreamWriter) JsonWriter(com.google.gson.stream.JsonWriter) Writer(java.io.Writer) OutputStreamWriter(java.io.OutputStreamWriter) JsonWriter(com.google.gson.stream.JsonWriter)

Example 69 with OutputStreamWriter

use of java.io.OutputStreamWriter in project flink by apache.

the class CsvOutputFormat method open.

// --------------------------------------------------------------------------------------------
@Override
public void open(int taskNumber, int numTasks) throws IOException {
    super.open(taskNumber, numTasks);
    this.wrt = this.charsetName == null ? new OutputStreamWriter(new BufferedOutputStream(this.stream, 4096)) : new OutputStreamWriter(new BufferedOutputStream(this.stream, 4096), this.charsetName);
}
Also used : OutputStreamWriter(java.io.OutputStreamWriter) BufferedOutputStream(java.io.BufferedOutputStream)

Example 70 with OutputStreamWriter

use of java.io.OutputStreamWriter in project cube-sdk by liaohuqiu.

the class PostRequestSender method send.

@Override
public void send() throws IOException {
    OutputStreamWriter writer = new OutputStreamWriter(mHttpURLConnection.getOutputStream());
    writer.write(mRequestData.getPostString());
    writer.flush();
}
Also used : OutputStreamWriter(java.io.OutputStreamWriter)

Aggregations

OutputStreamWriter (java.io.OutputStreamWriter)1784 IOException (java.io.IOException)690 FileOutputStream (java.io.FileOutputStream)653 BufferedWriter (java.io.BufferedWriter)647 Writer (java.io.Writer)479 File (java.io.File)407 PrintWriter (java.io.PrintWriter)296 InputStreamReader (java.io.InputStreamReader)244 OutputStream (java.io.OutputStream)221 ByteArrayOutputStream (java.io.ByteArrayOutputStream)216 BufferedReader (java.io.BufferedReader)210 Test (org.junit.Test)129 InputStream (java.io.InputStream)112 FileNotFoundException (java.io.FileNotFoundException)104 ArrayList (java.util.ArrayList)96 Path (org.apache.hadoop.fs.Path)93 UnsupportedEncodingException (java.io.UnsupportedEncodingException)92 URL (java.net.URL)90 HttpURLConnection (java.net.HttpURLConnection)78 FileInputStream (java.io.FileInputStream)71