You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jackrabbit.apache.org by tr...@apache.org on 2013/08/10 07:53:54 UTC
svn commit: r1512568 [39/39] - in /jackrabbit/commons/filevault/trunk: ./
parent/ vault-cli/ vault-cli/src/ vault-cli/src/main/
vault-cli/src/main/appassembler/ vault-cli/src/main/assembly/
vault-cli/src/main/java/ vault-cli/src/main/java/org/ vault-cl...
Added: jackrabbit/commons/filevault/trunk/vault-vlt/src/main/java/org/apache/jackrabbit/vault/vlt/meta/xml/file/FileMetaDir.java
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault/trunk/vault-vlt/src/main/java/org/apache/jackrabbit/vault/vlt/meta/xml/file/FileMetaDir.java?rev=1512568&view=auto
==============================================================================
--- jackrabbit/commons/filevault/trunk/vault-vlt/src/main/java/org/apache/jackrabbit/vault/vlt/meta/xml/file/FileMetaDir.java (added)
+++ jackrabbit/commons/filevault/trunk/vault-vlt/src/main/java/org/apache/jackrabbit/vault/vlt/meta/xml/file/FileMetaDir.java Sat Aug 10 05:53:42 2013
@@ -0,0 +1,165 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jackrabbit.vault.vlt.meta.xml.file;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.LinkedList;
+import java.util.List;
+
+import org.apache.commons.io.FileUtils;
+import org.apache.jackrabbit.vault.util.Constants;
+import org.apache.jackrabbit.vault.util.FileInputSource;
+import org.apache.jackrabbit.vault.vlt.VltException;
+import org.apache.jackrabbit.vault.vlt.meta.MetaDirectory;
+import org.apache.jackrabbit.vault.vlt.meta.MetaFile;
+import org.apache.jackrabbit.vault.vlt.meta.VltEntries;
+import org.apache.jackrabbit.vault.vlt.meta.xml.XmlEntries;
+
+/**
+ * <code>FileMetaDir</code>...
+ */
+public class FileMetaDir implements MetaDirectory {
+
+ public static final String ADDRESS_FILE_NAME = "repository.url";
+
+ public static final String BASE_DIR_NAME = "base";
+
+ public static final String TMP_DIR_NAME = "tmp";
+
+ public static final String ENTRIES_FILE_NAME = "entries.xml";
+
+ private final File dir;
+
+ private final File tmpDir;
+
+ private final File baseDir;
+
+ private final File entriesFile;
+
+ private XmlEntries entries;
+
+ public FileMetaDir(File dir) {
+ this.dir = dir;
+ this.tmpDir = new File(dir, TMP_DIR_NAME);
+ this.baseDir = new File(dir, BASE_DIR_NAME);
+ this.entriesFile = new File(dir, ENTRIES_FILE_NAME);
+ }
+
+ public boolean exists() {
+ return dir.exists();
+ }
+
+ public void create(String path) throws IOException {
+ if (!dir.exists()) {
+ dir.mkdirs();
+ entries = new XmlEntries(path, true);
+ sync();
+ }
+ }
+
+ public void delete() throws IOException {
+ FileUtils.deleteDirectory(dir);
+ }
+
+ public File getFile() {
+ return dir;
+ }
+
+
+ public String getRepositoryUrl() throws IOException {
+ File mpFile = new File(dir, ADDRESS_FILE_NAME);
+ if (!mpFile.canRead()) {
+ return null;
+ }
+ List lines = FileUtils.readLines(mpFile, Constants.ENCODING);
+ if (lines.isEmpty()) {
+ throw new IOException(mpFile.getPath() + " is empty.");
+ }
+ return (String) lines.get(0);
+ }
+
+ public void setRepositoryUrl(String url) throws IOException {
+ File mpFile = new File(dir, ADDRESS_FILE_NAME);
+ List<String> lines = new LinkedList<String>();
+ lines.add(url);
+ FileUtils.writeLines(mpFile, lines, Constants.ENCODING);
+ }
+
+ public VltEntries getEntries() throws VltException {
+ if (entries == null) {
+ if (entriesFile.exists()) {
+ entries = XmlEntries.load(new FileInputSource(entriesFile));
+ }
+ }
+ return entries;
+ }
+
+ public MetaFile getFile(String name) throws IOException {
+ return getFile(name, false);
+ }
+
+ public MetaFile getFile(String name, boolean create) throws IOException {
+ File file = new File(dir, name);
+ if (file.exists() || create) {
+ return new FileMetaFile(this, file);
+ } else {
+ return null;
+ }
+ }
+
+ public MetaFile getTmpFile(String name, boolean create) throws IOException {
+ File file = new File(tmpDir, name);
+ if (file.exists() || create) {
+ return new FileMetaFile(this, file);
+ } else {
+ return null;
+ }
+ }
+
+ public MetaFile getBaseFile(String name, boolean create) throws IOException {
+ File file = new File(baseDir, name);
+ if (file.exists() || create) {
+ return new FileMetaFile(this, file);
+ } else {
+ return null;
+ }
+ }
+
+ public boolean hasFile(String name) throws IOException {
+ File file = new File(dir, name);
+ return file.exists();
+ }
+
+ public void delete(String name) throws IOException {
+ File file = new File(dir, name);
+ FileUtils.forceDelete(file);
+ }
+
+ public void sync() throws IOException {
+ if (entries != null) {
+ if (entries.isDirty()) {
+ entries.save(FileUtils.openOutputStream(entriesFile));
+ }
+ }
+ }
+
+ public void close() throws IOException {
+ sync();
+ }
+}
\ No newline at end of file
Added: jackrabbit/commons/filevault/trunk/vault-vlt/src/main/java/org/apache/jackrabbit/vault/vlt/meta/xml/file/FileMetaFile.java
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault/trunk/vault-vlt/src/main/java/org/apache/jackrabbit/vault/vlt/meta/xml/file/FileMetaFile.java?rev=1512568&view=auto
==============================================================================
--- jackrabbit/commons/filevault/trunk/vault-vlt/src/main/java/org/apache/jackrabbit/vault/vlt/meta/xml/file/FileMetaFile.java (added)
+++ jackrabbit/commons/filevault/trunk/vault-vlt/src/main/java/org/apache/jackrabbit/vault/vlt/meta/xml/file/FileMetaFile.java Sat Aug 10 05:53:42 2013
@@ -0,0 +1,111 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jackrabbit.vault.vlt.meta.xml.file;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.Reader;
+
+import org.apache.commons.io.FileUtils;
+import org.apache.jackrabbit.vault.util.Constants;
+import org.apache.jackrabbit.vault.util.MD5;
+import org.apache.jackrabbit.vault.vlt.meta.MetaDirectory;
+import org.apache.jackrabbit.vault.vlt.meta.MetaFile;
+
+/**
+ * <code>FileMetaFile</code>...
+ */
+public class FileMetaFile implements MetaFile {
+
+ private final FileMetaDir parent;
+
+ private File file;
+
+ public FileMetaFile(FileMetaDir parent, File file) {
+ this.parent = parent;
+ this.file = file;
+ }
+
+ public MetaDirectory getDirectory() {
+ return parent;
+ }
+
+ public String getName() {
+ return file.getName();
+ }
+
+ public InputStream getInputStream() throws IOException {
+ return FileUtils.openInputStream(file);
+ }
+
+ public Reader getReader() throws IOException {
+ return new InputStreamReader(getInputStream(), Constants.ENCODING);
+ }
+
+ public long length() {
+ return file.length();
+ }
+
+ public MD5 md5() throws IOException {
+ return MD5.digest(file);
+ }
+
+ public long lastModified() {
+ return file.lastModified();
+ }
+
+ public void delete() throws IOException {
+ FileUtils.forceDelete(file);
+ }
+
+ public File openTempFile() throws IOException {
+ if (!file.exists()) {
+ if (!file.getParentFile().exists()) {
+ file.getParentFile().mkdirs();
+ }
+ file.createNewFile();
+ }
+ return file;
+ }
+
+ public void closeTempFile(boolean discard) throws IOException {
+ // ignore
+ }
+
+ public void moveTo(MetaFile dst) throws IOException {
+ FileMetaFile dest = (FileMetaFile) dst;
+ FileUtils.copyFile(file, dest.file, true);
+ FileUtils.forceDelete(file);
+ file = dest.file;
+ }
+
+ public void copyTo(MetaFile dst) throws IOException {
+ FileMetaFile dest = (FileMetaFile) dst;
+ FileUtils.copyFile(file, dest.file, true);
+ }
+
+ public void copyTo(File dst, boolean preserveFileDate) throws IOException {
+ FileUtils.copyFile(file, dst, preserveFileDate);
+ }
+
+ public String getPath() {
+ return file.getPath();
+ }
+}
\ No newline at end of file
Added: jackrabbit/commons/filevault/trunk/vault-vlt/src/main/java/org/apache/jackrabbit/vault/vlt/meta/xml/zip/UpdateableZipFile.java
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault/trunk/vault-vlt/src/main/java/org/apache/jackrabbit/vault/vlt/meta/xml/zip/UpdateableZipFile.java?rev=1512568&view=auto
==============================================================================
--- jackrabbit/commons/filevault/trunk/vault-vlt/src/main/java/org/apache/jackrabbit/vault/vlt/meta/xml/zip/UpdateableZipFile.java (added)
+++ jackrabbit/commons/filevault/trunk/vault-vlt/src/main/java/org/apache/jackrabbit/vault/vlt/meta/xml/zip/UpdateableZipFile.java Sat Aug 10 05:53:42 2013
@@ -0,0 +1,205 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jackrabbit.vault.vlt.meta.xml.zip;
+
+import java.io.BufferedOutputStream;
+import java.io.ByteArrayInputStream;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+import java.util.zip.Deflater;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipInputStream;
+import java.util.zip.ZipOutputStream;
+
+import org.apache.commons.io.FileUtils;
+import org.apache.commons.io.IOUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Implements an updateable zip file. Please note that the java 1.5 ZipFile
+ * showed some issues when creating many files.
+ */
+public class UpdateableZipFile {
+
+ /**
+ * default logger
+ */
+ private static final Logger log = LoggerFactory.getLogger(UpdateableZipFile.class);
+
+
+ private final File file;
+
+ private Set<String> toDelete = new HashSet<String>();
+
+ private Map<String, InputStream> toUpdate = new HashMap<String, InputStream>();
+
+ private Map<String, String> toMove = new HashMap<String, String>();
+
+ public UpdateableZipFile(File file) throws IOException {
+ this.file = file;
+ }
+
+ public File getZipFile() {
+ return file;
+ }
+
+ public boolean exists() {
+ return file.exists();
+ }
+
+ public String getPath() {
+ return file.getPath();
+ }
+
+ public void delete() {
+ if (file.exists()) {
+ file.delete();
+ }
+ toDelete.clear();
+ toUpdate.clear();
+ }
+
+ public ZipEntry getEntry(String name) {
+ if (!file.exists()) {
+ return null;
+ }
+ try {
+ InputStream in = FileUtils.openInputStream(file);
+ ZipInputStream zin = new ZipInputStream(in);
+ try {
+ ZipEntry entry = zin.getNextEntry();
+ while (entry != null) {
+ if (entry.getName().equals(name)) {
+ zin.closeEntry();
+ break;
+ }
+ entry = zin.getNextEntry();
+ }
+ return entry;
+ } finally {
+ IOUtils.closeQuietly(zin);
+ IOUtils.closeQuietly(in);
+ }
+ } catch (IOException e) {
+ log.error("Error while retrieving zip entry {}: {}", name, e.toString());
+ return null;
+ }
+ }
+
+ public InputStream getInputStream(String name) throws IOException {
+ if (!file.exists()) {
+ return null;
+ }
+ InputStream in = FileUtils.openInputStream(file);
+ ZipInputStream zin = new ZipInputStream(in);
+ ZipEntry entry = zin.getNextEntry();
+ while (entry != null) {
+ if (entry.getName().equals(name)) {
+ return zin;
+ }
+ entry = zin.getNextEntry();
+ }
+ IOUtils.closeQuietly(zin);
+ IOUtils.closeQuietly(in);
+ return null;
+ }
+
+ public void delete(String name) {
+ toDelete.add(name);
+ }
+
+ public void update(String name, InputStream in) {
+ toUpdate.put(name, in);
+ }
+
+ public void update(String name, byte[] bytes) {
+ toUpdate.put(name, new ByteArrayInputStream(bytes));
+ }
+
+ public void move(String src, String dst) {
+ toMove.put(src, dst);
+ toDelete.add(dst);
+ }
+
+ public void sync() throws IOException {
+ if (toDelete.isEmpty() && toUpdate.isEmpty() && toMove.isEmpty()) {
+ return;
+ }
+ // create tmp file
+ File newZip = File.createTempFile(file.getName(), ".tmp", file.getParentFile());
+ ZipOutputStream out = new ZipOutputStream(
+ new BufferedOutputStream(new FileOutputStream(newZip)));
+ out.setLevel(Deflater.NO_COMPRESSION);
+
+ // add new files on top
+ for (Map.Entry<String, InputStream> update: toUpdate.entrySet()) {
+ ZipEntry entry = new ZipEntry(update.getKey());
+ out.putNextEntry(entry);
+ InputStream in = update.getValue();
+ copy(in, out);
+ IOUtils.closeQuietly(in);
+ }
+ // process existing zip entries
+ if (file.exists()) {
+ InputStream in = FileUtils.openInputStream(file);
+ ZipInputStream zin = new ZipInputStream(in);
+ ZipEntry entry = zin.getNextEntry();
+ while (entry != null) {
+ if (!toUpdate.containsKey(entry.getName()) && !toDelete.contains(entry.getName())) {
+ ZipEntry newEntry = entry;
+ if (toMove.containsKey(entry.getName())) {
+ newEntry = new ZipEntry(toMove.get(entry.getName()));
+ newEntry.setTime(entry.getTime());
+ //newEntry.setSize(entry.getSize());
+ }
+ out.putNextEntry(newEntry);
+ copy(zin, out);
+ }
+ entry = zin.getNextEntry();
+ }
+ IOUtils.closeQuietly(zin);
+ IOUtils.closeQuietly(in);
+ }
+ out.close();
+ toDelete.clear();
+ toUpdate.clear();
+
+ // rotate files
+ FileUtils.deleteQuietly(file);
+ FileUtils.moveFile(newZip, file);
+ }
+
+ protected static void copy(InputStream in, ZipOutputStream out) throws IOException {
+ byte[] buffer = new byte[8192];
+ int read;
+ while ((read = in.read(buffer)) >= 0) {
+ out.write(buffer, 0, read);
+ }
+ }
+
+ public void close() throws IOException {
+ sync();
+ }
+}
\ No newline at end of file
Added: jackrabbit/commons/filevault/trunk/vault-vlt/src/main/java/org/apache/jackrabbit/vault/vlt/meta/xml/zip/ZipMetaDir.java
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault/trunk/vault-vlt/src/main/java/org/apache/jackrabbit/vault/vlt/meta/xml/zip/ZipMetaDir.java?rev=1512568&view=auto
==============================================================================
--- jackrabbit/commons/filevault/trunk/vault-vlt/src/main/java/org/apache/jackrabbit/vault/vlt/meta/xml/zip/ZipMetaDir.java (added)
+++ jackrabbit/commons/filevault/trunk/vault-vlt/src/main/java/org/apache/jackrabbit/vault/vlt/meta/xml/zip/ZipMetaDir.java Sat Aug 10 05:53:42 2013
@@ -0,0 +1,165 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jackrabbit.vault.vlt.meta.xml.zip;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.List;
+
+import org.apache.commons.io.IOUtils;
+import org.apache.commons.io.output.ByteArrayOutputStream;
+import org.apache.jackrabbit.vault.util.Constants;
+import org.apache.jackrabbit.vault.vlt.VltException;
+import org.apache.jackrabbit.vault.vlt.meta.MetaDirectory;
+import org.apache.jackrabbit.vault.vlt.meta.MetaFile;
+import org.apache.jackrabbit.vault.vlt.meta.VltEntries;
+import org.apache.jackrabbit.vault.vlt.meta.xml.XmlEntries;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * <code>ZipMetaDir</code>...
+ */
+public class ZipMetaDir implements MetaDirectory {
+
+ /**
+ * default logger
+ */
+ private static final Logger log = LoggerFactory.getLogger(ZipMetaDir.class);
+
+ public static final String ADDRESS_FILE_NAME = "repository.url";
+
+ public static final String BASE_DIR_NAME = "base";
+
+ public static final String TMP_DIR_NAME = "tmp";
+
+ public static final String ENTRIES_FILE_NAME = "entries.xml";
+
+ private final UpdateableZipFile zip;
+
+ private XmlEntries entries;
+
+ public ZipMetaDir(File file) throws IOException {
+ zip = new UpdateableZipFile(file);
+ }
+
+ protected UpdateableZipFile getZip() {
+ return zip;
+ }
+
+ public File getFile() {
+ return zip.getZipFile();
+ }
+
+ public String getRepositoryUrl() throws IOException {
+ InputStream in = zip.getInputStream(ADDRESS_FILE_NAME);
+ if (in == null) {
+ return null;
+ }
+ try {
+ List lines = IOUtils.readLines(in, Constants.ENCODING);
+ if (lines.isEmpty()) {
+ throw new IOException(getFile() + ":" + ADDRESS_FILE_NAME + " is empty.");
+ }
+ return (String) lines.get(0);
+ } finally {
+ IOUtils.closeQuietly(in);
+ }
+ }
+
+ public void setRepositoryUrl(String url) throws IOException {
+ zip.update(ADDRESS_FILE_NAME, url.getBytes(Constants.ENCODING));
+ // todo: really sync here ?
+ zip.sync();
+ }
+
+
+ public boolean exists() {
+ return zip.exists();
+ }
+
+ public void create(String path) throws IOException {
+ if (!zip.exists()) {
+ entries = new XmlEntries(path, true);
+ sync();
+ }
+ }
+
+ public void delete() throws IOException {
+ zip.delete();
+ }
+
+ public VltEntries getEntries() throws VltException {
+ try {
+ if (entries == null) {
+ InputStream in = zip.getInputStream(ENTRIES_FILE_NAME);
+ if (in != null) {
+ try {
+ entries = XmlEntries.load(in);
+ } finally {
+ IOUtils.closeQuietly(in);
+ }
+ }
+ }
+ return entries;
+ } catch (IOException e) {
+ throw new VltException("Error while reading entries.", e);
+ }
+ }
+
+ public MetaFile getFile(String name) throws IOException {
+ return getFile(name, false);
+ }
+
+ public MetaFile getFile(String name, boolean create) throws IOException {
+ if (create || zip.getEntry(name) != null) {
+ return new ZipMetaFile(this, name);
+ } else {
+ return null;
+ }
+ }
+
+ public MetaFile getTmpFile(String name, boolean create) throws IOException {
+ return getFile(TMP_DIR_NAME + "/" + name, create);
+ }
+
+ public MetaFile getBaseFile(String name, boolean create) throws IOException {
+ return getFile(BASE_DIR_NAME + "/" + name, create);
+ }
+
+ public boolean hasFile(String name) throws IOException {
+ return zip.getEntry(name) != null;
+ }
+
+ public void sync() throws IOException {
+ if (entries != null) {
+ if (entries.isDirty()) {
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ entries.save(out);
+ zip.update(ENTRIES_FILE_NAME, out.toByteArray());
+ }
+ }
+ zip.sync();
+ }
+
+ public void close() throws IOException {
+ sync();
+ zip.close();
+ }
+}
\ No newline at end of file
Added: jackrabbit/commons/filevault/trunk/vault-vlt/src/main/java/org/apache/jackrabbit/vault/vlt/meta/xml/zip/ZipMetaFile.java
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault/trunk/vault-vlt/src/main/java/org/apache/jackrabbit/vault/vlt/meta/xml/zip/ZipMetaFile.java?rev=1512568&view=auto
==============================================================================
--- jackrabbit/commons/filevault/trunk/vault-vlt/src/main/java/org/apache/jackrabbit/vault/vlt/meta/xml/zip/ZipMetaFile.java (added)
+++ jackrabbit/commons/filevault/trunk/vault-vlt/src/main/java/org/apache/jackrabbit/vault/vlt/meta/xml/zip/ZipMetaFile.java Sat Aug 10 05:53:42 2013
@@ -0,0 +1,180 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jackrabbit.vault.vlt.meta.xml.zip;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.Reader;
+import java.util.zip.ZipEntry;
+
+import org.apache.commons.io.FileUtils;
+import org.apache.commons.io.IOUtils;
+import org.apache.jackrabbit.vault.util.Constants;
+import org.apache.jackrabbit.vault.util.MD5;
+import org.apache.jackrabbit.vault.vlt.meta.MetaDirectory;
+import org.apache.jackrabbit.vault.vlt.meta.MetaFile;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * <code>ZipMetaFile</code>...
+ */
+public class ZipMetaFile implements MetaFile {
+
+ /**
+ * default logger
+ */
+ private static final Logger log = LoggerFactory.getLogger(ZipMetaFile.class);
+
+ private final ZipMetaDir parent;
+
+ private final String relPath;
+
+ private final String name;
+
+ private File tmpFile;
+
+ public ZipMetaFile(ZipMetaDir parent, String relPath) {
+ this.parent = parent;
+ this.relPath = relPath;
+ this.name = relPath.substring(relPath.lastIndexOf('/') + 1);
+ }
+
+ public MetaDirectory getDirectory() {
+ return parent;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public InputStream getInputStream() throws IOException {
+ InputStream in = parent.getZip().getInputStream(relPath);
+ if (in == null) {
+ throw new FileNotFoundException(parent.getFile() + ":" + relPath);
+ }
+ return in;
+ }
+
+ public Reader getReader() throws IOException {
+ return new InputStreamReader(getInputStream(), Constants.ENCODING);
+ }
+
+ public long length() {
+ ZipEntry entry = parent.getZip().getEntry(relPath);
+ return entry == null ? -1 : entry.getSize();
+ }
+
+ public MD5 md5() throws IOException {
+ InputStream in = parent.getZip().getInputStream(relPath);
+ if (in == null) {
+ throw new FileNotFoundException(parent.getFile() + ":" + relPath);
+ }
+ try {
+ return MD5.digest(in);
+ } finally {
+ IOUtils.closeQuietly(in);
+ }
+ }
+
+ public long lastModified() {
+ ZipEntry entry = parent.getZip().getEntry(relPath);
+ return entry == null ? 0 : entry.getTime();
+ }
+
+ public void delete() throws IOException {
+ parent.getZip().delete(relPath);
+ // todo: really sync here?
+ parent.getZip().sync();
+ }
+
+ public File openTempFile() throws IOException {
+ if (tmpFile == null) {
+ File parentDir = parent.getZip().getZipFile().getParentFile();
+ tmpFile = File.createTempFile(".vlt-", ".tmp", parentDir);
+ tmpFile.createNewFile();
+ copyToSilent(tmpFile, true);
+ }
+ return tmpFile;
+ }
+
+ public void closeTempFile(boolean discard) throws IOException {
+ if (tmpFile == null) {
+ log.warn("tmp file never opened: " + parent.getFile() + ":" + relPath);
+ } else {
+ if (!discard) {
+ InputStream in = new FileInputStream(tmpFile);
+ try {
+ parent.getZip().update(relPath, in);
+ // todo: really sync here ?
+ parent.getZip().sync();
+ } finally {
+ IOUtils.closeQuietly(in);
+ }
+ }
+ FileUtils.deleteQuietly(tmpFile);
+ tmpFile = null;
+ }
+ }
+
+ public void moveTo(MetaFile dst) throws IOException {
+ ZipMetaFile dest = (ZipMetaFile) dst;
+ parent.getZip().move(relPath, dest.relPath);
+ // todo: really sync here ?
+ parent.getZip().sync();
+ }
+
+ public void copyTo(File file, boolean preserveFileDate) throws IOException {
+ if (!copyToSilent(file, preserveFileDate)) {
+ throw new FileNotFoundException(parent.getFile() + ":" + relPath);
+ }
+ }
+
+ public String getPath() {
+ return parent.getFile() + ":" + relPath;
+ }
+
+ private boolean copyToSilent(File file, boolean preserveFileDate) throws IOException {
+ InputStream in = parent.getZip().getInputStream(relPath);
+ if (in == null) {
+ return false;
+ }
+ FileOutputStream out = null;
+ try {
+ out = FileUtils.openOutputStream(file);
+ IOUtils.copy(in, out);
+ if (preserveFileDate) {
+ ZipEntry entry = parent.getZip().getEntry(relPath);
+ file.setLastModified(entry.getTime());
+ }
+ } finally {
+ IOUtils.closeQuietly(in);
+ IOUtils.closeQuietly(out);
+ }
+ return true;
+ }
+
+ public String toString() {
+ return getPath();
+ }
+}
\ No newline at end of file
Added: jackrabbit/commons/filevault/trunk/vault-vlt/src/test/java/org/apache/jackrabbit/vault/vlt/Test.java
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault/trunk/vault-vlt/src/test/java/org/apache/jackrabbit/vault/vlt/Test.java?rev=1512568&view=auto
==============================================================================
--- jackrabbit/commons/filevault/trunk/vault-vlt/src/test/java/org/apache/jackrabbit/vault/vlt/Test.java (added)
+++ jackrabbit/commons/filevault/trunk/vault-vlt/src/test/java/org/apache/jackrabbit/vault/vlt/Test.java Sat Aug 10 05:53:42 2013
@@ -0,0 +1,110 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jackrabbit.vault.vlt;
+
+import java.io.BufferedOutputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Enumeration;
+import java.util.zip.Deflater;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipFile;
+import java.util.zip.ZipOutputStream;
+
+import org.apache.commons.io.FileUtils;
+import org.apache.jackrabbit.vault.vlt.meta.xml.zip.UpdateableZipFile;
+import org.junit.Ignore;
+
+/**
+ * <code>Test</code>...
+ */
+@Ignore
+public class Test {
+
+ public static final String TEXT = "/*\n" +
+ " * Licensed to the Apache Software Foundation (ASF) under one or more\n" +
+ " * contributor license agreements. See the NOTICE file distributed with\n" +
+ " * this work for additional information regarding copyright ownership.\n" +
+ " * The ASF licenses this file to You under the Apache License, Version 2.0\n" +
+ " * (the \"License\"); you may not use this file except in compliance with\n" +
+ " * the License. You may obtain a copy of the License at\n" +
+ " *\n" +
+ " * http://www.apache.org/licenses/LICENSE-2.0\n" +
+ " *\n" +
+ " * Unless required by applicable law or agreed to in writing, software\n" +
+ " * distributed under the License is distributed on an \"AS IS\" BASIS,\n" +
+ " * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n" +
+ " * See the License for the specific language governing permissions and\n" +
+ " * limitations under the License.\n" +
+ " */\n";
+
+ public static void main(String[] args) throws IOException {
+ File testFile = new File("test.dat");
+ FileUtils.writeStringToFile(testFile, TEXT);
+
+ UpdateableZipFile testZip = new UpdateableZipFile(new File("test.zip"));
+ for (int i=0; i<100; i++) {
+ String name = testFile.getName() + i;
+ System.out.println("adding " + name);
+ testZip.update(name, new FileInputStream(testFile));
+ testZip.sync();
+ }
+ testZip.update("test.dat50", new FileInputStream(testFile));
+ testZip.delete("test.dat1");
+ testZip.close();
+ }
+
+ public static void putFile(File zip, File file, String name) throws IOException {
+ // create tmp file
+ File newZip = new File(zip.getName() + "." + System.currentTimeMillis());
+ ZipOutputStream out = new ZipOutputStream(
+ new BufferedOutputStream(new FileOutputStream(newZip)));
+ out.setLevel(Deflater.NO_COMPRESSION);
+ if (zip.exists()) {
+ ZipFile zipFile = new ZipFile(zip, ZipFile.OPEN_DELETE | ZipFile.OPEN_READ);
+ Enumeration<? extends ZipEntry> entries = zipFile.entries();
+ while (entries.hasMoreElements()) {
+ ZipEntry entry = entries.nextElement();
+ if (!entry.getName().equals(name)) {
+ out.putNextEntry(entry);
+ copy(zipFile.getInputStream(entry), out);
+ }
+ }
+ zipFile.close();
+ }
+ ZipEntry entry = new ZipEntry(name);
+ entry.setSize(file.length());
+ out.putNextEntry(entry);
+ copy(new FileInputStream(file), out);
+ out.close();
+ zip.delete();
+ newZip.renameTo(zip);
+ }
+
+ public static void copy(InputStream in, ZipOutputStream out) throws IOException {
+ byte[] buffer = new byte[8192];
+ int read;
+ while ((read = in.read(buffer)) >= 0) {
+ out.write(buffer, 0, read);
+ }
+ in.close();
+ }
+}
\ No newline at end of file
Added: jackrabbit/commons/filevault/trunk/vault-vlt/src/test/java/org/apache/jackrabbit/vault/vlt/meta/AbstractTestEntries.java
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault/trunk/vault-vlt/src/test/java/org/apache/jackrabbit/vault/vlt/meta/AbstractTestEntries.java?rev=1512568&view=auto
==============================================================================
--- jackrabbit/commons/filevault/trunk/vault-vlt/src/test/java/org/apache/jackrabbit/vault/vlt/meta/AbstractTestEntries.java (added)
+++ jackrabbit/commons/filevault/trunk/vault-vlt/src/test/java/org/apache/jackrabbit/vault/vlt/meta/AbstractTestEntries.java Sat Aug 10 05:53:42 2013
@@ -0,0 +1,123 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jackrabbit.vault.vlt.meta;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.PrintWriter;
+
+import org.apache.jackrabbit.vault.fs.api.DumpContext;
+import org.apache.jackrabbit.vault.fs.api.Dumpable;
+import org.apache.jackrabbit.vault.util.MD5;
+import org.apache.jackrabbit.vault.vlt.VltException;
+
+import junit.framework.TestCase;
+
+/**
+ * <code>TestEntries</code>...
+ */
+public abstract class AbstractTestEntries extends TestCase {
+
+ protected File file = new File("target/vlt-test-entries.zip");
+
+ private boolean verbose;
+
+ protected MetaDirectory dir;
+
+ protected VltEntries entries;
+
+ abstract protected void open() throws IOException, VltException;
+
+ protected void close() throws IOException {
+ if (entries != null) {
+ entries = null;
+ }
+ if (dir != null) {
+ dir.sync();
+ dir.close();
+ }
+ }
+
+ protected void reopen() throws IOException, VltException {
+ close();
+ open();
+ }
+
+ public void testRepoAddress() throws IOException, VltException {
+ open();
+ assertNull(dir.getRepositoryUrl());
+ dir.setRepositoryUrl("http://localhost:8080");
+ dir.sync();
+ reopen();
+ assertEquals("http://localhost:8080", dir.getRepositoryUrl());
+ }
+
+ public void testAddEntry() throws VltException, IOException {
+ open();
+ assertFalse(entries.hasEntry("foo.png"));
+ VltEntry e = entries.update("foo.png", "/bla", "foo.png");
+ reopen();
+ assertTrue(entries.hasEntry("foo.png"));
+ }
+
+ public void testAddInfo() throws VltException, IOException {
+ testAddEntry();
+
+ assertTrue(entries.hasEntry("foo.png"));
+ VltEntry e = entries.getEntry("foo.png");
+ assertNull(e.base());
+ VltEntryInfo base = e.create(VltEntryInfo.Type.BASE);
+ e.put(base);
+ reopen();
+ e = entries.getEntry("foo.png");
+ assertTrue(entries.hasEntry("foo.png"));
+ assertNotNull(e.base());
+ }
+
+ public void testModifyInfo() throws VltException, IOException {
+ testAddInfo();
+ reopen();
+
+ assertTrue(entries.hasEntry("foo.png"));
+ VltEntry e = entries.getEntry("foo.png");
+ VltEntryInfo base = e.base();
+ assertNotNull(base);
+ base.setContentType("text/plain");
+ base.setDate(1000);
+ base.setMd5(new MD5(2,3));
+ base.setSize(4);
+ reopen();
+ e = entries.getEntry("foo.png");
+ base = e.base();
+ assertEquals("text/plain", base.getContentType());
+ assertEquals(1000, base.getDate());
+ assertEquals(new MD5(2,3), base.getMd5());
+ assertEquals(4, base.getSize());
+ }
+
+ protected void tearDown() throws Exception {
+ if (entries != null && verbose) {
+ PrintWriter out = new PrintWriter(System.out);
+ out.println("----------------------------------------------------------");
+ if (entries instanceof Dumpable) {
+ ((Dumpable) entries).dump(new DumpContext(out), true);
+ }
+ out.flush();
+ }
+ }
+}
\ No newline at end of file
Added: jackrabbit/commons/filevault/trunk/vault-vlt/src/test/java/org/apache/jackrabbit/vault/vlt/meta/TestBinEntries.java
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault/trunk/vault-vlt/src/test/java/org/apache/jackrabbit/vault/vlt/meta/TestBinEntries.java?rev=1512568&view=auto
==============================================================================
--- jackrabbit/commons/filevault/trunk/vault-vlt/src/test/java/org/apache/jackrabbit/vault/vlt/meta/TestBinEntries.java (added)
+++ jackrabbit/commons/filevault/trunk/vault-vlt/src/test/java/org/apache/jackrabbit/vault/vlt/meta/TestBinEntries.java Sat Aug 10 05:53:42 2013
@@ -0,0 +1,54 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.vault.vlt.meta;
+
+import java.io.File;
+import java.io.IOException;
+
+import org.apache.jackrabbit.vault.vlt.VltException;
+import org.apache.jackrabbit.vault.vlt.meta.bin.BinMetaDir;
+
+/**
+ * <code>TextXMLEntries</code>...
+ */
+abstract public class TestBinEntries extends AbstractTestEntries {
+
+ private File file = new File("target/vlt-test-entries.zip");
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+
+ if (file.exists()) {
+ file.delete();
+ }
+ dir = new BinMetaDir(file);
+ dir.create("/a/b/c");
+ dir.close();
+ }
+
+ @Override
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ }
+
+ protected void open() throws IOException, VltException {
+ dir = new BinMetaDir(file);
+ entries = dir.getEntries();
+ }
+
+}
\ No newline at end of file
Added: jackrabbit/commons/filevault/trunk/vault-vlt/src/test/java/org/apache/jackrabbit/vault/vlt/meta/TextXMLEntries.java
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault/trunk/vault-vlt/src/test/java/org/apache/jackrabbit/vault/vlt/meta/TextXMLEntries.java?rev=1512568&view=auto
==============================================================================
--- jackrabbit/commons/filevault/trunk/vault-vlt/src/test/java/org/apache/jackrabbit/vault/vlt/meta/TextXMLEntries.java (added)
+++ jackrabbit/commons/filevault/trunk/vault-vlt/src/test/java/org/apache/jackrabbit/vault/vlt/meta/TextXMLEntries.java Sat Aug 10 05:53:42 2013
@@ -0,0 +1,55 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.vault.vlt.meta;
+
+import java.io.File;
+import java.io.IOException;
+
+import org.apache.jackrabbit.vault.vlt.VltException;
+import org.apache.jackrabbit.vault.vlt.meta.xml.zip.ZipMetaDir;
+
+/**
+ * <code>TextXMLEntries</code>...
+ */
+public class TextXMLEntries extends AbstractTestEntries {
+
+ private File file = new File("target/vlt-test-entries.zip");
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ if (file.exists()) {
+ file.delete();
+ }
+ dir = new ZipMetaDir(file);
+ dir.create("/a/b/c");
+ dir.close();
+ dir = null;
+ }
+
+ @Override
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ }
+
+ protected void open() throws IOException, VltException {
+ dir = new ZipMetaDir(file);
+ entries = dir.getEntries();
+ }
+
+
+}
\ No newline at end of file
Added: jackrabbit/commons/filevault/trunk/vault-vlt/src/test/java/org/apache/jackrabbit/vault/vlt/meta/bin/MetaFileTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault/trunk/vault-vlt/src/test/java/org/apache/jackrabbit/vault/vlt/meta/bin/MetaFileTest.java?rev=1512568&view=auto
==============================================================================
--- jackrabbit/commons/filevault/trunk/vault-vlt/src/test/java/org/apache/jackrabbit/vault/vlt/meta/bin/MetaFileTest.java (added)
+++ jackrabbit/commons/filevault/trunk/vault-vlt/src/test/java/org/apache/jackrabbit/vault/vlt/meta/bin/MetaFileTest.java Sat Aug 10 05:53:42 2013
@@ -0,0 +1,173 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jackrabbit.vault.vlt.meta.bin;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.PrintWriter;
+import java.io.StringWriter;
+
+import org.apache.commons.io.IOUtils;
+import org.apache.jackrabbit.vault.fs.api.DumpContext;
+
+import junit.framework.TestCase;
+
+/**
+ * <code>MetaFileTest</code>...
+ */
+public class MetaFileTest extends TestCase {
+
+ private PrintWriter log = new PrintWriter(System.out);
+
+ private DumpContext dump = new DumpContext(log);
+
+ private File file;
+
+ public MetaFileTest() {
+ log = new PrintWriter(new StringWriter());
+ }
+
+ protected void setUp() throws Exception {
+ file = new File("target/testFile.vlt");
+ }
+
+ public void testEmpty() throws IOException {
+ file.delete();
+ BinMetaFile m = new BinMetaFile(file);
+ HeaderBlock h = m.open();
+ h.dump(dump, false);
+ m.close();
+ }
+
+ public void testExisting() throws IOException {
+ file.delete();
+ BinMetaFile m = new BinMetaFile(file);
+ HeaderBlock h = m.open();
+ h.dump(dump, false);
+ m.close();
+
+ m = new BinMetaFile(file);
+ h = m.open();
+ h.dump(dump, false);
+ m.close();
+ }
+
+ public void testHeaderProps() throws IOException {
+ log.println("-------------------------------------------");
+ log.println("testHeaderProps()");
+ log.println("-------------------------------------------");
+ BinMetaFile m = new BinMetaFile(file);
+ HeaderBlock header = m.open();
+ PropertiesBlock pBlk = m.getLinkedBlock(header, 0, PropertiesBlock.class, true);
+ pBlk.setProperty("foo", "bar");
+ pBlk.setProperty("hello", "world");
+ m.sync();
+ m.dump(dump, false);
+ log.println("-------------------------------------------");
+ pBlk.setProperty("larum", "ipsum");
+ m.sync();
+ m.dump(dump, false);
+ m.close();
+ }
+
+ public void testNewEntry() throws IOException {
+ log.println("-------------------------------------------");
+ log.println("testNewEntry()");
+ log.println("-------------------------------------------");
+ BinMetaFile m = new BinMetaFile(file);
+ HeaderBlock header = m.open();
+ EntryBlock blk = new EntryBlock("myentry", "aggPath", "relPath");
+ m.add(blk);
+ m.sync();
+ m.dump(dump, false);
+ log.println("-------------------------------------------");
+ InfoBlock e = m.getLinkedBlock(blk, EntryBlock.ID_WORK, InfoBlock.class, true);
+ e.setContentType("text/plain");
+ m.sync();
+ m.dump(dump, false);
+ m.close();
+ }
+
+ public void testUpdateEntry() throws IOException {
+ log.println("-------------------------------------------");
+ log.println("testUpdateEntry()");
+ log.println("-------------------------------------------");
+ BinMetaFile m = new BinMetaFile(file);
+ HeaderBlock header = m.open();
+ EntryBlock blk = m.getEntryBlock("myentry");
+ InfoBlock e = m.getLinkedBlock(blk, EntryBlock.ID_WORK, InfoBlock.class, true);
+ e.setSize(1234);
+ m.sync();
+ m.dump(dump, false);
+ log.println("-------------------------------------------");
+ e.setContentType("text/html");
+ m.sync();
+ m.dump(dump, false);
+ m.close();
+ }
+
+ public void testWriteData() throws IOException {
+ log.println("-------------------------------------------");
+ log.println("testWriteData()");
+ log.println("-------------------------------------------");
+ BinMetaFile m = new BinMetaFile(file);
+ HeaderBlock header = m.open();
+ EntryBlock blk = m.getEntryBlock("myentry");
+ InfoBlock info = m.getLinkedBlock(blk, EntryBlock.ID_WORK, InfoBlock.class, true);
+ DataBlock data = m.createDataBlock("hello, world".getBytes());
+ m.linkBlock(info, InfoBlock.ID_DATA, data);
+ m.sync();
+ m.dump(dump, false);
+ m.close();
+ }
+
+ public void testReadData() throws IOException {
+ log.println("-------------------------------------------");
+ log.println("testReadData()");
+ log.println("-------------------------------------------");
+ BinMetaFile m = new BinMetaFile(file);
+ HeaderBlock header = m.open();
+ EntryBlock blk = m.getEntryBlock("myentry");
+ InfoBlock info = m.getLinkedBlock(blk, EntryBlock.ID_WORK, InfoBlock.class, true);
+ DataBlock data = m.getLinkedBlock(info, InfoBlock.ID_DATA, DataBlock.class, true);
+ String s = new String(m.getBytes(data));
+ log.println(s);
+ InputStream in = m.getInputStream(data);
+ s = IOUtils.toString(in);
+ log.println(s);
+ m.close();
+ }
+
+ public void testDeleteEntry() throws IOException {
+ log.println("-------------------------------------------");
+ log.println("testDeleteEntry()");
+ log.println("-------------------------------------------");
+ BinMetaFile m = new BinMetaFile(file);
+ HeaderBlock header = m.open();
+ EntryBlock blk = m.getEntryBlock("myentry");
+ m.delete(blk);
+ m.sync();
+ m.dump(dump, false);
+ m.close();
+ }
+
+ protected void tearDown() throws Exception {
+ log.flush();
+ }
+}
\ No newline at end of file