private long getLengthWhenQuotedPrintableEncoded(byte[] bytes) throws IOException { CountingOutputStream countingOutputStream = new CountingOutputStream(); writeSignSafeQuotedPrintable(countingOutputStream, bytes); return countingOutputStream.getCount(); }
private long decodeAndCountBytes(InputStream rawInputStream, String encoding, long fallbackValue) { InputStream decodingInputStream = localStore.getDecodingInputStream(rawInputStream, encoding); try { CountingOutputStream countingOutputStream = new CountingOutputStream(); try { IOUtils.copy(decodingInputStream, countingOutputStream); return countingOutputStream.getCount(); } catch (IOException e) { return fallbackValue; } } finally { try { decodingInputStream.close(); } catch (IOException e) { /* ignore */ } } }
private long computeMessageSize(LocalMessage message) { // TODO: Store message size in database when saving message so this can be a simple lookup instead. try { CountingOutputStream countingOutputStream = new CountingOutputStream(); message.writeTo(countingOutputStream); return countingOutputStream.getCount(); } catch (IOException | MessagingException e) { Timber.w(e, "Unable to compute message size"); return 0; } }
public long calculateSize() { try { CountingOutputStream out = new CountingOutputStream(); EOLConvertingOutputStream eolOut = new EOLConvertingOutputStream(out); writeTo(eolOut); eolOut.flush(); return out.getCount(); } catch (IOException e) { Timber.e(e, "Failed to calculate a message size"); } catch (MessagingException e) { Timber.e(e, "Failed to calculate a message size"); } return 0; } }