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.logging.Level;
28 import java.util.prefs.PreferenceChangeEvent;
29 import java.util.prefs.PreferenceChangeListener;
30 import javax.swing.SwingWorker;
31 import org.netbeans.api.progress.ProgressHandle;
32 import org.openide.util.NbBundle;
55 private static final SimpleDateFormat
dateFormatter =
new SimpleDateFormat(
"yyyy-MM-dd HH:mm:ss z");
56 private static final SimpleDateFormat
dateFormatterISO8601 =
new SimpleDateFormat(
"yyyy-MM-dd'T'HH:mm:ss'Z'");
61 public void preferenceChange(PreferenceChangeEvent evt) {
71 throw new AssertionError();
83 String time =
"0000-00-00 00:00:00";
84 if (epochSeconds != 0) {
86 dateFormatter.setTimeZone(tzone);
87 time = dateFormatter.format(
new java.util.Date(epochSeconds * 1000));
94 String time =
"0000-00-00T00:00:00Z";
95 if (epochSeconds != 0) {
97 dateFormatterISO8601.setTimeZone(tzone);
98 time = dateFormatterISO8601.format(
new java.util.Date(epochSeconds * 1000));
134 return TimeZone.getTimeZone(
"GMT");
136 final Content dataSource = c.getDataSource();
137 if ((dataSource != null) && (dataSource instanceof Image)) {
138 Image image = (Image) dataSource;
139 return TimeZone.getTimeZone(image.getTimeZone());
142 return TimeZone.getDefault();
145 }
catch (TskException ex) {
146 return TimeZone.getDefault();
152 return content.accept(systemName);
162 return cntnt.getName() +
":" + Long.toString(cntnt.getId());
185 public static <T>
long writeToFile(Content content, java.io.File outputFile,
186 ProgressHandle progress, Future<T> worker,
boolean source)
throws IOException {
188 InputStream in =
new ReadContentInputStream(content);
190 boolean append =
false;
191 FileOutputStream out =
new FileOutputStream(outputFile, append);
194 int unit = (int) (content.getSize() / 100);
199 int len = in.read(buffer);
202 if (worker != null && worker.isCancelled()) {
205 out.write(buffer, 0, len);
206 len = in.read(buffer);
210 if (progress != null && source && totalRead >= TO_FILE_BUFFER_SIZE) {
211 int totalProgress = (int) (totalRead / unit);
212 progress.progress(content.getName(), totalProgress);
214 }
else if (progress != null && !source) {
215 progress.progress(content.getName());
224 public static void writeToFile(Content content, java.io.File outputFile) throws IOException {
225 writeToFile(content, outputFile, null, null,
false);
232 String name = dir.getName();
233 return name.equals(
".") || name.equals(
"..");
244 ProgressHandle progress;
245 SwingWorker<T, V> worker;
246 boolean source =
false;
261 ProgressHandle progress, SwingWorker<T, V> worker,
boolean source) {
263 this.progress = progress;
264 this.worker = worker;
265 this.source = source;
276 public static <T, V>
void extract(Content cntnt, java.io.File dest, ProgressHandle progress, SwingWorker<T, V> worker) {
284 }
catch (IOException ex) {
285 logger.log(Level.SEVERE,
286 "Trouble extracting file to " + dest.getAbsolutePath(),
296 }
catch (IOException ex) {
297 logger.log(Level.SEVERE,
298 "Trouble extracting unallocated content file to " + dest.getAbsolutePath(),
308 }
catch (IOException ex) {
309 logger.log(Level.SEVERE,
310 "Error extracting derived file to " + dest.getAbsolutePath(),
320 }
catch (IOException ex) {
321 logger.log(Level.SEVERE,
322 "Error extracting local file to " + dest.getAbsolutePath(),
334 public Void
visit(VirtualDirectory dir) {
339 String path = dest.getAbsolutePath() + java.io.File.separator
341 return new java.io.File(path);
354 int numProcessed = 0;
356 for (Content child : dir.getChildren()) {
363 if (worker != null && worker.isCancelled()) {
366 if (progress != null && source) {
367 progress.progress(child.getName(), numProcessed);
369 child.accept(childVisitor);
372 }
catch (TskException ex) {
373 logger.log(Level.SEVERE,
374 "Trouble fetching children to extract.", ex);
382 throw new UnsupportedOperationException(NbBundle.getMessage(
this.getClass(),
383 "ContentUtils.exception.msg",
384 cntnt.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 boolean isDotDirectory(AbstractFile dir)