2 * Meviz - Various tools collection to work with multimedia.
3 * Copyright (C) 2012 -- 2018, 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 eu.svjatoslav.commons.file.IOHelper;
13 import org.apache.log4j.Logger;
17 public class MetadadaHelper {
19 private static final Logger logger = Logger.getLogger(MetadadaHelper.class);
22 * Load previously generated or initialize new directory metadata.
24 public static DirectoryMetadata initDirectoryMetadata(
25 final File metadataFile) {
27 if (!metadataFile.exists())
28 return new DirectoryMetadata();
32 final ObjectInputStream in = new ObjectInputStream(
33 new FileInputStream(metadataFile));
34 final DirectoryMetadata directory = (DirectoryMetadata) in
40 } catch (final Exception exception) {
41 logger.error("Cannot load existing directory metadata.",
44 return new DirectoryMetadata();
48 public static void saveDirectoryMetadata(final File persistanceFile,
49 final DirectoryMetadata directory) throws IOException {
50 // serialize directory metadata into byte array
51 final ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
53 final ObjectOutputStream out = new ObjectOutputStream(
54 byteArrayOutputStream);
55 out.writeObject(directory);
58 // store byte array into file
59 IOHelper.saveToFile(persistanceFile,
60 byteArrayOutputStream.toByteArray());