During message.getInterceptorChain().doIntercept(message); I see call to maybeDeleteTempFile() which resets inmem = true; and later csnew.getInputStream() execution leads to if (inmem) { }
2016-09-19 13:05 GMT+04:00 Vjacheslav V. Borisov <slav...@gmail.com>: > Hi! > > I have following code (this is interceptror which does regular expression > replacements) > > > https://github.com/ilb/common/blob/master/common-jaxrs/src/ > main/java/ru/ilb/common/jaxrs/interceptors/ReplaceOutInterceptor.java > > private void replaceContents(Message message) { > OutputStream os = message.getContent(OutputStream.class); > CachedStream cs = new CachedStream(); > message.setContent(OutputStream.class, cs); > > message.getInterceptorChain().doIntercept(message); > > try { > cs.flush(); > CachedOutputStream csnew = (CachedOutputStream) > message.getContent(OutputStream.class); > > String contents = IOUtils.toString(csnew.getInputStream()); > for (Map.Entry<String, String> keyValue : > replacements.entrySet()) { > contents = contents.replaceAll(keyValue.getKey(), > keyValue.getValue()); > } > //String replaced=contents.replaceAll(regex, replacement); > os.write(contents.getBytes(Charset.forName(encoding))); > os.flush(); > > message.setContent(OutputStream.class, os); > > } catch (IOException ioe) { > throw new RuntimeException(ioe); > } > } > > > > Howewer, when response contents length of if less than threshold (128 * > 1024 bytes) > i can get csnew.getInputStream() and get its contents, but when content is > more than treshold, > i see that in enforceLimits() -> createFileOutputStream() temp file is > created, > but using csnew.getInputStream() I am getting empty stream. >