@Override public void startCompression() { compressed = true; try { if (tlsStreamHandler == null) { ZOutputStream out = new ZOutputStream( ServerTrafficCounter.wrapOutputStream(socket.getOutputStream()), JZlib.Z_BEST_COMPRESSION); out.setFlushMode(JZlib.Z_PARTIAL_FLUSH); writer = new BufferedWriter(new OutputStreamWriter(out, StandardCharsets.UTF_8)); xmlSerializer = new XMLSocketWriter(writer, this); } else { ZOutputStream out = new ZOutputStream(tlsStreamHandler.getOutputStream(), JZlib.Z_BEST_COMPRESSION); out.setFlushMode(JZlib.Z_PARTIAL_FLUSH); writer = new BufferedWriter(new OutputStreamWriter(out, StandardCharsets.UTF_8)); xmlSerializer = new XMLSocketWriter(writer, this); } } catch (IOException e) { // TODO Would be nice to still be able to throw the exception and not catch it here Log.error("Error while starting compression", e); compressed = false; } }
if (getFlags() == COMPRESS_FLAG) { ByteArrayOutputStream out2 = new ByteArrayOutputStream(); zout = new ZOutputStream(out2, JZlib.Z_DEFAULT_COMPRESSION); zout.write(out1.toByteArray()); zout.flush(); zout.end(); bytes = out2.toByteArray(); } else { if (zout != null) { try { zout.close(); } catch (IOException e) {} zout = null;
public void write(int b) throws IOException { buf1[0]=(byte)b; write(buf1, 0, 1); }
@RequestMapping(value = "/download", method = RequestMethod.POST) @ResponseStatus(HttpStatus.OK) public void downloadHandler(HttpServletRequest request, HttpServletResponse response) throws IOException { ZOutputStream zOutput = new ZOutputStream(response.getOutputStream(), JZlib.Z_BEST_COMPRESSION); DataInputStream dataInput = new DataInputStream(request.getInputStream()); DataOutputStream dataOutput = new DataOutputStream(zOutput); try { readParameters(dataInput); byte action = readActionByte(dataInput); ByteArrayOutputStream byteStream = new ByteArrayOutputStream(); if (action == ACTION_DOWNLOAD_STUDY_LIST) { handleDownloadStudies(byteStream); } else if (action == ACTION_DOWNLOAD_USERS_AND_FORMS) { handleDownloadUsersAndForms(byteStream, dataInput); } dataOutput.writeByte(RESPONSE_SUCCESS); dataOutput.write(byteStream.toByteArray()); log.info("successfully downloaded the xforms"); } catch (Exception e) { dataOutput.writeByte(RESPONSE_ERROR); throw new SerializationFailedException(FAILED_TO_SERIALIZE_DATA, e); } finally { dataOutput.close(); response.flushBuffer(); } }
public void finish() throws IOException { int err; do{ z.next_out=buf; z.next_out_index=0; z.avail_out=bufsize; if(compress){ err=z.deflate(JZlib.Z_FINISH); } else{ err=z.inflate(JZlib.Z_FINISH); } if(err!=JZlib.Z_STREAM_END && err != JZlib.Z_OK) throw new ZStreamException((compress?"de":"in")+"flating: "+z.msg); if(bufsize-z.avail_out>0){ out.write(buf, 0, bufsize-z.avail_out); } } while(z.avail_in>0 || z.avail_out==0); flush(); } public void end() {
protected void sendBufferNow() throws java.io.IOException { if (sockBuf.position() == 0) return; sockBuf.flip(); if (zout != null) { zout.write(sockBuf.array(), 0, sockBuf.limit()); zout.flush(); } else { while (clientSocket != null && sockBuf.hasRemaining()) clientSocket.write(sockBuf); } sockBuf.clear(); }
public void write(int b) throws IOException { buf1[0]=(byte)b; write(buf1, 0, 1); }
@RequestMapping(value = "/upload", method = RequestMethod.POST) @ResponseStatus(HttpStatus.OK) public void uploadHandler(HttpServletRequest request, HttpServletResponse response) throws IOException { ZOutputStream zOutput = new ZOutputStream(response.getOutputStream(), JZlib.Z_BEST_COMPRESSION); DataInputStream dataInput = new DataInputStream(request.getInputStream()); DataOutputStream dataOutput = new DataOutputStream(zOutput);
public void finish() throws IOException { int err; do{ z.next_out=buf; z.next_out_index=0; z.avail_out=bufsize; if(compress){ err=z.deflate(JZlib.Z_FINISH); } else{ err=z.inflate(JZlib.Z_FINISH); } if(err!=JZlib.Z_STREAM_END && err != JZlib.Z_OK) throw new ZStreamException((compress?"de":"in")+"flating: "+z.msg); if(bufsize-z.avail_out>0){ out.write(buf, 0, bufsize-z.avail_out); } } while(z.avail_in>0 || z.avail_out==0); flush(); } public void end() {
private void enableCompression(Socket socket) throws IOException { InputStream inputStream = new InflaterInputStream(socket.getInputStream(), new Inflater(true)); input = Okio.buffer(Okio.source(inputStream)); ZOutputStream outputStream = new ZOutputStream(socket.getOutputStream(), JZlib.Z_BEST_SPEED, true); outputStream.setFlushMode(JZlib.Z_PARTIAL_FLUSH); output = Okio.buffer(Okio.sink(outputStream)); }
public void write(int b) throws IOException { buf1[0]=(byte)b; write(buf1, 0, 1); }
public void finish() throws IOException { int err; do{ z.next_out=buf; z.next_out_index=0; z.avail_out=bufsize; if(compress){ err=z.deflate(JZlib.Z_FINISH); } else{ err=z.inflate(JZlib.Z_FINISH); } if(err!=JZlib.Z_STREAM_END && err != JZlib.Z_OK) throw new ZStreamException((compress?"de":"in")+"flating: "+z.msg); if(bufsize-z.avail_out>0){ out.write(buf, 0, bufsize-z.avail_out); } } while(z.avail_in>0 || z.avail_out==0); try { flush(); } catch (IOException ignored) { } } public void end() throws IOException {
private void enableCompression(Socket socket) throws IOException { InputStream inputStream = new InflaterInputStream(socket.getInputStream(), new Inflater(true)); input = Okio.buffer(Okio.source(inputStream)); ZOutputStream outputStream = new ZOutputStream(socket.getOutputStream(), JZlib.Z_BEST_SPEED, true); outputStream.setFlushMode(JZlib.Z_PARTIAL_FLUSH); output = Okio.buffer(Okio.sink(outputStream)); }