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");
}
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;
}
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);
}
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;
}
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();
}
}
Aggregations