Examples of ReadContentInputStream


Examples of org.sleuthkit.datamodel.ReadContentInputStream

                    NbBundle.getMessage(this.getClass(), "ScalpelCarver.carve.exception.cannotWriteConfig",
                                        outputFolderPath));
        }

        final String carverInputId = file.getId() + ": " + file.getName();
        final ReadContentInputStream carverInput = new ReadContentInputStream(file);
       

        try {
            carveNat(carverInputId, carverInput, configFilePath, outputFolderPath);
        }
        catch (Exception e) {
            logger.log(Level.SEVERE, "Error while caving file " + file, e); //NON-NLS
            throw new ScalpelException(e);
        }
        finally {
            try {
                carverInput.close();
            } catch (IOException ex) {
                logger.log(Level.SEVERE, "Error closing input stream after carving, file: " + file, ex); //NON-NLS
            }
        }
       
View Full Code Here

Examples of org.sleuthkit.datamodel.ReadContentInputStream

            image = imageRef.get();
        }

        if (image == null) {

            try (ReadContentInputStream readContentInputStream = new ReadContentInputStream(this.getAbstractFile())) {
                BufferedImage read = ImageIO.read(readContentInputStream);
                image = SwingFXUtils.toFXImage(read, null);
            } catch (IOException | NullPointerException ex) {
                Logger.getLogger(ImageFile.class.getName()).log(Level.WARNING, "unable to read file" + getName());
                return null;
View Full Code Here

Examples of org.sleuthkit.datamodel.ReadContentInputStream

    ProcessResult processFile(AbstractFile f) {
        InputStream in = null;
        BufferedInputStream bin = null;

        try {
            in = new ReadContentInputStream(f);
            bin = new BufferedInputStream(in);

            Collection<BlackboardAttribute> attributes = new ArrayList<>();
            Metadata metadata = ImageMetadataReader.readMetadata(bin, true);
View Full Code Here

Examples of org.sleuthkit.datamodel.ReadContentInputStream

        this.sourceFile = sourceFile;
        numChunks = 0; //unknown until indexing is done

        boolean success = false;
        Reader reader = null;
        final InputStream stream = new ReadContentInputStream(sourceFile);
        try {
            Metadata meta = new Metadata();

            //Parse the file in a task
            Tika tika = new Tika(); //new tika instance for every file, to workaround tika memory issues
            ParseRequestTask parseTask = new ParseRequestTask(tika, stream, meta, sourceFile);
            final Future<?> future = tikaParseExecutor.submit(parseTask);
            try {
                future.get(Ingester.getTimeout(sourceFile.getSize()), TimeUnit.SECONDS);
            } catch (TimeoutException te) {
                final String msg = NbBundle.getMessage(this.getClass(),
                                                       "AbstractFileTikaTextExtract.index.tikaParseTimeout.text",
                                                       sourceFile.getId(), sourceFile.getName());
                KeywordSearch.getTikaLogger().log(Level.WARNING, msg, te);
                logger.log(Level.WARNING, msg);
                throw new IngesterException(msg);
            } catch (Exception ex) {
                final String msg = NbBundle.getMessage(this.getClass(),
                                                       "AbstractFileTikaTextExtract.index.exception.tikaParse.msg",
                                                       sourceFile.getId(), sourceFile.getName());
                KeywordSearch.getTikaLogger().log(Level.WARNING, msg, ex);
                logger.log(Level.WARNING, msg);
                throw new IngesterException(msg);
            }

            // get the reader with the results
            reader = parseTask.getReader();
            if (reader == null) {
                //likely due to exception in parse()
                logger.log(Level.WARNING, "No reader available from Tika parse"); //NON-NLS
                return false;
            }


            // break the results into chunks and index
            success = true;
            long readSize;
            long totalRead = 0;
            boolean eof = false;
            //we read max 1024 chars at time, this seems to max what this Reader would return
            while (!eof) {
                readSize = reader.read(textChunkBuf, 0, SINGLE_READ_CHARS);
                if (readSize == -1) {
                    eof = true;
                }
                else {
                    totalRead += readSize;
                }
                //consume more bytes to fill entire chunk (leave EXTRA_CHARS to end the word)
                while (!eof && (totalRead < MAX_EXTR_TEXT_CHARS - SINGLE_READ_CHARS - EXTRA_CHARS)
                        && (readSize = reader.read(textChunkBuf, (int) totalRead, SINGLE_READ_CHARS)) != -1) {
                    totalRead += readSize;
                }
                if (readSize == -1) {
                    //this is the last chunk
                    eof = true;
                } else {
                    //try to read char-by-char until whitespace to not break words
                    while ((totalRead < MAX_EXTR_TEXT_CHARS - 1)
                            && !Character.isWhitespace(textChunkBuf[(int) totalRead - 1])
                            && (readSize = reader.read(textChunkBuf, (int) totalRead, 1)) != -1) {
                        totalRead += readSize;
                    }
                    if (readSize == -1) {
                        //this is the last chunk
                        eof = true;
                    }
                }

                //logger.log(Level.INFO, "TOTAL READ SIZE: " + totalRead + " file: " + sourceFile.getName());
                //encode to bytes to index as byte stream
                String extracted;
                //add BOM and trim the 0 bytes
                //set initial size to chars read + bom + metadata (roughly) - try to prevent from resizing
                StringBuilder sb = new StringBuilder((int) totalRead + 1000);
                //inject BOM here (saves byte buffer realloc later), will be converted to specific encoding BOM
                //sb.append(UTF16BOM); disabled prepending of BOM
                if (totalRead < MAX_EXTR_TEXT_CHARS) {
                    sb.append(textChunkBuf, 0, (int) totalRead);
                } else {
                    sb.append(textChunkBuf);
                }

                //reset for next chunk
                totalRead = 0;

                //append meta data if last chunk
                if (eof) {
                    //sort meta data keys
                    List<String> sortedKeyList = Arrays.asList(meta.names());
                    Collections.sort(sortedKeyList);
                    sb.append("\n\n------------------------------METADATA------------------------------\n\n"); //NON-NLS
                    for (String key : sortedKeyList) {
                        String value = meta.get(key);
                        sb.append(key).append(": ").append(value).append("\n");
                    }
                }

                extracted = sb.toString();

               
                //converts BOM automatically to charSet encoding
                byte[] encodedBytes = extracted.getBytes(OUTPUT_CHARSET);
                AbstractFileChunk chunk = new AbstractFileChunk(this, this.numChunks + 1);
                try {
                    chunk.index(ingester, encodedBytes, encodedBytes.length, OUTPUT_CHARSET);
                    ++this.numChunks;
                } catch (Ingester.IngesterException ingEx) {
                    success = false;
                    logger.log(Level.WARNING, "Ingester had a problem with extracted strings from file '" //NON-NLS
                            + sourceFile.getName() + "' (id: " + sourceFile.getId() + ").", ingEx); //NON-NLS
                    throw ingEx; //need to rethrow/return to signal error and move on
                }
            }
        } catch (IOException ex) {
            final String msg = "Exception: Unable to read Tika content stream from " + sourceFile.getId() + ": " + sourceFile.getName(); //NON-NLS
            KeywordSearch.getTikaLogger().log(Level.WARNING, msg, ex);
            logger.log(Level.WARNING, msg);
            success = false;
        } catch (Exception ex) {
            final String msg = "Exception: Unexpected error, can't read Tika content stream from " + sourceFile.getId() + ": " + sourceFile.getName(); //NON-NLS
            KeywordSearch.getTikaLogger().log(Level.WARNING, msg, ex);
            logger.log(Level.WARNING, msg);
            success = false;
        } finally {
            try {
                stream.close();
            } catch (IOException ex) {
                logger.log(Level.WARNING, "Unable to close Tika content stream from " + sourceFile.getId(), ex); //NON-NLS
            }
            try {
                if (reader != null) {
View Full Code Here

Examples of org.sleuthkit.datamodel.ReadContentInputStream

            return f.getSize();
        }

        @Override
        public InputStream getStream() throws IOException {
            return new ReadContentInputStream(f);
        }
View Full Code Here

Examples of org.sleuthkit.datamodel.ReadContentInputStream

        numChunks = 0; //unknown until indexing is done

        boolean success = false;
        Reader reader = null;

        final InputStream stream = new ReadContentInputStream(sourceFile);

        try {
            // Parse the stream with Jericho
            JerichoParserWrapper jpw = new JerichoParserWrapper(stream);
            jpw.parse();
            reader = jpw.getReader();

            // In case there is an exception or parse() isn't called
            if (reader == null) {
                logger.log(Level.WARNING, "No reader available from HTML parser"); //NON-NLS
                return false;
            }

            success = true;
            long readSize;
            long totalRead = 0;
            boolean eof = false;
            //we read max 1024 chars at time, this seems to max what this Reader would return
            while (!eof && (readSize = reader.read(textChunkBuf, 0, SINGLE_READ_CHARS)) != -1) {
                totalRead += readSize;

                //consume more bytes to fill entire chunk (leave EXTRA_CHARS to end the word)
                while ((totalRead < MAX_EXTR_TEXT_CHARS - SINGLE_READ_CHARS - EXTRA_CHARS)
                        && (readSize = reader.read(textChunkBuf, (int) totalRead, SINGLE_READ_CHARS)) != -1) {
                    totalRead += readSize;
                }
                if (readSize == -1) {
                    //this is the last chunk
                    eof = true;
                } else {
                    //try to read until whitespace to not break words
                    while ((totalRead < MAX_EXTR_TEXT_CHARS - 1)
                            && !Character.isWhitespace(textChunkBuf[(int) totalRead - 1])
                            && (readSize = reader.read(textChunkBuf, (int) totalRead, 1)) != -1) {
                        totalRead += readSize;
                    }
                    if (readSize == -1) {
                        //this is the last chunk
                        eof = true;
                    }
                }

                //logger.log(Level.INFO, "TOTAL READ SIZE: " + totalRead + " file: " + sourceFile.getName());
                //encode to bytes to index as byte stream
                String extracted;

                //add BOM and trim the 0 bytes
                //set initial size to chars read + bom - try to prevent from resizing
                StringBuilder sb = new StringBuilder((int) totalRead + 1000);
                //inject BOM here (saves byte buffer realloc later), will be converted to specific encoding BOM
                //sb.append(UTF16BOM); disabled BOM, not needing as bypassing Tika
                if (totalRead < MAX_EXTR_TEXT_CHARS) {
                    sb.append(textChunkBuf, 0, (int) totalRead);
                } else {
                    sb.append(textChunkBuf);
                }

                //reset for next chunk
                totalRead = 0;
                extracted = sb.toString();

                //converts BOM automatically to charSet encoding
                byte[] encodedBytes = extracted.getBytes(outCharset);
                AbstractFileChunk chunk = new AbstractFileChunk(this, this.numChunks + 1);
                try {
                    chunk.index(ingester, encodedBytes, encodedBytes.length, outCharset);
                    ++this.numChunks;
                } catch (Ingester.IngesterException ingEx) {
                    success = false;
                    logger.log(Level.WARNING, "Ingester had a problem with extracted HTML from file '" //NON-NLS
                            + sourceFile.getName() + "' (id: " + sourceFile.getId() + ").", ingEx); //NON-NLS
                    throw ingEx; //need to rethrow/return to signal error and move on
                }
            }
        } catch (IOException ex) {
            logger.log(Level.WARNING, "Unable to read content stream from " + sourceFile.getId() + ": " + sourceFile.getName(), ex); //NON-NLS
            success = false;
        } catch (Exception ex) {
            logger.log(Level.WARNING, "Unexpected error, can't read content stream from " + sourceFile.getId() + ": " + sourceFile.getName(), ex); //NON-NLS
            success = false;
        } finally {
            try {
                stream.close();
            } catch (IOException ex) {
                logger.log(Level.WARNING, "Unable to close content stream from " + sourceFile.getId(), ex); //NON-NLS
            }
            try {
                if (reader != null) {
View Full Code Here

Examples of org.sleuthkit.datamodel.ReadContentInputStream

     * @throws IOException if file could not be written
     */
    public static <T,V> long writeToFile(Content content, java.io.File outputFile,
            ProgressHandle progress, SwingWorker<T,V> worker, boolean source) throws IOException {

        InputStream in = new ReadContentInputStream(content);

        boolean append = false;
        FileOutputStream out = new FileOutputStream(outputFile, append);

        // Get the unit size for a progress bar
        int unit = (int) (content.getSize() / 100);
        long totalRead = 0;

        try {
            byte[] buffer = new byte[TO_FILE_BUFFER_SIZE];
            int len = in.read(buffer);
            while (len != -1) {
                // If there is a worker, check for a cancelation
                if (worker != null && worker.isCancelled()) {
                    break;
                }
                out.write(buffer, 0, len);
                len = in.read(buffer);
                totalRead += len;
                // If there is a progress bar and this is the source file,
                // report any progress
                if (progress != null && source && totalRead >= TO_FILE_BUFFER_SIZE) {
                    int totalProgress = (int) (totalRead / unit);
View Full Code Here

Examples of org.sleuthkit.datamodel.ReadContentInputStream

                    //handle in-between condition when case is being closed
                    //and an image was previously selected
                    return;
                }

                final InputStream inputStream = new ReadContentInputStream(file);

                final Image fxImage;
                try {
                    //original input stream
                    BufferedImage bi = ImageIO.read(inputStream);
                    if (bi == null) {
                        logger.log(Level.WARNING, "Could image reader not found for file: " + fileName); //NON-NLS
                        return;
                    }
                    //scale image using Scalr
                    BufferedImage biScaled = ScalrWrapper.resizeHighQuality(bi, (int) dims.getWidth(), (int) dims.getHeight());
                    //convert from awt imageto fx image
                    fxImage = SwingFXUtils.toFXImage(biScaled, null);
                } catch (IOException ex) {
                    logger.log(Level.WARNING, "Could not load image file into media view: " + fileName, ex); //NON-NLS
                    return;
                } catch (OutOfMemoryError ex) {
                    logger.log(Level.WARNING, "Could not load image file into media view (too large): " + fileName, ex); //NON-NLS
                    MessageNotifyUtil.Notify.warn(
                            NbBundle.getMessage(this.getClass(), "MediaViewImagePanel.imgFileTooLarge.msg", file.getName()),
                            ex.getMessage());
                    return;
                } finally {
                    try {
                        inputStream.close();
                    } catch (IOException ex) {
                        logger.log(Level.WARNING, "Could not close input stream after loading image in media view: " + fileName, ex); //NON-NLS
                    }
                }
View Full Code Here

Examples of org.sleuthkit.datamodel.ReadContentInputStream

     */
    private static BufferedImage generateIcon(Content content, int iconSize) {

        InputStream inputStream = null;
        try {
            inputStream = new ReadContentInputStream(content);
            BufferedImage bi = ImageIO.read(inputStream);
            if (bi == null) {
                logger.log(Level.WARNING, "No image reader for file: " + content.getName()); //NON-NLS
                return null;
            }
View Full Code Here

Examples of org.sleuthkit.datamodel.ReadContentInputStream

        int processedItems = 0;

        String compressMethod = null;
        boolean progressStarted = false;
        try {
            stream = new SevenZipContentReadStream(new ReadContentInputStream(archiveFile));

            // for RAR files we need to open them explicitly as RAR. Otherwise, if there is a ZIP archive inside RAR archive
            // it will be opened incorrectly when using 7zip's built-in auto-detect functionality.
            // All other archive formats are still opened using 7zip built-in auto-detect functionality.
            ArchiveFormat options = get7ZipOptions(archiveFile);           
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.