throws IOException { if (inputOffset > 0) { skipFully(input, inputOffset);
final long inputOffset, final long length, final byte[] buffer) throws IOException { if (inputOffset > 0) { skipFully(input, inputOffset);
private static long computeFileChecksum(final File sourceFile) { try ( CheckedInputStream stream = new CheckedInputStream( new BufferedInputStream(Files.newInputStream(sourceFile.toPath())), new Adler32()); ) { // Just read it, the CheckedInputStream will update the checksum on it's own IOUtils.skipFully(stream, sourceFile.length()); return stream.getChecksum().getValue(); } catch (final IOException ignored) { // We don't really care, if it's unreadable // the analysis will fail and report the error on it's own since the checksum won't match } return 0; }
@Test public void testSkipFully_InputStream() throws Exception { final int size = 1027; final InputStream input = new ByteArrayInputStream(new byte[size]); try { IOUtils.skipFully(input, -1); fail("Should have failed with IllegalArgumentException"); } catch (final IllegalArgumentException expected) { // expected } IOUtils.skipFully(input, 0); IOUtils.skipFully(input, size - 1); try { IOUtils.skipFully(input, 2); fail("Should have failed with IOException"); } catch (final IOException expected) { // expected } IOUtils.closeQuietly(input); }
@Test public void testSkipFully_Reader() throws Exception { final int size = 1027; final Reader input = new CharArrayReader(new char[size]); IOUtils.skipFully(input, 0); IOUtils.skipFully(input, size - 3); try { IOUtils.skipFully(input, -1); fail("Should have failed with IllegalArgumentException"); } catch (final IllegalArgumentException expected) { // expected } try { IOUtils.skipFully(input, 5); fail("Should have failed with IOException"); } catch (final IOException expected) { // expected } IOUtils.closeQuietly(input); }
@Test public void testSkipFully_ReadableByteChannel() throws Exception { final FileInputStream fileInputStream = new FileInputStream(m_testFile); final FileChannel fileChannel = fileInputStream.getChannel(); try { try { IOUtils.skipFully(fileChannel, -1); fail("Should have failed with IllegalArgumentException"); } catch (final IllegalArgumentException expected) { // expected } IOUtils.skipFully(fileChannel, 0); IOUtils.skipFully(fileChannel, FILE_SIZE - 1); try { IOUtils.skipFully(fileChannel, 2); fail("Should have failed with IOException"); } catch (final IOException expected) { // expected } } finally { IOUtils.closeQuietly(fileChannel, fileInputStream); } }
@Override public long skip(long ln) throws IOException { IOUtils.skipFully(in, ln); return ln; } }
private long processFieldEntries(InputStream stream, List<FieldInfo> fieldInfoList, Metadata embeddedMetadata, long bytesRead) throws IOException, TikaException { byte[] buffer = null; for (FieldInfo f : fieldInfoList) { long diff = f.offset - bytesRead; //just in case IOUtils.skipFully(stream, diff); bytesRead += diff; if (f.entryId == REAL_NAME) { if (f.length > Integer.MAX_VALUE) { throw new TikaException("File name length can't be > integer max"); } buffer = new byte[(int)f.length]; IOUtils.readFully(stream, buffer); bytesRead += f.length; String originalFileName = new String(buffer, 0, buffer.length, StandardCharsets.US_ASCII); embeddedMetadata.set(TikaCoreProperties.ORIGINAL_RESOURCE_NAME, originalFileName); } else if (f.entryId != DATA_FORK) { IOUtils.skipFully(stream, f.length); bytesRead += f.length; } } return bytesRead; }
private short readThroughNumEntries(InputStream stream) throws TikaException, IOException { //mime EndianUtils.readIntBE(stream); //version long version = EndianUtils.readIntBE(stream); if (version != 0x00020000) { throw new TikaException("Version should have been 0x00020000, but was:"+version); } IOUtils.skipFully(stream, 16);//filler return EndianUtils.readShortBE(stream);//number of entries }
@Override public long skip(long ln) throws IOException { IOUtils.skipFully(in, ln); return ln; } }
IOUtils.skipFully(in, param);
@Override public void parse(InputStream stream, ContentHandler handler, Metadata metadata, ParseContext context) throws IOException, SAXException, TikaException { EmbeddedDocumentExtractor ex = EmbeddedDocumentUtil.getEmbeddedDocumentExtractor(context); short numEntries = readThroughNumEntries(stream); long bytesRead = 26; List<FieldInfo> fieldInfoList = getSortedFieldInfoList(stream, numEntries); bytesRead += 12*numEntries; Metadata embeddedMetadata = new Metadata(); bytesRead = processFieldEntries(stream, fieldInfoList, embeddedMetadata, bytesRead); FieldInfo contentFieldInfo = getContentFieldInfo(fieldInfoList); XHTMLContentHandler xhtml = new XHTMLContentHandler(handler, metadata); xhtml.startDocument(); if (contentFieldInfo != null) { long diff = contentFieldInfo.offset-bytesRead; IOUtils.skipFully(stream, diff); if (ex.shouldParseEmbedded(embeddedMetadata)) { // TODO: we should probably add a readlimiting wrapper around this // stream to ensure that not more than contentFieldInfo.length bytes // are read ex.parseEmbedded(new CloseShieldInputStream(stream), xhtml, embeddedMetadata, false); } } xhtml.endDocument(); }
/** * Skip the remaining bytes of the last message returned from nextMessage(). This must be called if it is not certain * that all of the bytes of the message were consumed. * @throws IOException On IO error */ public void skipRemainingBytes() throws IOException { long count = countingInputStream.resetByteCount(); if (count < messageSize) { IOUtils.skipFully(dataInputStream, messageSize - count); } messageSize = 0; } }
private static void readCommentBlock(DataInput dataInput, InputStream inputStream, FlacTrackInfoBuilder trackInfoBuilder) throws IOException { int vendorLength = Integer.reverseBytes(dataInput.readInt()); IOUtils.skipFully(inputStream, vendorLength); int listLength = Integer.reverseBytes(dataInput.readInt()); for (int i = 0; i < listLength; i++) { int itemLength = Integer.reverseBytes(dataInput.readInt()); byte[] textBytes = new byte[itemLength]; dataInput.readFully(textBytes); String text = new String(textBytes, 0, textBytes.length, CHARSET); String[] keyAndValue = text.split("=", 2); if (keyAndValue.length > 1) { trackInfoBuilder.addTag(keyAndValue[0].toUpperCase(), keyAndValue[1]); } } }
private static long computeFileChecksum(final File sourceFile) { try ( CheckedInputStream stream = new CheckedInputStream( new BufferedInputStream(Files.newInputStream(sourceFile.toPath())), new Adler32()); ) { // Just read it, the CheckedInputStream will update the checksum on it's own IOUtils.skipFully(stream, sourceFile.length()); return stream.getChecksum().getValue(); } catch (final IOException ignored) { // We don't really care, if it's unreadable // the analysis will fail and report the error on it's own since the checksum won't match } return 0; }
public static void skipFully(ActionContext actionContext) throws IOException { Thing self = actionContext.getObject("self"); Object input = self.doAction("getInput", actionContext); Long skipSize = (Long) self.doAction("getSkipSize", actionContext); if(input instanceof InputStream){ IOUtils.skipFully((InputStream) input, skipSize); }else if(input instanceof Reader){ IOUtils.skipFully((Reader) input, skipSize); }else if(input instanceof ReadableByteChannel){ IOUtils.skipFully((ReadableByteChannel) input, skipSize); }else{ throw new ActionException("Unsupport input " + input + ", action=" + self.getMetadata().getPath()); } }
private short readThroughNumEntries(InputStream stream) throws TikaException, IOException { //mime EndianUtils.readIntBE(stream); //version long version = EndianUtils.readIntBE(stream); if (version != 0x00020000) { throw new TikaException("Version should have been 0x00020000, but was:"+version); } IOUtils.skipFully(stream, 16);//filler return EndianUtils.readShortBE(stream);//number of entries }
private short readThroughNumEntries(InputStream stream) throws TikaException, IOException { //mime EndianUtils.readIntBE(stream); //version long version = EndianUtils.readIntBE(stream); if (version != 0x00020000) { throw new TikaException("Version should have been 0x00020000, but was:"+version); } IOUtils.skipFully(stream, 16);//filler return EndianUtils.readShortBE(stream);//number of entries }