@Test(expected = IllegalArgumentException.class) public void testNoData() throws Exception { GzipTelemetrySerializer tested = new GzipTelemetrySerializer(); tested.serialize(new ArrayList<Telemetry>()); }
@Override public Optional<Transmission> serialize(Collection<Telemetry> telemetries) { Preconditions.checkNotNull(telemetries, "telemetries must be non-null value"); Preconditions.checkArgument(!telemetries.isEmpty(), "telemetries: One or more telemetry item is expected"); Transmission result = null; boolean succeeded = false; try { Buffer buffer = new Buffer(); try { GzipSink gzipSink = new GzipSink(buffer); BufferedSink bufferedSink = Okio.buffer(gzipSink); try { succeeded = compress(bufferedSink, telemetries); } catch (Exception e) { logger.error("Failed to serialize , exception: {}", e.toString()); } catch (ThreadDeath td) { throw td; } catch (Throwable t) { try { logger.error("Failed to serialize, unknown exception: {}", t.toString()); } catch (ThreadDeath td) { throw td; } catch (Throwable t2) { } } finally { bufferedSink.close(); } } finally { if (succeeded) { result = new Transmission(buffer.readByteArray(), GZIP_WEB_CONTENT_TYPE, GZIP_WEB_ENCODING_TYPE); } buffer.clear(); } } catch(Exception e) { logger.error("Failed to serialize , exception: {}", e.toString()); } return Optional.fromNullable(result); }
GzipTelemetrySerializer implements TelemetrySerializer { @Override public Optional<Transmission> serialize(Collection<Telemetry> telemetries) { Preconditions.checkNotNull(telemetries, "telemetries must be non-null value"); Preconditions.checkArgument(!telemetries.isEmpty(), "telemetries: One or more telemetry item is expected"); Transmission result = null; boolean succeeded = false; try { Buffer buffer = new Buffer(); try { GzipSink gzipSink = new GzipSink(buffer); BufferedSink bufferedSink = Okio.buffer(gzipSink); try { succeeded = compress(bufferedSink, telemetries); } catch (Exception e) { logger.error("Failed to serialize , exception: {}", e.toString()); } catch (ThreadDeath td) { throw td; } catch (Throwable t) { try { logger.error("Failed to serialize, unknown exception: {}", t.toString()); } catch (ThreadDeath td) { throw td; } catch (Throwable t2) { } } finally { bufferedSink.close(); } } finally { if (succeeded) { result = new Transmission(buffer.readByteArray(), GZIP_WEB_CONTENT_TYPE, GZIP_WEB_ENCODING_TYPE); } buffer.clear(); } } catch(Exception e) { logger.error("Failed to serialize , exception: {}", e.toString()); } return Optional.fromNullable(result); } }
GzipTelemetrySerializer implements TelemetrySerializer { @Override public Optional<Transmission> serialize(Collection<Telemetry> telemetries) { Preconditions.checkNotNull(telemetries, "telemetries must be non-null value"); Preconditions.checkArgument(!telemetries.isEmpty(), "telemetries: One or more telemetry item is expected"); Transmission result = null; boolean succeeded = false; try { Buffer buffer = new Buffer(); try { GzipSink gzipSink = new GzipSink(buffer); BufferedSink bufferedSink = Okio.buffer(gzipSink); try { succeeded = compress(bufferedSink, telemetries); } catch (Exception e) { logger.error("Failed to serialize , exception: {}", e.toString()); } catch (ThreadDeath td) { throw td; } catch (Throwable t) { try { logger.error("Failed to serialize, unknown exception: {}", t.toString()); } catch (ThreadDeath td) { throw td; } catch (Throwable t2) { } } finally { bufferedSink.close(); } } finally { if (succeeded) { result = new Transmission(buffer.readByteArray(), GZIP_WEB_CONTENT_TYPE, GZIP_WEB_ENCODING_TYPE); } buffer.clear(); } } catch(Exception e) { logger.error("Failed to serialize , exception: {}", e.toString()); } return Optional.fromNullable(result); } GzipTelemetrySerializer(); }
GzipTelemetrySerializer implements TelemetrySerializer { @Override public Optional<Transmission> serialize(Collection<Telemetry> telemetries) { Preconditions.checkNotNull(telemetries, "telemetries must be non-null value"); Preconditions.checkArgument(!telemetries.isEmpty(), "telemetries: One or more telemetry item is expected"); Transmission result = null; boolean succeeded = false; try { Buffer buffer = new Buffer(); try { GzipSink gzipSink = new GzipSink(buffer); BufferedSink bufferedSink = Okio.buffer(gzipSink); try { succeeded = compress(bufferedSink, telemetries); } catch (Exception e) { logger.error("Failed to serialize , exception: {}", e.toString()); } catch (ThreadDeath td) { throw td; } catch (Throwable t) { try { logger.error("Failed to serialize, unknown exception: {}", t.toString()); } catch (ThreadDeath td) { throw td; } catch (Throwable t2) { } } finally { bufferedSink.close(); } } finally { if (succeeded) { result = new Transmission(buffer.readByteArray(), GZIP_WEB_CONTENT_TYPE, GZIP_WEB_ENCODING_TYPE); } buffer.clear(); } } catch(Exception e) { logger.error("Failed to serialize , exception: {}", e.toString()); } return Optional.fromNullable(result); } GzipTelemetrySerializer(); @Override Optional<Transmission> serialize(Collection<Telemetry> telemetries); Optional<Transmission> serializeFromStrings(Collection<String> telemetries); }
GzipTelemetrySerializer implements TelemetrySerializer { @Override public Optional<Transmission> serialize(Collection<Telemetry> telemetries) { Preconditions.checkNotNull(telemetries, "telemetries must be non-null value"); Preconditions.checkArgument(!telemetries.isEmpty(), "telemetries: One or more telemetry item is expected"); Transmission result = null; boolean succeeded = false; try { Buffer buffer = new Buffer(); try { GzipSink gzipSink = new GzipSink(buffer); BufferedSink bufferedSink = Okio.buffer(gzipSink); try { succeeded = compress(bufferedSink, telemetries); } catch (Exception e) { logger.error("Failed to serialize , exception: {}", e.toString()); } catch (ThreadDeath td) { throw td; } catch (Throwable t) { try { logger.error("Failed to serialize, unknown exception: {}", t.toString()); } catch (ThreadDeath td) { throw td; } catch (Throwable t2) { } } finally { bufferedSink.close(); } } finally { if (succeeded) { result = new Transmission(buffer.readByteArray(), GZIP_WEB_CONTENT_TYPE, GZIP_WEB_ENCODING_TYPE); } buffer.clear(); } } catch(Exception e) { logger.error("Failed to serialize , exception: {}", e.toString()); } return Optional.fromNullable(result); } GzipTelemetrySerializer(); @Override Optional<Transmission> serialize(Collection<Telemetry> telemetries); Optional<Transmission> serializeFromStrings(Collection<String> telemetries);  }