/** * Convenience method to get the embedded data as byte array. * * @return the embedded data. */ default byte[] getBytes() throws IOException { try (InputStream is = getInputStream()) { return IOUtils.toByteArray(is); } }
/** * Convenience method to return the raw data as {@code InputStream} * * @return the raw data stream * * @throws IOException if the data couldn't be retrieved */ default InputStream readObjectDataRaw() throws IOException { return getObjectData().getInputStream(); }
/** * Gets the object data. Only call for ones that have * data though. See {@link #hasDirectoryEntry()}. * The caller has to close the corresponding POIFSFileSystem * * @return the object data as an OLE2 directory. * @throws IOException if there was an error reading the data. */ @SuppressWarnings("resource") default DirectoryEntry getDirectory() throws IOException { try (final InputStream is = getInputStream()) { return new POIFSFileSystem(is).getRoot(); } }
/** * @return does this ObjectData have an associated POIFS Directory Entry? * (Not all do, those that don't have a data portion) */ default boolean hasDirectoryEntry() { try (final InputStream is = FileMagic.prepareToCheckMagic(getInputStream())) { FileMagic fm = FileMagic.valueOf(is); return fm == FileMagic.OLE2; } catch (IOException e) { POILogger LOG = POILogFactory.getLogger(ObjectData.class); LOG.log(POILogger.WARN, "Can't determine filemagic of ole stream", e); return false; } }
/** * Convenience method to get the embedded data as byte array. * * @return the embedded data. */ default byte[] getBytes() throws IOException { try (InputStream is = getInputStream()) { return IOUtils.toByteArray(is); } }
/** * Convenience method to return the raw data as {@code InputStream} * * @return the raw data stream * * @throws IOException if the data couldn't be retrieved */ default InputStream readObjectDataRaw() throws IOException { return getObjectData().getInputStream(); }
/** * Gets the object data. Only call for ones that have * data though. See {@link #hasDirectoryEntry()}. * The caller has to close the corresponding POIFSFileSystem * * @return the object data as an OLE2 directory. * @throws IOException if there was an error reading the data. */ @SuppressWarnings("resource") default DirectoryEntry getDirectory() throws IOException { try (final InputStream is = getInputStream()) { return new POIFSFileSystem(is).getRoot(); } }
/** * @return does this ObjectData have an associated POIFS Directory Entry? * (Not all do, those that don't have a data portion) */ default boolean hasDirectoryEntry() { try (final InputStream is = FileMagic.prepareToCheckMagic(getInputStream())) { FileMagic fm = FileMagic.valueOf(is); return fm == FileMagic.OLE2; } catch (IOException e) { POILogger LOG = POILogFactory.getLogger(ObjectData.class); LOG.log(POILogger.WARN, "Can't determine filemagic of ole stream", e); return false; } }