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;
57 private static final SimpleDateFormat
dateFormatter =
new SimpleDateFormat(
"yyyy-MM-dd HH:mm:ss z");
58 private static final SimpleDateFormat
dateFormatterISO8601 =
new SimpleDateFormat(
"yyyy-MM-dd'T'HH:mm:ss'Z'");
63 public void preferenceChange(PreferenceChangeEvent evt) {
73 throw new AssertionError();
85 String time =
"0000-00-00 00:00:00";
86 if (epochSeconds != 0) {
88 dateFormatter.setTimeZone(tzone);
89 time = dateFormatter.format(
new java.util.Date(epochSeconds * 1000));
96 String time =
"0000-00-00T00:00:00Z";
97 if (epochSeconds != 0) {
99 dateFormatterISO8601.setTimeZone(tzone);
100 time = dateFormatterISO8601.format(
new java.util.Date(epochSeconds * 1000));
136 return TimeZone.getTimeZone(
"GMT");
138 final Content dataSource = c.getDataSource();
139 if ((dataSource != null) && (dataSource instanceof Image)) {
140 Image image = (Image) dataSource;
141 return TimeZone.getTimeZone(image.getTimeZone());
144 return TimeZone.getDefault();
147 }
catch (TskException ex) {
148 return TimeZone.getDefault();
154 return content.accept(systemName);
164 return cntnt.getName() +
":" + Long.toString(cntnt.getId());
187 public static <T>
long writeToFile(Content content, java.io.File outputFile,
188 ProgressHandle progress, Future<T> worker,
boolean source)
throws IOException {
189 InputStream in =
new ReadContentInputStream(content);
192 int unit = (int) (content.getSize() / 100);
195 try (FileOutputStream out =
new FileOutputStream(outputFile,
false)) {
197 int len = in.read(buffer);
200 if (worker != null && worker.isCancelled()) {
203 out.write(buffer, 0, len);
204 len = in.read(buffer);
208 if (progress != null && source && totalRead >= TO_FILE_BUFFER_SIZE) {
209 int totalProgress = (int) (totalRead / unit);
210 progress.progress(content.getName(), totalProgress);
212 }
else if (progress != null && !source) {
213 progress.progress(content.getName());
222 public static void writeToFile(Content content, java.io.File outputFile) throws IOException {
223 writeToFile(content, outputFile, null, null,
false);
238 public static long writeToFile(Content content, java.io.File outputFile,
239 Supplier<Boolean> cancelCheck)
throws IOException {
240 InputStream in =
new ReadContentInputStream(content);
243 try (FileOutputStream out =
new FileOutputStream(outputFile,
false)) {
245 int len = in.read(buffer);
247 out.write(buffer, 0, len);
249 if (cancelCheck.get()) {
252 len = in.read(buffer);
264 String name = dir.getName();
265 return name.equals(
".") || name.equals(
"..");
276 ProgressHandle progress;
277 SwingWorker<T, V> worker;
278 boolean source =
false;
293 ProgressHandle progress, SwingWorker<T, V> worker,
boolean source) {
295 this.progress = progress;
296 this.worker = worker;
297 this.source = source;
308 public static <T, V>
void extract(Content cntnt, java.io.File dest, ProgressHandle progress, SwingWorker<T, V> worker) {
316 }
catch (IOException ex) {
317 logger.log(Level.SEVERE,
318 "Trouble extracting file to " + dest.getAbsolutePath(),
328 }
catch (IOException ex) {
329 logger.log(Level.SEVERE,
330 "Trouble extracting unallocated content file to " + dest.getAbsolutePath(),
340 }
catch (IOException ex) {
341 logger.log(Level.SEVERE,
342 "Error extracting derived file to " + dest.getAbsolutePath(),
352 }
catch (IOException ex) {
353 logger.log(Level.SEVERE,
354 "Error extracting local file to " + dest.getAbsolutePath(),
364 }
catch (IOException ex) {
365 logger.log(Level.SEVERE,
366 "Trouble extracting slack file to " + dest.getAbsolutePath(),
378 public Void
visit(VirtualDirectory dir) {
383 String path = dest.getAbsolutePath() + java.io.File.separator
385 return new java.io.File(path);
398 int numProcessed = 0;
400 for (Content child : dir.getChildren()) {
407 if (worker != null && worker.isCancelled()) {
410 if (progress != null && source) {
411 progress.progress(child.getName(), numProcessed);
413 child.accept(childVisitor);
416 }
catch (TskException ex) {
417 logger.log(Level.SEVERE,
418 "Trouble fetching children to extract.", ex);
426 throw new UnsupportedOperationException(NbBundle.getMessage(
this.getClass(),
427 "ContentUtils.exception.msg",
428 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)