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;
56 private static final SimpleDateFormat
dateFormatter =
new SimpleDateFormat(
"yyyy-MM-dd HH:mm:ss z");
57 private static final SimpleDateFormat
dateFormatterISO8601 =
new SimpleDateFormat(
"yyyy-MM-dd'T'HH:mm:ss'Z'");
62 public void preferenceChange(PreferenceChangeEvent evt) {
72 throw new AssertionError();
84 String time =
"0000-00-00 00:00:00";
85 if (epochSeconds != 0) {
87 dateFormatter.setTimeZone(tzone);
88 time = dateFormatter.format(
new java.util.Date(epochSeconds * 1000));
95 String time =
"0000-00-00T00:00:00Z";
96 if (epochSeconds != 0) {
98 dateFormatterISO8601.setTimeZone(tzone);
99 time = dateFormatterISO8601.format(
new java.util.Date(epochSeconds * 1000));
135 return TimeZone.getTimeZone(
"GMT");
137 final Content dataSource = c.getDataSource();
138 if ((dataSource != null) && (dataSource instanceof Image)) {
139 Image image = (Image) dataSource;
140 return TimeZone.getTimeZone(image.getTimeZone());
143 return TimeZone.getDefault();
146 }
catch (TskException ex) {
147 return TimeZone.getDefault();
153 return content.accept(systemName);
163 return cntnt.getName() +
":" + Long.toString(cntnt.getId());
186 public static <T>
long writeToFile(Content content, java.io.File outputFile,
187 ProgressHandle progress, Future<T> worker,
boolean source)
throws IOException {
188 InputStream in =
new ReadContentInputStream(content);
191 int unit = (int) (content.getSize() / 100);
194 try (FileOutputStream out =
new FileOutputStream(outputFile,
false)) {
196 int len = in.read(buffer);
199 if (worker != null && worker.isCancelled()) {
202 out.write(buffer, 0, len);
203 len = in.read(buffer);
207 if (progress != null && source && totalRead >= TO_FILE_BUFFER_SIZE) {
208 int totalProgress = (int) (totalRead / unit);
209 progress.progress(content.getName(), totalProgress);
211 }
else if (progress != null && !source) {
212 progress.progress(content.getName());
221 public static void writeToFile(Content content, java.io.File outputFile) throws IOException {
222 writeToFile(content, outputFile, null, null,
false);
237 public static long writeToFile(Content content, java.io.File outputFile,
238 Supplier<Boolean> cancelCheck)
throws IOException {
239 InputStream in =
new ReadContentInputStream(content);
242 try (FileOutputStream out =
new FileOutputStream(outputFile,
false)) {
244 int len = in.read(buffer);
246 out.write(buffer, 0, len);
248 if (cancelCheck.get()) {
251 len = in.read(buffer);
263 String name = dir.getName();
264 return name.equals(
".") || name.equals(
"..");
275 ProgressHandle progress;
276 SwingWorker<T, V> worker;
277 boolean source =
false;
292 ProgressHandle progress, SwingWorker<T, V> worker,
boolean source) {
294 this.progress = progress;
295 this.worker = worker;
296 this.source = source;
307 public static <T, V>
void extract(Content cntnt, java.io.File dest, ProgressHandle progress, SwingWorker<T, V> worker) {
315 }
catch (IOException ex) {
316 logger.log(Level.SEVERE,
317 "Trouble extracting file to " + dest.getAbsolutePath(),
327 }
catch (IOException ex) {
328 logger.log(Level.SEVERE,
329 "Trouble extracting unallocated content file to " + dest.getAbsolutePath(),
339 }
catch (IOException ex) {
340 logger.log(Level.SEVERE,
341 "Error extracting derived file to " + dest.getAbsolutePath(),
351 }
catch (IOException ex) {
352 logger.log(Level.SEVERE,
353 "Error extracting local file to " + dest.getAbsolutePath(),
365 public Void
visit(VirtualDirectory dir) {
370 String path = dest.getAbsolutePath() + java.io.File.separator
372 return new java.io.File(path);
385 int numProcessed = 0;
387 for (Content child : dir.getChildren()) {
394 if (worker != null && worker.isCancelled()) {
397 if (progress != null && source) {
398 progress.progress(child.getName(), numProcessed);
400 child.accept(childVisitor);
403 }
catch (TskException ex) {
404 logger.log(Level.SEVERE,
405 "Trouble fetching children to extract.", ex);
413 throw new UnsupportedOperationException(NbBundle.getMessage(
this.getClass(),
414 "ContentUtils.exception.msg",
415 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)