public static PyString compress(PyString data, int compresslevel) { PyString returnData = null; try { ByteArrayOutputStream compressedArray = new ByteArrayOutputStream(); BZip2CompressorOutputStream bzbuf = new BZip2CompressorOutputStream( compressedArray); bzbuf.write(data.toBytes()); bzbuf.finish(); bzbuf.close(); returnData = new PyString(compressedArray.toString("iso-8859-1")); compressedArray.close(); } catch (IOException e) { throw Py.IOError(e.getMessage()); } return returnData; }
@Override public Object __tojava__(Class<?> c) { if (c.isAssignableFrom(String.class)) { return getString(); } if (c == Character.TYPE || c == Character.class) { if (getString().length() == 1) { return new Character(getString().charAt(0)); } } if (c.isArray()) { if (c.getComponentType() == Byte.TYPE) { return toBytes(); } if (c.getComponentType() == Character.TYPE) { return getString().toCharArray(); } } if (c.isAssignableFrom(Collection.class)) { List<Object> list = new ArrayList(); for (int i = 0; i < __len__(); i++) { list.add(pyget(i).__tojava__(String.class)); } return list; } if (c.isInstance(this)) { return this; } return Py.NoConversion; }
data.toBytes()); BZip2CompressorInputStream bzbuf = new BZip2CompressorInputStream( inputArray);
s.getOutputStream().write(payload.toBytes()); s.getOutputStream().flush();
/** * Sink implementation which forwards the items it receives to the Graphite. * Graphite's Pickle Protocol is used for communication between Jet and Graphite. * * @param host Graphite host * @param port Graphite port */ private static Sink<TimestampedEntry> buildGraphiteSink(String host, int port) { return sinkBuilder("graphite", instance -> new BufferedOutputStream(new Socket(host, port).getOutputStream())) .<TimestampedEntry>receiveFn((bos, entry) -> { GraphiteMetric metric = new GraphiteMetric(); metric.from(entry); PyString payload = cPickle.dumps(metric.getAsList(), 2); byte[] header = ByteBuffer.allocate(4).putInt(payload.__len__()).array(); bos.write(header); bos.write(payload.toBytes()); }) .flushFn(BufferedOutputStream::flush) .destroyFn(BufferedOutputStream::close) .build(); }
byte[] indata = data.toBytes(); if (indata.length > 0) { ByteBuffer bytebuf = ByteBuffer.allocate(accumulator.length
@ExposedMethod public PyString BZ2Compressor_compress(PyObject[] args, String[] kwds) { ArgParser ap = new ArgParser("compress", args, kwds, new String[] { "data" }, 1); PyString data = (PyString) ap.getPyObject(0); PyString returnData = null; try { compressStream.write(data.toBytes()); returnData = readData(); } catch (IOException e) { throw Py.IOError(e.getMessage()); } return returnData; }
bytes = ((PyFile) object).read().toBytes(); } else { String varchar = (String) object.__tojava__(String.class);
byte[] chars = ((PyString)value).toBytes(); if (chars.length == stop - start && step == 1) { System.arraycopy(chars, 0, data, start, chars.length);
socketOutputStream.write(payload.toBytes());