19 package org.sleuthkit.autopsy.datamodel;
21 import java.io.FileOutputStream;
22 import java.io.IOException;
23 import java.io.InputStream;
24 import java.text.SimpleDateFormat;
25 import java.util.TimeZone;
26 import java.util.concurrent.Future;
27 import java.util.function.Supplier;
28 import java.util.logging.Level;
29 import java.util.prefs.PreferenceChangeEvent;
30 import java.util.prefs.PreferenceChangeListener;
31 import javax.swing.SwingWorker;
32 import org.netbeans.api.progress.ProgressHandle;
33 import org.openide.util.NbBundle;
58 private static final SimpleDateFormat
dateFormatter =
new SimpleDateFormat(
"yyyy-MM-dd HH:mm:ss z");
59 private static final SimpleDateFormat
dateFormatterISO8601 =
new SimpleDateFormat(
"yyyy-MM-dd'T'HH:mm:ss'Z'");
64 public void preferenceChange(PreferenceChangeEvent evt) {
74 throw new AssertionError();
86 String time =
"0000-00-00 00:00:00";
87 if (epochSeconds != 0) {
89 dateFormatter.setTimeZone(tzone);
90 time = dateFormatter.format(
new java.util.Date(epochSeconds * 1000));
97 String time =
"0000-00-00T00:00:00Z";
98 if (epochSeconds != 0) {
100 dateFormatterISO8601.setTimeZone(tzone);
101 time = dateFormatterISO8601.format(
new java.util.Date(epochSeconds * 1000));
137 return TimeZone.getTimeZone(
"GMT");
139 final Content dataSource = c.getDataSource();
140 if ((dataSource != null) && (dataSource instanceof Image)) {
141 Image image = (Image) dataSource;
142 return TimeZone.getTimeZone(image.getTimeZone());
145 return TimeZone.getDefault();
148 }
catch (TskCoreException ex) {
149 return TimeZone.getDefault();
155 return content.accept(systemName);
165 return cntnt.getName() +
":" + Long.toString(cntnt.getId());
188 public static <T>
long writeToFile(Content content, java.io.File outputFile,
189 ProgressHandle progress, Future<T> worker,
boolean source)
throws IOException {
190 InputStream in =
new ReadContentInputStream(content);
193 int unit = (int) (content.getSize() / 100);
196 try (FileOutputStream out =
new FileOutputStream(outputFile,
false)) {
198 int len = in.read(buffer);
201 if (worker != null && worker.isCancelled()) {
204 out.write(buffer, 0, len);
205 len = in.read(buffer);
209 if (progress != null && source && totalRead >= TO_FILE_BUFFER_SIZE) {
210 int totalProgress = (int) (totalRead / unit);
211 progress.progress(content.getName(), totalProgress);
213 }
else if (progress != null && !source) {
214 progress.progress(content.getName());
223 public static void writeToFile(Content content, java.io.File outputFile) throws IOException {
224 writeToFile(content, outputFile, null, null,
false);
239 public static long writeToFile(Content content, java.io.File outputFile,
240 Supplier<Boolean> cancelCheck)
throws IOException {
241 InputStream in =
new ReadContentInputStream(content);
244 try (FileOutputStream out =
new FileOutputStream(outputFile,
false)) {
246 int len = in.read(buffer);
248 out.write(buffer, 0, len);
250 if (cancelCheck.get()) {
253 len = in.read(buffer);
267 String name = dir.getName();
268 return name.equals(
".") || name.equals(
"..");
279 ProgressHandle progress;
280 SwingWorker<T, V> worker;
281 boolean source =
false;
296 ProgressHandle progress, SwingWorker<T, V> worker,
boolean source) {
298 this.progress = progress;
299 this.worker = worker;
300 this.source = source;
311 public static <T, V>
void extract(Content cntnt, java.io.File dest, ProgressHandle progress, SwingWorker<T, V> worker) {
319 }
catch (IOException ex) {
320 logger.log(Level.SEVERE,
321 "Trouble extracting file to " + dest.getAbsolutePath(),
331 }
catch (IOException ex) {
332 logger.log(Level.SEVERE,
333 "Trouble extracting unallocated content file to " + dest.getAbsolutePath(),
343 }
catch (IOException ex) {
344 logger.log(Level.SEVERE,
345 "Error extracting derived file to " + dest.getAbsolutePath(),
355 }
catch (IOException ex) {
356 logger.log(Level.SEVERE,
357 "Error extracting local file to " + dest.getAbsolutePath(),
367 }
catch (IOException ex) {
368 logger.log(Level.SEVERE,
369 "Trouble extracting slack file to " + dest.getAbsolutePath(),
381 public Void
visit(VirtualDirectory dir) {
386 public Void
visit(LocalDirectory dir) {
391 String path = dest.getAbsolutePath() + java.io.File.separator
393 return new java.io.File(path);
406 int numProcessed = 0;
408 for (Content child : dir.getChildren()) {
409 if (child instanceof AbstractFile){
416 if (worker != null && worker.isCancelled()) {
419 if (progress != null && source) {
420 progress.progress(child.getName(), numProcessed);
422 child.accept(childVisitor);
426 }
catch (TskCoreException ex) {
427 logger.log(Level.SEVERE,
428 "Trouble fetching children to extract.", ex);
436 throw new UnsupportedOperationException(NbBundle.getMessage(
this.getClass(),
437 "ContentUtils.exception.msg",
438 content.getClass().getSimpleName()));
static String getStringTime(long epochSeconds, TimeZone tzone)
static final SimpleDateFormat dateFormatter
String defaultVisit(Content cntnt)
static boolean shouldDisplayTimesInLocalTime()
static final Logger logger
static< T > long writeToFile(Content content, java.io.File outputFile, ProgressHandle progress, Future< T > worker, boolean source)
static final int TO_FILE_BUFFER_SIZE
static String getSystemName(Content content)
static String getStringTimeISO8601(long epochSeconds, TimeZone tzone)
static final SimpleDateFormat dateFormatterISO8601
static final String DISPLAY_TIMES_IN_LOCAL_TIME
static final SystemNameVisitor systemName
static String getStringTime(long epochSeconds, Content c)
synchronized static Logger getLogger(String name)
static String getStringTimeISO8601(long epochSeconds, Content c)
static void addChangeListener(PreferenceChangeListener listener)
static boolean displayTimesInLocalTime
static TimeZone getTimeZone(Content c)
static void writeToFile(Content content, java.io.File outputFile)
static boolean displayTimesInLocalTime()
static long writeToFile(Content content, java.io.File outputFile, Supplier< Boolean > cancelCheck)
static boolean isDotDirectory(AbstractFile dir)