2 * Meviz - Various tools collection to work with multimedia. Author: Svjatoslav Agejenko.
3 * This project is released under Creative Commons Zero (CC0) license.
7 package eu.svjatoslav.meviz.htmlindexer.metadata;
9 import eu.svjatoslav.commons.file.IOHelper;
10 import org.apache.log4j.Logger;
14 public class MetadadaHelper {
16 private static final Logger logger = Logger.getLogger(MetadadaHelper.class);
19 * Load previously generated or initialize new directory metadata.
21 public static DirectoryMetadata initDirectoryMetadata(
22 final File metadataFile) {
24 if (!metadataFile.exists())
25 return new DirectoryMetadata();
29 final ObjectInputStream in = new ObjectInputStream(
30 new FileInputStream(metadataFile));
31 final DirectoryMetadata directory = (DirectoryMetadata) in
37 } catch (final Exception exception) {
38 logger.error("Cannot load existing directory metadata.",
41 return new DirectoryMetadata();
45 public static void saveDirectoryMetadata(final File persistanceFile,
46 final DirectoryMetadata directory) throws IOException {
47 // serialize directory metadata into byte array
48 final ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
50 final ObjectOutputStream out = new ObjectOutputStream(
51 byteArrayOutputStream);
52 out.writeObject(directory);
55 // store byte array into file
56 IOHelper.saveToFile(persistanceFile,
57 byteArrayOutputStream.toByteArray());