Search in sources :

Example 96 with GZIPOutputStream

use of java.util.zip.GZIPOutputStream in project bnd by bndtools.

the class Httpbin method _gzip.

public void _gzip(Request req, Response rsp) throws IOException {
    ByteArrayOutputStream bout = new ByteArrayOutputStream();
    GZIPOutputStream gzout = new GZIPOutputStream(bout);
    getResource(rsp, "utf8.html", "text/html;charset=utf8");
    gzout.write(rsp.content);
    gzout.close();
    rsp.content = bout.toByteArray();
    rsp.length = rsp.content.length;
    rsp.headers.put("Content-Encoding", "gzip");
}
Also used : GZIPOutputStream(java.util.zip.GZIPOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 97 with GZIPOutputStream

use of java.util.zip.GZIPOutputStream in project geode by apache.

the class OSProcess method zipStacks.

/** dumps this vm's stacks and returns gzipped result */
public static byte[] zipStacks() throws IOException {
    ThreadMXBean bean = ManagementFactory.getThreadMXBean();
    long[] threadIds = bean.getAllThreadIds();
    ThreadInfo[] infos = bean.getThreadInfo(threadIds, true, true);
    long thisThread = Thread.currentThread().getId();
    ByteArrayOutputStream baos = new ByteArrayOutputStream(10000);
    GZIPOutputStream zipOut = new GZIPOutputStream(baos, 10000);
    PrintWriter pw = new PrintWriter(zipOut, true);
    for (int i = 0; i < infos.length; i++) {
        if (i != thisThread && infos[i] != null) {
            formatThreadInfo(infos[i], pw);
        }
    }
    pw.flush();
    zipOut.close();
    byte[] result = baos.toByteArray();
    return result;
}
Also used : GZIPOutputStream(java.util.zip.GZIPOutputStream)

Example 98 with GZIPOutputStream

use of java.util.zip.GZIPOutputStream in project dhis2-core by dhis2.

the class EventController method getCsvEvents.

@RequestMapping(value = "", method = RequestMethod.GET, produces = { "application/csv", "application/csv+gzip", "text/csv" })
@PreAuthorize("hasRole('ALL') or hasRole('F_TRACKED_ENTITY_DATAVALUE_ADD') or hasRole('F_TRACKED_ENTITY_DATAVALUE_READ')")
public void getCsvEvents(@RequestParam(required = false) String program, @RequestParam(required = false) String programStage, @RequestParam(required = false) ProgramStatus programStatus, @RequestParam(required = false) Boolean followUp, @RequestParam(required = false) String trackedEntityInstance, @RequestParam(required = false) String orgUnit, @RequestParam(required = false) OrganisationUnitSelectionMode ouMode, @RequestParam(required = false) Date startDate, @RequestParam(required = false) Date endDate, @RequestParam(required = false) Date dueDateStart, @RequestParam(required = false) Date dueDateEnd, @RequestParam(required = false) Date lastUpdated, @RequestParam(required = false) Date lastUpdatedStartDate, @RequestParam(required = false) Date lastUpdatedEndDate, @RequestParam(required = false) EventStatus status, @RequestParam(required = false) String attributeCc, @RequestParam(required = false) String attributeCos, @RequestParam(required = false) Integer page, @RequestParam(required = false) Integer pageSize, @RequestParam(required = false) boolean totalPages, @RequestParam(required = false) boolean skipPaging, @RequestParam(required = false) String order, @RequestParam(required = false) String attachment, @RequestParam(required = false, defaultValue = "false") boolean includeDeleted, @RequestParam(required = false, defaultValue = "false") boolean skipHeader, IdSchemes idSchemes, HttpServletResponse response, HttpServletRequest request) throws IOException, WebMessageException {
    boolean allowNoAttrOptionCombo = trackedEntityInstance != null && entityInstanceService.getTrackedEntityInstance(trackedEntityInstance) != null;
    DataElementCategoryOptionCombo attributeOptionCombo = inputUtils.getAttributeOptionCombo(attributeCc, attributeCos, allowNoAttrOptionCombo);
    if (attributeOptionCombo == null && !allowNoAttrOptionCombo) {
        throw new WebMessageException(WebMessageUtils.conflict("Illegal attribute option combo identifier: " + attributeCc + " " + attributeCos));
    }
    lastUpdatedStartDate = lastUpdatedStartDate != null ? lastUpdatedStartDate : lastUpdated;
    EventSearchParams params = eventService.getFromUrl(program, programStage, programStatus, followUp, orgUnit, ouMode, trackedEntityInstance, startDate, endDate, dueDateStart, dueDateEnd, lastUpdatedStartDate, lastUpdatedEndDate, status, attributeOptionCombo, idSchemes, page, pageSize, totalPages, skipPaging, getOrderParams(order), null, false, null, null, null, includeDeleted);
    Events events = eventService.getEvents(params);
    OutputStream outputStream = response.getOutputStream();
    response.setContentType("application/csv");
    if (ContextUtils.isAcceptCsvGzip(request)) {
        response.addHeader(ContextUtils.HEADER_CONTENT_TRANSFER_ENCODING, "binary");
        outputStream = new GZIPOutputStream(outputStream);
        response.setContentType("application/csv+gzip");
    }
    if (!StringUtils.isEmpty(attachment)) {
        response.addHeader("Content-Disposition", "attachment; filename=" + attachment);
    }
    csvEventService.writeEvents(outputStream, events, !skipHeader);
}
Also used : WebMessageException(org.hisp.dhis.dxf2.webmessage.WebMessageException) Events(org.hisp.dhis.dxf2.events.event.Events) GZIPOutputStream(java.util.zip.GZIPOutputStream) EventSearchParams(org.hisp.dhis.dxf2.events.event.EventSearchParams) GZIPOutputStream(java.util.zip.GZIPOutputStream) OutputStream(java.io.OutputStream) DataElementCategoryOptionCombo(org.hisp.dhis.dataelement.DataElementCategoryOptionCombo) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 99 with GZIPOutputStream

use of java.util.zip.GZIPOutputStream in project BKCommonLib by bergerhealer.

the class MCSDWebbingCodec method calculateCompressedSize.

public int calculateCompressedSize() {
    ByteArrayOutputStream bs = new ByteArrayOutputStream();
    try {
        BitOutputStream s = new BitOutputStream(CommonUtil.setCompressionLevel(new GZIPOutputStream(bs), Deflater.BEST_COMPRESSION));
        for (int i = 0; i < this.packets_count; i++) {
            s.writePacket(this.packets[i]);
        }
        s.close();
        return bs.size();
    } catch (IOException ex) {
        ex.printStackTrace();
    }
    return 0;
}
Also used : BitOutputStream(com.bergerkiller.bukkit.common.io.BitOutputStream) GZIPOutputStream(java.util.zip.GZIPOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException)

Example 100 with GZIPOutputStream

use of java.util.zip.GZIPOutputStream in project BKCommonLib by bergerhealer.

the class MCSDFlat method writeTo.

public void writeTo(OutputStream stream) throws IOException {
    Logging.LOGGER_MAPDISPLAY.info("Compressing flat map color space data...");
    GZIPOutputStream zip = new GZIPOutputStream(stream);
    try {
        for (int i = 0; i < 256; i++) {
            Color color = this.getColor((byte) i);
            zip.write(color.getRed());
            zip.write(color.getGreen());
            zip.write(color.getBlue());
            zip.write(color.getAlpha());
        }
        for (int index = 0; index < (1 << 24); index++) {
            zip.write(this.get(index) & 0xFF);
        }
        Logging.LOGGER_MAPDISPLAY.info("Finished compressing map color space data");
    } finally {
        zip.close();
    }
}
Also used : GZIPOutputStream(java.util.zip.GZIPOutputStream) Color(java.awt.Color)

Aggregations

GZIPOutputStream (java.util.zip.GZIPOutputStream)835 ByteArrayOutputStream (java.io.ByteArrayOutputStream)339 IOException (java.io.IOException)254 FileOutputStream (java.io.FileOutputStream)251 OutputStream (java.io.OutputStream)185 File (java.io.File)179 Test (org.junit.Test)93 BufferedOutputStream (java.io.BufferedOutputStream)84 GZIPInputStream (java.util.zip.GZIPInputStream)77 FileInputStream (java.io.FileInputStream)72 InputStream (java.io.InputStream)64 ByteArrayInputStream (java.io.ByteArrayInputStream)60 OutputStreamWriter (java.io.OutputStreamWriter)53 ObjectOutputStream (java.io.ObjectOutputStream)39 DataOutputStream (java.io.DataOutputStream)38 BufferedWriter (java.io.BufferedWriter)30 ByteBuffer (java.nio.ByteBuffer)28 Path (java.nio.file.Path)28 ArrayList (java.util.ArrayList)28 NodeSettings (org.knime.core.node.NodeSettings)28