@Override public byte[] serialize(Object data) throws IOException { ByteArrayOutputStream bos = new ByteArrayOutputStream(); Kryo kryo = kryoThreadMap.get(); KryoObjectOutput out = new KryoObjectOutput(kryo, new FastOutput(bos)); out.writeObject(data); out.flush(); return bos.toByteArray(); }
public void openFileForWriting() { try { File destinationFile = newFileStrategy.getNewFile(); LOG.info("{} storing events to: {}", newFileStrategy.toString(), destinationFile.getAbsolutePath()); FileOutputStream fos = new FileOutputStream(destinationFile); OutputStream out = storeInGzip ? new GZIPOutputStream(fos, true) : fos; output = new FastOutput(out); } catch (IOException e) { e.printStackTrace(); } }
public final byte[] serialize(final Object value) { final Kryo kryo = threadLocalKryo.get(); final Output output = new FastOutput(16, 1024); kryo.writeClassAndObject(output, value); return output.toBytes(); }
public static RecordableHttpServletRequest prepareRequestToRecord(HttpServletRequest original, HttpRecordInformation info) { // buffer is 1kb at least ByteArrayOutputStream stream = new ByteArrayOutputStream(1024 * 1024); FastOutput out = new FastOutput(stream); Kryo kryo = threadKryo.get(); if (kryo == null) { kryo = new Kryo(); kryo.register(HashMap.class, new MapSerializer()); kryo.register(ConcurrentHashMap.class, new MapSerializer()); threadKryo.set(kryo); } HashMap<String, String[]> item = new HashMap<>(); if (original.getParameterMap() != null) { item.putAll(original.getParameterMap()); } HashMap<String, String> headers = new HashMap<>(); Enumeration<String> names = original.getHeaderNames(); while (names.hasMoreElements()) { String header = names.nextElement(); headers.put(header, original.getHeader(header)); } try { kryo.writeObject(out, item); kryo.writeObject(out, headers); kryo.writeObjectOrNull(out, original.getContentLength(), Integer.class); kryo.writeObjectOrNull(out, original.getContentType(), String.class); kryo.writeObjectOrNull(out, original.getRequestURI(), String.class); kryo.writeObjectOrNull(out, original.getMethod(), String.class); kryo.writeObjectOrNull(out, original.getServletContext().getContextPath(), String.class); HashMap<String, String> cookies = new HashMap<>(); if (original.getCookies() != null && original.getCookies().length > 0) { for (Cookie cookie : original.getCookies()) { cookies.put(cookie.getName(), cookie.getValue()); } } kryo.writeObject(out, cookies); out.flush(); out.close(); } catch (Exception e) { e.printStackTrace(System.err); throw e; } info.params = stream.toByteArray(); return new RecordableHttpServletRequest(original); }