Example usage for java.util.zip GZIPOutputStream GZIPOutputStream

List of usage examples for java.util.zip GZIPOutputStream GZIPOutputStream

Introduction

In this page you can find the example usage for java.util.zip GZIPOutputStream GZIPOutputStream.

Prototype

public GZIPOutputStream(OutputStream out, boolean syncFlush) throws IOException 

Source Link

Document

Creates a new output stream with a default buffer size and the specified flush mode.

Usage

From source file:com.nebhale.cyclinglibrary.web.GzipFilterTest.java

private byte[] gzipContent(String content) throws IOException {
    ByteArrayOutputStream bytes = new ByteArrayOutputStream();

    InputStream in = null;//w w w . j ava  2s . c o  m
    OutputStream out = null;

    try {
        in = new ByteArrayInputStream(content.getBytes("UTF-8"));

        out = new GZIPOutputStream(bytes, true);

        copy(in, out);
    } finally {
        closeQuietly(in, out);
    }

    return bytes.toByteArray();
}

From source file:io.ecarf.core.compress.NTripleGzipProcessor.java

/**
 * Reads the input file, gunziped if needed, calls the callback to process
 * each line that being read then writes the file back to a gziped output file
 * @param callback//w  w  w. jav a 2 s . c o  m
 * @throws IOException 
 */
public String process(NTripleGzipCallback callback) throws IOException {

    try (BufferedReader deflated = new BufferedReader(
            new InputStreamReader(this.getDeflatedStream(new FileInputStream(this.inputFile))),
            Constants.GZIP_BUF_SIZE);) {

        try (//BufferedReader bf = new BufferedReader(new InputStreamReader(deflated, Constants.UTF8));
                PrintWriter writer = new PrintWriter(new BufferedOutputStream(
                        new GZIPOutputStream(new FileOutputStream(this.outputFile), Constants.GZIP_BUF_SIZE),
                        Constants.GZIP_BUF_SIZE));) {

            String outLine;

            callback.setOutput(writer);

            NxParser nxp = new NxParser(deflated);

            while (nxp.hasNext()) {

                Node[] ns = nxp.next();

                //We are only interested in triples, no quads
                if (ns.length == 3) {

                    outLine = callback.process(ns);
                    if (outLine != null) {
                        writer.println(outLine);
                    }

                } else {
                    log.warn("Ignoring line: " + ns);
                }
            }

        }

        return this.outputFile;
    }
}

From source file:io.ecarf.core.cloud.task.processor.reason.phase2.ReasonUtils.java

/**
 * //from  w w w.  ja v  a2  s . co  m
 * @param file
 * @param writer
 * @param compressed
 * @return
 * @throws IOException 
 */
public static int reason(String inFile, String outFile, boolean compressed, Map<Long, Set<Triple>> schemaTerms,
        Set<Long> productiveTerms, DuplicatesBuster duplicatesBuster) throws IOException {

    log.info("Reasoning for file: " + inFile + ", memory usage: " + Utils.getMemoryUsageInGB() + "GB");

    int inferredTriples = 0;

    // loop through the instance triples probably stored in a file and generate all the triples matching the schema triples set
    try (BufferedReader reader = getQueryResultsReader(inFile, compressed);
            PrintWriter writer = new PrintWriter(new BufferedOutputStream(
                    new GZIPOutputStream(new FileOutputStream(outFile), Constants.GZIP_BUF_SIZE),
                    Constants.GZIP_BUF_SIZE));) {

        Iterable<CSVRecord> records;

        if (compressed) {
            // ignore first row subject,predicate,object
            records = CSVFormat.DEFAULT.withHeader().withSkipHeaderRecord().parse(reader);

        } else {
            records = CSVFormat.DEFAULT.parse(reader);
        }

        Long term;

        for (CSVRecord record : records) {

            ETriple instanceTriple = ETriple.fromCSV(record.values());

            // TODO review for OWL ruleset
            if (SchemaURIType.RDF_TYPE.id == instanceTriple.getPredicate()) {

                term = instanceTriple.getObject(); // object

            } else {

                term = instanceTriple.getPredicate(); // predicate
            }

            Set<Triple> schemaTriples = schemaTerms.get(term);

            if ((schemaTriples != null) && !schemaTriples.isEmpty()) {
                productiveTerms.add(term);

                for (Triple schemaTriple : schemaTriples) {
                    Rule rule = GenericRule.getRule(schemaTriple);
                    Triple inferredTriple = rule.head(schemaTriple, instanceTriple);

                    if ((inferredTriple != null) && !duplicatesBuster.isDuplicate(inferredTriple)) {
                        writer.println(inferredTriple.toCsv());
                        inferredTriples++;
                    }
                }
            }

        }

    }

    return inferredTriples;
}

From source file:jetbrains.exodus.util.CompressBackupUtil.java

/**
 * Compresses the content of source and stores newly created archive in dest.
 * In case source is a directory, it will be compressed recursively.
 *
 * @param source file or folder to be archived. Should exist on method call.
 * @param dest   path to the archive to be created. Should not exist on method call.
 * @throws IOException           in case of any issues with underlying store.
 * @throws FileNotFoundException in case source does not exist.
 *///from w w  w.ja v  a 2 s  .c  om
public static void tar(@NotNull File source, @NotNull File dest) throws IOException {
    if (!source.exists()) {
        throw new IllegalArgumentException("No source file or folder exists: " + source.getAbsolutePath());
    }
    if (dest.exists()) {
        throw new IllegalArgumentException(
                "Destination refers to existing file or folder: " + dest.getAbsolutePath());
    }

    TarArchiveOutputStream tarOut = null;
    try {
        tarOut = new TarArchiveOutputStream(
                new GZIPOutputStream(new BufferedOutputStream(new FileOutputStream(dest)), 0x1000));
        doTar("", source, tarOut);
        tarOut.close();
    } catch (IOException e) {
        cleanUp(tarOut, dest); // operation filed, let's remove the destination archive
        throw e;
    }
}

From source file:cn.com.loopj.android.http.JsonStreamerEntity.java

@Override
public void writeTo(final OutputStream out) throws IOException {
    if (out == null) {
        throw new IllegalStateException("Output stream cannot be null.");
    }/* w  ww .ja v  a  2s  .  co  m*/

    // Record the time when uploading started.
    long now = System.currentTimeMillis();

    // Use GZIP compression when sending streams, otherwise just use
    // a buffered output stream to speed things up a bit.
    OutputStream os = contentEncoding != null ? new GZIPOutputStream(out, BUFFER_SIZE) : out;

    // Always send a JSON object.
    os.write('{');

    // Keys used by the HashMaps.
    Set<String> keys = jsonParams.keySet();

    int keysCount = keys.size();
    if (0 < keysCount) {
        int keysProcessed = 0;
        boolean isFileWrapper;

        // Go over all keys and handle each's value.
        for (String key : keys) {
            // Indicate that this key has been processed.
            keysProcessed++;

            try {
                // Evaluate the value (which cannot be null).
                Object value = jsonParams.get(key);

                // Write the JSON object's key.
                os.write(escape(key));
                os.write(':');

                // Bail out prematurely if value's null.
                if (value == null) {
                    os.write(JSON_NULL);
                } else {
                    // Check if this is a FileWrapper.
                    isFileWrapper = value instanceof RequestParams.FileWrapper;

                    // If a file should be uploaded.
                    if (isFileWrapper || value instanceof RequestParams.StreamWrapper) {
                        // All uploads are sent as an object containing the file's details.
                        os.write('{');

                        // Determine how to handle this entry.
                        if (isFileWrapper) {
                            writeToFromFile(os, (RequestParams.FileWrapper) value);
                        } else {
                            writeToFromStream(os, (RequestParams.StreamWrapper) value);
                        }

                        // End the file's object and prepare for next one.
                        os.write('}');
                    } else if (value instanceof JsonValueInterface) {
                        os.write(((JsonValueInterface) value).getEscapedJsonValue());
                    } else if (value instanceof org.json.JSONObject) {
                        os.write(value.toString().getBytes());
                    } else if (value instanceof org.json.JSONArray) {
                        os.write(value.toString().getBytes());
                    } else if (value instanceof Boolean) {
                        os.write((Boolean) value ? JSON_TRUE : JSON_FALSE);
                    } else if (value instanceof Long) {
                        os.write((((Number) value).longValue() + "").getBytes());
                    } else if (value instanceof Double) {
                        os.write((((Number) value).doubleValue() + "").getBytes());
                    } else if (value instanceof Float) {
                        os.write((((Number) value).floatValue() + "").getBytes());
                    } else if (value instanceof Integer) {
                        os.write((((Number) value).intValue() + "").getBytes());
                    } else {
                        os.write(escape(value.toString()));
                    }
                }
            } finally {
                // Separate each K:V with a comma, except the last one.
                if (elapsedField != null || keysProcessed < keysCount) {
                    os.write(',');
                }
            }
        }

        // Calculate how many milliseconds it took to upload the contents.
        long elapsedTime = System.currentTimeMillis() - now;

        // Include the elapsed time taken to upload everything.
        // This might be useful for somebody, but it serves us well since
        // there will almost always be a ',' as the last sent character.
        if (elapsedField != null) {
            os.write(elapsedField);
            os.write(':');
            os.write((elapsedTime + "").getBytes());
        }

        AsyncHttpClient.log.i(LOG_TAG, "Uploaded JSON in " + Math.floor(elapsedTime / 1000) + " seconds");
    }

    // Close the JSON object.
    os.write('}');

    // Flush the contents up the stream.
    os.flush();
    AsyncHttpClient.silentCloseOutputStream(os);
}

From source file:com.zftlive.android.library.third.asynchttp.JsonStreamerEntity.java

@Override
public void writeTo(final OutputStream out) throws IOException {
    if (out == null) {
        throw new IllegalStateException("Output stream cannot be null.");
    }//from ww w  .ja  v  a2 s  .co m

    // Record the time when uploading started.
    long now = System.currentTimeMillis();

    // Use GZIP compression when sending streams, otherwise just use
    // a buffered output stream to speed things up a bit.
    OutputStream os = contentEncoding != null ? new GZIPOutputStream(out, BUFFER_SIZE) : out;

    // Always send a JSON object.
    os.write('{');

    // Keys used by the HashMaps.
    Set<String> keys = jsonParams.keySet();

    int keysCount = keys.size();
    if (0 < keysCount) {
        int keysProcessed = 0;
        boolean isFileWrapper;

        // Go over all keys and handle each's value.
        for (String key : keys) {
            // Indicate that this key has been processed.
            keysProcessed++;

            try {
                // Evaluate the value (which cannot be null).
                Object value = jsonParams.get(key);

                // Write the JSON object's key.
                os.write(escape(key));
                os.write(':');

                // Bail out prematurely if value's null.
                if (value == null) {
                    os.write(JSON_NULL);
                } else {
                    // Check if this is a FileWrapper.
                    isFileWrapper = value instanceof RequestParams.FileWrapper;

                    // If a file should be uploaded.
                    if (isFileWrapper || value instanceof RequestParams.StreamWrapper) {
                        // All uploads are sent as an object containing the file's details.
                        os.write('{');

                        // Determine how to handle this entry.
                        if (isFileWrapper) {
                            writeToFromFile(os, (RequestParams.FileWrapper) value);
                        } else {
                            writeToFromStream(os, (RequestParams.StreamWrapper) value);
                        }

                        // End the file's object and prepare for next one.
                        os.write('}');
                    } else if (value instanceof JsonValueInterface) {
                        os.write(((JsonValueInterface) value).getEscapedJsonValue());
                    } else if (value instanceof org.json.JSONObject) {
                        os.write(value.toString().getBytes());
                    } else if (value instanceof org.json.JSONArray) {
                        os.write(value.toString().getBytes());
                    } else if (value instanceof Boolean) {
                        os.write((Boolean) value ? JSON_TRUE : JSON_FALSE);
                    } else if (value instanceof Long) {
                        os.write((((Number) value).longValue() + "").getBytes());
                    } else if (value instanceof Double) {
                        os.write((((Number) value).doubleValue() + "").getBytes());
                    } else if (value instanceof Float) {
                        os.write((((Number) value).floatValue() + "").getBytes());
                    } else if (value instanceof Integer) {
                        os.write((((Number) value).intValue() + "").getBytes());
                    } else {
                        os.write(escape(value.toString()));
                    }
                }
            } finally {
                // Separate each K:V with a comma, except the last one.
                if (elapsedField != null || keysProcessed < keysCount) {
                    os.write(',');
                }
            }
        }

        // Calculate how many milliseconds it took to upload the contents.
        long elapsedTime = System.currentTimeMillis() - now;

        // Include the elapsed time taken to upload everything.
        // This might be useful for somebody, but it serves us well since
        // there will almost always be a ',' as the last sent character.
        if (elapsedField != null) {
            os.write(elapsedField);
            os.write(':');
            os.write((elapsedTime + "").getBytes());
        }

        Log.i(LOG_TAG, "Uploaded JSON in " + Math.floor(elapsedTime / 1000) + " seconds");
    }

    // Close the JSON object.
    os.write('}');

    // Flush the contents up the stream.
    os.flush();
    AsyncHttpClient.silentCloseOutputStream(os);
}

From source file:com.example.pierre.applicompanies.library_http.JsonStreamerEntity.java

@Override
public void writeTo(final OutputStream out) throws IOException {
    if (out == null) {
        throw new IllegalStateException("Output stream cannot be null.");
    }//from   w w  w . j a v  a 2 s . c  o  m

    // Record the time when uploading started.
    long now = System.currentTimeMillis();

    // Use GZIP compression when sending streams, otherwise just use
    // a buffered output stream to speed things up a bit.
    OutputStream os = contentEncoding != null ? new GZIPOutputStream(out, BUFFER_SIZE) : out;

    // Always send a JSON object.
    os.write('{');

    // Keys used by the HashMaps.
    Set<String> keys = jsonParams.keySet();

    int keysCount = keys.size();
    if (0 < keysCount) {
        int keysProcessed = 0;
        boolean isFileWrapper;

        // Go over all keys and handle each's value.
        for (String key : keys) {
            // Indicate that this key has been processed.
            keysProcessed++;

            try {
                // Evaluate the value (which cannot be null).
                Object value = jsonParams.get(key);

                // Write the JSON object's key.
                os.write(escape(key));
                os.write(':');

                // Bail out prematurely if value's null.
                if (value == null) {
                    os.write(JSON_NULL);
                } else {
                    // Check if this is a FileWrapper.
                    isFileWrapper = value instanceof RequestParams.FileWrapper;

                    // If a file should be uploaded.
                    if (isFileWrapper || value instanceof RequestParams.StreamWrapper) {
                        // All uploads are sent as an object containing the file's details.
                        os.write('{');

                        // Determine how to handle this entry.
                        if (isFileWrapper) {
                            writeToFromFile(os, (RequestParams.FileWrapper) value);
                        } else {
                            writeToFromStream(os, (RequestParams.StreamWrapper) value);
                        }

                        // End the file's object and prepare for next one.
                        os.write('}');
                    } else if (value instanceof JsonValueInterface) {
                        os.write(((JsonValueInterface) value).getEscapedJsonValue());
                    } else if (value instanceof org.json.JSONObject) {
                        os.write(((org.json.JSONObject) value).toString().getBytes());
                    } else if (value instanceof org.json.JSONArray) {
                        os.write(((org.json.JSONArray) value).toString().getBytes());
                    } else if (value instanceof Boolean) {
                        os.write((Boolean) value ? JSON_TRUE : JSON_FALSE);
                    } else if (value instanceof Long) {
                        os.write((((Number) value).longValue() + "").getBytes());
                    } else if (value instanceof Double) {
                        os.write((((Number) value).doubleValue() + "").getBytes());
                    } else if (value instanceof Float) {
                        os.write((((Number) value).floatValue() + "").getBytes());
                    } else if (value instanceof Integer) {
                        os.write((((Number) value).intValue() + "").getBytes());
                    } else {
                        os.write(escape(value.toString()));
                    }
                }
            } finally {
                // Separate each K:V with a comma, except the last one.
                if (elapsedField != null || keysProcessed < keysCount) {
                    os.write(',');
                }
            }
        }

        // Calculate how many milliseconds it took to upload the contents.
        long elapsedTime = System.currentTimeMillis() - now;

        // Include the elapsed time taken to upload everything.
        // This might be useful for somebody, but it serves us well since
        // there will almost always be a ',' as the last sent character.
        if (elapsedField != null) {
            os.write(elapsedField);
            os.write(':');
            os.write((elapsedTime + "").getBytes());
        }

        Log.i(LOG_TAG, "Uploaded JSON in " + Math.floor(elapsedTime / 1000) + " seconds");
    }

    // Close the JSON object.
    os.write('}');

    // Flush the contents up the stream.
    os.flush();
    AsyncHttpClient.silentCloseOutputStream(os);
}

From source file:com.yunmall.ymsdk.net.http.JsonStreamerEntity.java

@Override
public void writeTo(final OutputStream out) throws IOException {
    if (out == null) {
        throw new IllegalStateException("Output stream cannot be null.");
    }/*from   w w w  .  jav a  2s  . co m*/

    // Record the time when uploading started.
    long now = System.currentTimeMillis();

    // Use GZIP compression when sending streams, otherwise just use
    // a buffered output stream to speed things up a bit.
    OutputStream os = null != contentEncoding ? new GZIPOutputStream(out, BUFFER_SIZE) : out;

    // Always send a JSON object.
    os.write('{');

    // Keys used by the HashMaps.
    Set<String> keys = jsonParams.keySet();

    boolean isFileWrapper;

    // Go over all keys and handle each's value.
    for (String key : keys) {
        // Evaluate the value (which cannot be null).
        Object value = jsonParams.get(key);

        // Bail out prematurely if value's null.
        if (value == null) {
            continue;
        }

        // Write the JSON object's key.
        os.write(escape(key));
        os.write(':');

        // Check if this is a FileWrapper.
        isFileWrapper = value instanceof RequestParams.FileWrapper;

        // If a file should be uploaded.
        if (isFileWrapper || value instanceof RequestParams.StreamWrapper) {
            // All uploads are sent as an object containing the file's details.
            os.write('{');

            // Determine how to handle this entry.
            if (isFileWrapper) {
                writeToFromFile(os, (RequestParams.FileWrapper) value);
            } else {
                writeToFromStream(os, (RequestParams.StreamWrapper) value);
            }

            // End the file's object and prepare for next one.
            os.write('}');
        } else if (value instanceof Boolean) {
            os.write((Boolean) value ? JSON_TRUE : JSON_FALSE);
        } else if (value instanceof Long) {
            os.write((((Number) value).longValue() + "").getBytes());
        } else if (value instanceof Double) {
            os.write((((Number) value).doubleValue() + "").getBytes());
        } else if (value instanceof Float) {
            os.write((((Number) value).floatValue() + "").getBytes());
        } else if (value instanceof Integer) {
            os.write((((Number) value).intValue() + "").getBytes());
        } else {
            os.write(escape(value.toString()));
        }

        os.write(',');
    }

    // Include the elapsed time taken to upload everything.
    // This might be useful for somebody, but it serves us well since
    // there will almost always be a ',' as the last sent character.
    os.write(STREAM_ELAPSED);
    os.write(':');
    long elapsedTime = System.currentTimeMillis() - now;
    os.write((elapsedTime + "}").getBytes());

    YmLog.i(LOG_TAG, "Uploaded JSON in " + Math.floor(elapsedTime / 1000) + " seconds");

    // Flush the contents up the stream.
    os.flush();
    AsyncHttpClient.silentCloseOutputStream(os);
}

From source file:com.amytech.android.library.utils.asynchttp.JsonStreamerEntity.java

@Override
public void writeTo(final OutputStream out) throws IOException {
    if (out == null) {
        throw new IllegalStateException("Output stream cannot be null.");
    }//from w  w w.j  a  va  2s .c  o m

    // Record the time when uploading started.
    long now = System.currentTimeMillis();

    // Use GZIP compression when sending streams, otherwise just use
    // a buffered output stream to speed things up a bit.
    OutputStream os = contentEncoding != null ? new GZIPOutputStream(out, BUFFER_SIZE) : out;

    // Always send a JSON object.
    os.write('{');

    // Keys used by the HashMaps.
    Set<String> keys = jsonParams.keySet();

    int keysCount = keys.size();
    if (0 < keysCount) {
        int keysProcessed = 0;
        boolean isFileWrapper;

        // Go over all keys and handle each's value.
        for (String key : keys) {
            // Indicate that this key has been processed.
            keysProcessed++;

            try {
                // Evaluate the value (which cannot be null).
                Object value = jsonParams.get(key);

                // Write the JSON object's key.
                os.write(escape(key));
                os.write(':');

                // Bail out prematurely if value's null.
                if (value == null) {
                    os.write(JSON_NULL);
                } else {
                    // Check if this is a FileWrapper.
                    isFileWrapper = value instanceof RequestParams.FileWrapper;

                    // If a file should be uploaded.
                    if (isFileWrapper || value instanceof RequestParams.StreamWrapper) {
                        // All uploads are sent as an object containing the
                        // file's details.
                        os.write('{');

                        // Determine how to handle this entry.
                        if (isFileWrapper) {
                            writeToFromFile(os, (RequestParams.FileWrapper) value);
                        } else {
                            writeToFromStream(os, (RequestParams.StreamWrapper) value);
                        }

                        // End the file's object and prepare for next one.
                        os.write('}');
                    } else if (value instanceof JsonValueInterface) {
                        os.write(((JsonValueInterface) value).getEscapedJsonValue());
                    } else if (value instanceof org.json.JSONObject) {
                        os.write(value.toString().getBytes());
                    } else if (value instanceof org.json.JSONArray) {
                        os.write(value.toString().getBytes());
                    } else if (value instanceof Boolean) {
                        os.write((Boolean) value ? JSON_TRUE : JSON_FALSE);
                    } else if (value instanceof Long) {
                        os.write((((Number) value).longValue() + "").getBytes());
                    } else if (value instanceof Double) {
                        os.write((((Number) value).doubleValue() + "").getBytes());
                    } else if (value instanceof Float) {
                        os.write((((Number) value).floatValue() + "").getBytes());
                    } else if (value instanceof Integer) {
                        os.write((((Number) value).intValue() + "").getBytes());
                    } else {
                        os.write(escape(value.toString()));
                    }
                }
            } finally {
                // Separate each K:V with a comma, except the last one.
                if (elapsedField != null || keysProcessed < keysCount) {
                    os.write(',');
                }
            }
        }

        // Calculate how many milliseconds it took to upload the contents.
        long elapsedTime = System.currentTimeMillis() - now;

        // Include the elapsed time taken to upload everything.
        // This might be useful for somebody, but it serves us well since
        // there will almost always be a ',' as the last sent character.
        if (elapsedField != null) {
            os.write(elapsedField);
            os.write(':');
            os.write((elapsedTime + "").getBytes());
        }

        Log.i(LOG_TAG, "Uploaded JSON in " + Math.floor(elapsedTime / 1000) + " seconds");
    }

    // Close the JSON object.
    os.write('}');

    // Flush the contents up the stream.
    os.flush();
    AsyncHttpClient.silentCloseOutputStream(os);
}

From source file:com.android.yijiang.kzx.http.JsonStreamerEntity.java

@Override
public void writeTo(final OutputStream out) throws IOException {
    if (out == null) {
        throw new IllegalStateException("Output stream cannot be null.");
    }/*from   w  w  w .j ava2s .c  o m*/

    // Record the time when uploading started.
    long now = System.currentTimeMillis();

    // Use GZIP compression when sending streams, otherwise just use
    // a buffered output stream to speed things up a bit.
    OutputStream os = null != contentEncoding ? new GZIPOutputStream(out, BUFFER_SIZE) : out;

    // Always send a JSON object.
    os.write('{');

    // Keys used by the HashMaps.
    Set<String> keys = jsonParams.keySet();

    boolean isFileWrapper;

    // Go over all keys and handle each's value.
    for (String key : keys) {
        // Evaluate the value (which cannot be null).
        Object value = jsonParams.get(key);

        // Bail out prematurely if value's null.
        if (value == null) {
            continue;
        }

        // Write the JSON object's key.
        os.write(escape(key));
        os.write(':');

        // Check if this is a FileWrapper.
        isFileWrapper = value instanceof RequestParams.FileWrapper;

        // If a file should be uploaded.
        if (isFileWrapper || value instanceof RequestParams.StreamWrapper) {
            // All uploads are sent as an object containing the file's details.
            os.write('{');

            // Determine how to handle this entry.
            if (isFileWrapper) {
                writeToFromFile(os, (RequestParams.FileWrapper) value);
            } else {
                writeToFromStream(os, (RequestParams.StreamWrapper) value);
            }

            // End the file's object and prepare for next one.
            os.write('}');
        } else if (value instanceof Boolean) {
            os.write((Boolean) value ? JSON_TRUE : JSON_FALSE);
        } else if (value instanceof Long) {
            os.write((((Number) value).longValue() + "").getBytes());
        } else if (value instanceof Double) {
            os.write((((Number) value).doubleValue() + "").getBytes());
        } else if (value instanceof Float) {
            os.write((((Number) value).floatValue() + "").getBytes());
        } else if (value instanceof Integer) {
            os.write((((Number) value).intValue() + "").getBytes());
        } else {
            os.write(value.toString().getBytes());
        }

        os.write(',');
    }

    // Include the elapsed time taken to upload everything.
    // This might be useful for somebody, but it serves us well since
    // there will almost always be a ',' as the last sent character.
    os.write(STREAM_ELAPSED);
    os.write(':');
    long elapsedTime = System.currentTimeMillis() - now;
    os.write((elapsedTime + "}").getBytes());

    Log.i(LOG_TAG, "Uploaded JSON in " + Math.floor(elapsedTime / 1000) + " seconds");

    // Flush the contents up the stream.
    os.flush();
    AsyncHttpClient.silentCloseOutputStream(os);
}