List of usage examples for java.io InputStream markSupported
public boolean markSupported()
mark
and reset
methods. From source file:run.var.teamcity.cloud.docker.client.apcon.ApacheConnector.java
private static InputStream getInputStream(final CloseableHttpResponse response) throws IOException { final InputStream inputStream; // DK_CLD: do not forward the entity stream to Jersey if the connection has been upgraded. This prevent any // component of trying to reading it, which likely result in unexpected result or even deadlock. if (response.getEntity() == null) { inputStream = new ByteArrayInputStream(new byte[0]); } else {/*from ww w .j av a 2 s.c o m*/ final InputStream i = response.getEntity().getContent(); if (i.markSupported()) { inputStream = i; } else { inputStream = new BufferedInputStream(i, ReaderWriter.BUFFER_SIZE); } } return new FilterInputStream(inputStream) { @Override public void close() throws IOException { response.close(); super.close(); } }; }
From source file:com.zotoh.core.io.StreamUte.java
/** * @param src// ww w . j a v a 2s . co m * @param out * @param reset * @throws IOException */ public static void streamToStream(InputStream src, OutputStream out, boolean reset) throws IOException { tstObjArg("out-stream", out); tstObjArg("in-stream", src); byte[] bits = new byte[4096]; int cnt; while ((cnt = src.read(bits)) > 0) { out.write(bits, 0, cnt); } safeFlush(out); if (reset && src.markSupported()) { src.reset(); } }
From source file:org.apache.synapse.commons.json.JsonUtil.java
/** * Returns the JSON stream associated with the payload of this message context. * * @param messageContext Axis2 Message context * @param reset Whether to reset the input stream that contains this JSON payload so that next read will start from the beginning of this stream. * @return JSON input stream// w w w. j a va 2s. co m */ private static InputStream jsonStream(MessageContext messageContext, boolean reset) { if (messageContext == null) { return null; } Object o = messageContext.getProperty(ORG_APACHE_SYNAPSE_COMMONS_JSON_JSON_INPUT_STREAM); if (o instanceof InputStream) { InputStream is = (InputStream) o; if (reset) { if (is.markSupported()) { try { is.reset(); } catch (IOException e) { logger.error("#jsonStream. Could not reuse JSON Stream. Error>>>\n", e); return null; } } } return is; } return null; }
From source file:edu.cornell.mannlib.vitro.webapp.rdfservice.impl.ModelChangeImpl.java
private String streamToString(InputStream stream) { if (!stream.markSupported()) { return String.valueOf(stream); }/* w w w.j a va2s .c om*/ try { stream.mark(Integer.MAX_VALUE); List<String> lines = IOUtils.readLines(stream); stream.reset(); return String.valueOf(lines); } catch (IOException e) { return "Failed to read input stream: " + e; } }
From source file:edu.vt.middleware.ldap.ssl.AbstractCredentialReader.java
/** * Gets a buffered input stream from the given input stream. If the given * instance is already buffered, it is simply returned. * * @param is Input stream from which to create buffered instance. * * @return Buffered input stream. If the given instance is already buffered, * it is simply returned./* www . j a v a 2s.c om*/ */ protected InputStream getBufferedInputStream(final InputStream is) { if (is.markSupported()) { return is; } else { return new BufferedInputStream(is); } }
From source file:org.apache.synapse.commons.json.JsonUtil.java
private static void writeJsonStream(InputStream json, MessageContext messageContext, OutputStream out) throws AxisFault { try {//www. j a v a 2 s . c o m if (json.markSupported()) { json.reset(); } IOUtils.copy(json, out); // Write the JSON stream if (messageContext.getProperty(PRESERVE_JSON_STREAM) != null) { if (json.markSupported()) { json.reset(); } messageContext.removeProperty(PRESERVE_JSON_STREAM); } } catch (IOException e) { logger.error("#writeJsonStream. Could not write JSON stream. MessageID: " + messageContext.getMessageID() + ". Error>> " + e.getLocalizedMessage()); throw new AxisFault("Could not write JSON stream.", e); } }
From source file:com.github.n_i_e.dirtreedb.ApacheCompressCompressingArchiveLister.java
public ApacheCompressCompressingArchiveLister(PathEntry basepath, InputStream inf) throws IOException { super(basepath); Assertion.assertNullPointerException(inf != null); try {/*from ww w.ja va 2 s . c o m*/ InputStream inf2 = new CompressorStreamFactory().createCompressorInputStream(inf); InputStream inf3 = new BufferedInputStream(inf2); assert (inf3.markSupported()); instream = new ArchiveStreamFactory().createArchiveInputStream(inf3); } catch (ArchiveException e) { throw new IOException(e.toString()); } catch (CompressorException e) { throw new IOException(e.toString()); } }
From source file:com.smartitengineering.cms.spi.impl.type.validator.XMLSchemaBasedTypeValidator.java
@Override public boolean isValid(InputStream documentStream) throws Exception { if (!documentStream.markSupported()) { throw new IOException("Only markeable input stream expected!"); }/*from w w w. j a v a 2s. c om*/ documentStream.mark(Integer.MAX_VALUE); InputStream cloneStream = new ByteArrayInputStream(IOUtils.toByteArray(documentStream)); documentStream.reset(); Document document = getDocumentForSource(cloneStream); return isValid(document); }
From source file:org.nuxeo.ecm.platform.convert.plugins.UTF8CharsetConverter.java
protected String detectEncoding(InputStream in) throws IOException, ConversionException { if (!in.markSupported()) { // detector.setText requires mark in = new BufferedInputStream(in); }// www. j a v a 2 s . co m CharsetDetector detector = new CharsetDetector(); detector.setText(in); CharsetMatch charsetMatch = detector.detect(); if (charsetMatch == null) { throw new ConversionException("Cannot detect source charset."); } return charsetMatch.getName(); }
From source file:com.intuit.karate.http.jersey.LoggingInterceptor.java
@Override public void filter(ClientRequestContext request, ClientResponseContext response) throws IOException { int id = counter.get(); StringBuilder sb = new StringBuilder(); sb.append('\n').append(id).append(" < ").append(response.getStatus()).append('\n'); logHeaders(sb, id, '<', response.getHeaders()); if (response.hasEntity() && isPrintable(response.getMediaType())) { InputStream is = response.getEntityStream(); if (!is.markSupported()) { is = new BufferedInputStream(is); }/* w ww . j a v a2 s. c om*/ is.mark(Integer.MAX_VALUE); String buffer = IOUtils.toString(is, UTF8); sb.append(buffer).append('\n'); is.reset(); response.setEntityStream(is); // in case it was swapped } logger.debug(sb.toString()); }