List of usage examples for java.io InputStream markSupported
public boolean markSupported()
mark
and reset
methods. From source file:org.xwiki.filter.xar.internal.input.XARInputFilterStream.java
private Boolean isZip(InputStream stream) throws IOException { if (!stream.markSupported()) { // ZIP by default return null; }//from w w w. ja v a2s. c o m final byte[] signature = new byte[12]; stream.mark(signature.length); int signatureLength = stream.read(signature); stream.reset(); return ZipArchiveInputStream.matches(signature, signatureLength); }
From source file:de.fanero.uncompress.stream.StreamDetectorImpl.java
@Override public ArchiveInputStream detectAndCreateInputStream(InputStream in, ArchiveEntry archiveEntry) throws IOException { if (!in.markSupported()) { throw new IllegalArgumentException("Mark is not supported."); }//from ww w. j a v a 2 s . c o m byte[] header = readHeader(in, headerSize); archiveEntry = nullToEmpty(archiveEntry); for (StreamMatcherFactory detector : detectors) { StreamMatcher.MatchResult matchResult = detector.matches(header, archiveEntry); switch (matchResult) { case MATCH: return detector.createStream(in, archiveEntry); case NO_MATCH: break; case STOP_MATCHING: return null; } } return null; }
From source file:VASSAL.tools.io.RereadableInputStreamTest.java
@Test public void testMarkSupported() { final InputStream in = new RereadableInputStream(new NullInputStream(10)); assertTrue(in.markSupported()); }
From source file:com.amazonaws.internal.ResettableInputStreamTest.java
@Test public void testFileInputStream() throws IOException { InputStream is = new FileInputStream(file); assertFalse(is.markSupported()); final String content = IOUtils.toString(is); final String content2 = IOUtils.toString(is); assertTrue(content.length() == 100); assertEquals(content2, ""); is.close();// w w w . j ava 2 s .c o m }
From source file:MidiTest.java
/** * Loads a sequence from an input stream. Returns null if an error occurs. *//* www. j a v a 2s .c o m*/ public Sequence getSequence(InputStream is) { try { if (!is.markSupported()) { is = new BufferedInputStream(is); } Sequence s = MidiSystem.getSequence(is); is.close(); return s; } catch (InvalidMidiDataException ex) { ex.printStackTrace(); return null; } catch (IOException ex) { ex.printStackTrace(); return null; } }
From source file:com.intuit.karate.LoggingFilter.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); }/*from w w w . j av a2 s .c o m*/ is.mark(Integer.MAX_VALUE); String buffer = IOUtils.toString(is, getCharset(response.getMediaType())); sb.append(buffer).append('\n'); is.reset(); response.setEntityStream(is); // in case it was swapped } logger.debug(sb.toString()); }
From source file:com.github.n_i_e.dirtreedb.ApacheCompressArchiveLister.java
public ApacheCompressArchiveLister(PathEntry basepath, InputStream inf) throws IOException { super(basepath); Assertion.assertNullPointerException(inf != null); Assertion.assertAssertionError(inf.markSupported()); try {//from w w w . j ava 2 s . c o m instream = new ArchiveStreamFactory().createArchiveInputStream(inf); } catch (ArchiveException e) { throw new IOException(e.toString()); } }
From source file:org.alfresco.encoding.AbstractCharactersetFinder.java
/** * {@inheritDoc}// w w w. ja va 2 s. c om * <p> * The input stream is checked to ensure that it supports marks, after which * a buffer is extracted, leaving the stream in its original state. */ public final Charset detectCharset(InputStream is) { // Only support marking streams if (!is.markSupported()) { throw new IllegalArgumentException( "The InputStream must support marks. Wrap the stream in a BufferedInputStream."); } try { int bufferSize = getBufferSize(); if (bufferSize < 0) { throw new RuntimeException("The required buffer size may not be negative: " + bufferSize); } // Mark the stream for just a few more than we actually will need is.mark(bufferSize); // Create a buffer to hold the data byte[] buffer = new byte[bufferSize]; // Fill it int read = is.read(buffer); // Create an appropriately sized buffer if (read > -1 && read < buffer.length) { byte[] copyBuffer = new byte[read]; System.arraycopy(buffer, 0, copyBuffer, 0, read); buffer = copyBuffer; } // Detect return detectCharset(buffer); } catch (IOException e) { // Attempt a reset throw new AlfrescoRuntimeException("IOException while attempting to detect charset encoding.", e); } finally { try { is.reset(); } catch (Throwable ee) { } } }
From source file:org.apache.tika.parser.wordperfect.WPInputStream.java
/** * Constructor.//from ww w . ja v a 2 s .c o m * @param in input stream */ public WPInputStream(InputStream in) { if (!in.markSupported()) { in = new BufferedInputStream(in); } this.in = new DataInputStream(in); }
From source file:com.jaeksoft.searchlib.streamlimiter.StreamLimiter.java
public InputStream getNewInputStream() throws IOException { if (outputCache == null) loadOutputCache();/* w w w . ja v a2s. co m*/ if (outputCache == null) return null; InputStream inputStream = registerInputStream(outputCache.getNewInputStream()); if (inputStream.markSupported()) return inputStream; inputStream = registerInputStream(new BufferedInputStream(inputStream)); return inputStream; }