2 * Meviz - Various tools collection to work with multimedia.
3 * Copyright (C) 2012, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of version 2 of the GNU General Public License
7 * as published by the Free Software Foundation.
10 package eu.svjatoslav.meviz.htmlindexer.metadata;
12 import java.io.ByteArrayOutputStream;
14 import java.io.FileInputStream;
15 import java.io.IOException;
16 import java.io.ObjectInputStream;
17 import java.io.ObjectOutputStream;
19 import org.apache.log4j.Logger;
21 import eu.svjatoslav.commons.file.IOHelper;
23 public class MetadadaHelper {
25 public static final Logger logger = Logger.getLogger(MetadadaHelper.class);
28 * Load previously generated or initialize new directory metadata.
30 public static DirectoryMetadata initDirectoryMetadata(
31 final File metadataFile) {
33 if (!metadataFile.exists())
34 return new DirectoryMetadata();
38 final ObjectInputStream in = new ObjectInputStream(
39 new FileInputStream(metadataFile));
40 final DirectoryMetadata directory = (DirectoryMetadata) in
46 } catch (final Exception exception) {
47 logger.error("Cannot load existing directory metadata.",
50 return new DirectoryMetadata();
54 public static void saveDirectoryMetadata(final File persistanceFile,
55 final DirectoryMetadata directory) throws IOException {
56 // serialize directory metadata into byte array
57 final ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
59 final ObjectOutputStream out = new ObjectOutputStream(
60 byteArrayOutputStream);
61 out.writeObject(directory);
64 // store byte array into file
65 IOHelper.saveToFile(persistanceFile,
66 byteArrayOutputStream.toByteArray());