Getting size of request

12 views
Skip to first unread message

cobo lus

unread,
Apr 8, 2021, 7:06:38 AM4/8/21
to ipf-user
hi !

i want to process a ITI-41 request and would like to know how big the request is in bytes before I store the documents to disk. Is there a way to get the content length ?

Quentin Ligier

unread,
Apr 13, 2021, 3:08:40 PM4/13/21
to ipf-user
Hi,

You can simply count the bytes in the document input stream:
final ProvideAndRegisterDocumentSet request = Exchanges.getBody(exchange, ProvideAndRegisterDocumentSet.class);
final InputStream fileInputStream = request.getDocuments().get(0).getDataHandler().getInputStream();
final long documentSize;
try (final CountingOutputStream counter = new CountingOutputStream(new NullOutputStream())) {
    int b;
    while ((b = fileInputStream.read()) != -1) {
        counter.write(b);
    }
    documentSize = counter.getByteCount();
}

Kind regards,
Quentin

Christian Ohr

unread,
Apr 13, 2021, 4:14:17 PM4/13/21
to ipf-...@googlegroups.com
... and sometimes the content-length header ist present.

Christian

--
You received this message because you are subscribed to the Google Groups "ipf-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ipf-user+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ipf-user/cef08ac3-573c-438c-8d2c-c828ee4114f0n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages