Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/**
* Copyright (C) 2010 BonitaSoft S.A.
* BonitaSoft, 31 rue Gustave Eiffel - 38000 Grenoble
* This library is free software; you can redistribute it and/or modify it under the terms
* of the GNU Lesser General Public License as published by the Free Software Foundation
* version 2.1 of the License.
* This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU Lesser General Public License for more details.
* You should have received a copy of the GNU Lesser General Public License along with this
* program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
* Floor, Boston, MA 02110-1301, USA.
**/
package org.ow2.bonita.services.impl;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Properties;
import java.util.Set;
import java.util.UUID;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.ow2.bonita.services.LargeDataRepository;
import org.ow2.bonita.util.BonitaConstants;
import org.ow2.bonita.util.BonitaRuntimeException;
import org.ow2.bonita.util.ExceptionManager;
import org.ow2.bonita.util.Misc;
public class FileLargeDataRepository implements LargeDataRepository {
private static final Logger LOG = Logger.getLogger(FileLargeDataRepository.class.getName());
private final File base;
private static final Object CONSTRUCTOR_MUTEX = new Object();
private static final String INDEX_NAME = "index.txt";
@Override
public void clean() {
Misc.deleteDir(this.base, 10, 5);
createRepository();
}
@Override
public boolean isEmpty() {
return checkIsEmpty(this.base);
}
private boolean checkIsEmpty(final File dir) {
final File[] files = dir.listFiles();
if (files == null) {
return true;
}
for (final File file : files) {
if (file.isFile() && !file.getName().equals(INDEX_NAME)) {
return false;
} else if (!checkIsEmpty(file)) {
return false;
}
}
return true;
}
public FileLargeDataRepository(final String value) {
Misc.checkArgsNotNull(value);
final String property = "property:";
String path = value;
if (value.startsWith(property)) {
path = System.getProperty(value.substring(property.length()));
} else if (value.startsWith("${" + BonitaConstants.HOME + "}")) {
path = path.replace("${" + BonitaConstants.HOME + "}", System.getProperty(BonitaConstants.HOME));
}
this.base = new File(path, "bonita-large-data-repository");
if (LOG.isLoggable(Level.INFO)) {
LOG.fine("Creating " + getClass().getName() + " with base: " + this.base);
}
createRepository();
}
@Override
public boolean deleteData(final List categories, final String key) {
try {
final File file = removeFromIndex(categories, key);
if (file != null && file.exists()) {
int counter = 0;
while (!file.delete() && counter < 50) {
counter++;
try {
Thread.sleep(10);
} catch (final InterruptedException e) {
// nothing
}
}
} else {
return false;
}
} catch (final IOException e) {
throw new BonitaRuntimeException(e);
}
return true;
}
@Override
public boolean deleteData(final List categories) {
final File dir = getPath(categories, false);
if (dir != null && dir.exists()) {
Misc.deleteDir(dir, 10, 5);
if (!dir.exists()) {
return true;
}
}
return false;
}
@Override
public T getData(final Class clazz, final List categories, final String key) {
try {
final File file = getFromIndex(categories, key);
if (file == null || !file.exists()) {
return null;
}
return getData(clazz, file);
} catch (final IOException e) {
throw new BonitaRuntimeException(e);
}
}
@Override
public Set getKeys(final List categories, final String regex) {
final File dir = getPath(categories, false);
if (dir == null || !dir.exists()) {
return Collections.emptySet();
}
try {
final File index = getIndex(categories);
synchronized (index.getAbsolutePath()) {
final Properties properties = loadIndex(index);
final Enumeration