本文整理汇总了Java中org.rmatil.sync.persistence.exceptions.InputOutputException类的典型用法代码示例。如果您正苦于以下问题:Java InputOutputException类的具体用法?Java InputOutputException怎么用?Java InputOutputException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
InputOutputException类属于org.rmatil.sync.persistence.exceptions包,在下文中一共展示了InputOutputException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: execute
import org.rmatil.sync.persistence.exceptions.InputOutputException; //导入依赖的package包/类
@Override
public void execute() {
try {
PublicKey publicKey = this.nodeManager.getPublicKey(this.user.getUserName());
PrivateKey privateKey = this.nodeManager.getPrivateKey(this.user);
Output.println("Public Key");
if (null != publicKey) {
Output.printKey(publicKey);
} else {
Output.println("null");
}
if (null != privateKey) {
Output.printKey(privateKey);
} else {
Output.println("null");
}
} catch (InputOutputException e) {
Output.println("Failed to fetch public/private key: " + e.getMessage() + ". Please try again");
}
}
示例2: addSharer
import org.rmatil.sync.persistence.exceptions.InputOutputException; //导入依赖的package包/类
@Override
public synchronized void addSharer(String username, AccessType accessType, String pathToFile)
throws InputOutputException {
String fileNameHash = Hash.hash(Config.DEFAULT.getHashingAlgorithm(), pathToFile);
String firstSharingHistoryEntry = Hash.hash(Config.DEFAULT.getHashingAlgorithm(), accessType.name());
List<String> sharingHistory = new ArrayList<>();
sharingHistory.add(firstSharingHistoryEntry);
Sharer sharer = new Sharer(
username,
accessType,
sharingHistory
);
PathObject pathObject = this.objectManager.getObject(fileNameHash);
pathObject.setIsShared(true);
pathObject.getSharers().add(sharer);
this.objectManager.writeObject(pathObject);
}
示例3: ObjectManager
import org.rmatil.sync.persistence.exceptions.InputOutputException; //导入依赖的package包/类
public ObjectManager(String indexFileName, String objectDirName, ITreeStorageAdapter storageAdapter)
throws InputOutputException {
this.storageAdapter = storageAdapter;
this.indexFileName = indexFileName;
this.objectDirName = objectDirName;
TreePathElement indexPath = new TreePathElement(this.indexFileName);
try {
// create the index from the stored file
logger.trace("Trying to read from existing index file");
byte[] content = this.storageAdapter.read(indexPath);
String json = new String(content, StandardCharsets.UTF_8);
this.index = Index.fromJson(json);
} catch (InputOutputException e) {
// the file does not exist yet, so we have to create it
logger.error(e.getMessage());
logger.info("Creating the index file at " + this.indexFileName);
this.index = new Index(new HashMap<>());
this.storageAdapter.persist(StorageType.FILE, indexPath, this.index.toJson().getBytes());
}
}
示例4: clear
import org.rmatil.sync.persistence.exceptions.InputOutputException; //导入依赖的package包/类
@Override
public synchronized void clear()
throws InputOutputException {
TreePathElement objectPath = new TreePathElement(this.objectDirName);
TreePathElement indexPath = new TreePathElement(this.indexFileName);
// delete all objects
if (this.storageAdapter.exists(StorageType.DIRECTORY, objectPath)) {
this.storageAdapter.delete(objectPath);
} else {
logger.info("Could not remove object folder (No such file or directory)");
}
// recreate empty index
this.index = new Index(new HashMap<>());
this.storageAdapter.persist(StorageType.FILE, indexPath, this.index.toJson().getBytes());
}
示例5: writeObject
import org.rmatil.sync.persistence.exceptions.InputOutputException; //导入依赖的package包/类
@Override
public synchronized void writeObject(PathObject path)
throws InputOutputException {
logger.trace("Writing path object for file " + path.getAbsolutePath());
String fileNameHash = Hash.hash(Config.DEFAULT.getHashingAlgorithm(), path.getAbsolutePath());
this.index.addPath(path.getAbsolutePath(), fileNameHash);
logger.trace("Calculated hash for file name: " + fileNameHash);
String pathToObject = this.createObjectDirIfNotExists(fileNameHash);
TreePathElement indexPath = new TreePathElement(this.indexFileName);
TreePathElement objectPath = new TreePathElement(pathToObject + "/" + fileNameHash + ".json");
logger.trace("Writing path object to " + objectPath.getPath());
logger.trace("Writing index to " + indexPath.getPath());
this.storageAdapter.persist(StorageType.FILE, objectPath, path.toJson().getBytes());
this.storageAdapter.persist(StorageType.FILE, indexPath, this.index.toJson().getBytes());
}
示例6: removeObject
import org.rmatil.sync.persistence.exceptions.InputOutputException; //导入依赖的package包/类
@Override
public synchronized void removeObject(String fileNameHash)
throws InputOutputException {
String pathToHash = this.getAbsolutePathToHash(fileNameHash);
PathObject pathObjectToDelete = this.getObject(fileNameHash);
logger.trace("Removing path object for file " + pathObjectToDelete.getAbsolutePath());
TreePathElement objectPath = new TreePathElement(pathToHash);
TreePathElement indexPath = new TreePathElement(this.indexFileName);
// remove object file, i.e. the file containing versions, ...
if (this.storageAdapter.exists(StorageType.FILE, objectPath)) {
logger.trace("Removing old path object " + objectPath.getPath());
this.storageAdapter.delete(objectPath);
}
logger.trace("Removing file from index...");
this.index.removePath(pathObjectToDelete.getAbsolutePath());
this.storageAdapter.persist(StorageType.FILE, indexPath, this.index.toJson().getBytes());
logger.trace("Rewriting index after removing of file " + pathObjectToDelete.getAbsolutePath());
}
示例7: createObjectDirIfNotExists
import org.rmatil.sync.persistence.exceptions.InputOutputException; //导入依赖的package包/类
protected synchronized String createObjectDirIfNotExists(String hash)
throws InputOutputException {
String prefix = hash.substring(0, 2);
String postfix = hash.substring(2);
TreePathElement objectDir = new TreePathElement(this.objectDirName);
if (! this.storageAdapter.exists(StorageType.DIRECTORY, objectDir)) {
this.storageAdapter.persist(StorageType.DIRECTORY, objectDir, null);
}
TreePathElement prefixDir = new TreePathElement(this.objectDirName + "/" + prefix);
TreePathElement postfixDir = new TreePathElement(this.objectDirName + "/" + prefix + "/" + postfix);
if (! this.storageAdapter.exists(StorageType.DIRECTORY, prefixDir)) {
this.storageAdapter.persist(StorageType.DIRECTORY, prefixDir, null);
}
if (! this.storageAdapter.exists(StorageType.DIRECTORY, postfixDir)) {
this.storageAdapter.persist(StorageType.DIRECTORY, postfixDir, null);
}
return this.objectDirName + "/" + prefix + "/" + postfix;
}
示例8: addVersion
import org.rmatil.sync.persistence.exceptions.InputOutputException; //导入依赖的package包/类
public synchronized void addVersion(Version version, String pathToFile)
throws InputOutputException {
String fileNameHash = Hash.hash(Config.DEFAULT.getHashingAlgorithm(), pathToFile);
PathObject pathObject = this.objectManager.getObject(fileNameHash);
if (! pathObject.getVersions().isEmpty()) {
// only add a version if the last is not the same
Version lastVersion = pathObject.getVersions().get(Math.max(0, pathObject.getVersions().size() - 1));
if (! lastVersion.getHash().equals(version.getHash())) {
pathObject.getVersions().add(version);
}
} else {
pathObject.getVersions().add(version);
}
this.objectManager.writeObject(pathObject);
}
示例9: onCreateFile
import org.rmatil.sync.persistence.exceptions.InputOutputException; //导入依赖的package包/类
@Override
public void onCreateFile(String relativePath, String contentHash)
throws InputOutputException {
logger.debug("Creating object for " + relativePath);
TreePathElement element = new TreePathElement(relativePath);
PathType pathType = null;
if (this.folderStorageAdapter.isDir(element)) {
pathType = PathType.DIRECTORY;
} else if (this.folderStorageAdapter.isFile(element)) {
pathType = PathType.FILE;
}
this.onCreateFile(relativePath, pathType, contentHash);
}
示例10: onRemoveFile
import org.rmatil.sync.persistence.exceptions.InputOutputException; //导入依赖的package包/类
@Override
public void onRemoveFile(String relativePath)
throws InputOutputException {
logger.debug("Removing object for " + relativePath);
// just setting the deleted flag
PathObject object = this.objectManager.getObject(Hash.hash(Config.DEFAULT.getHashingAlgorithm(), relativePath));
PathObject deletedObject = new PathObject(
object.getName(),
Naming.getPathWithoutFileName(object.getName(), relativePath),
object.getPathType(),
object.getAccessType(),
object.isShared(),
object.getDeleted(),
null, // reset
new HashSet<>(), // reset
object.getVersions()
);
this.objectManager.writeObject(deletedObject);
this.deleteManager.setIsDeleted(relativePath);
}
示例11: onMoveFile
import org.rmatil.sync.persistence.exceptions.InputOutputException; //导入依赖的package包/类
@Override
public void onMoveFile(String oldRelativePath, String newRelativePath)
throws InputOutputException {
logger.debug("Moving object for " + oldRelativePath);
PathObject oldObject = this.objectManager.getObject(Hash.hash(Config.DEFAULT.getHashingAlgorithm(), oldRelativePath));
PathObject newObject = new PathObject(
oldObject.getName(),
Naming.getPathWithoutFileName(oldObject.getName(), newRelativePath),
oldObject.getPathType(),
oldObject.getAccessType(),
oldObject.isShared(),
oldObject.getDeleted(),
oldObject.getOwner(),
oldObject.getSharers(),
oldObject.getVersions()
);
this.objectManager.writeObject(newObject);
this.objectManager.removeObject(Hash.hash(Config.DEFAULT.getHashingAlgorithm(), oldRelativePath));
}
示例12: addChange
import org.rmatil.sync.persistence.exceptions.InputOutputException; //导入依赖的package包/类
protected synchronized void addChange(String pathToFile, DeleteType deleteType)
throws InputOutputException {
PathObject pathObject = this.objectManager.getObjectForPath(pathToFile);
pathObject.getDeleted().setDeleteType(deleteType);
List<String> deleteHistory = pathObject.getDeleted().getDeleteHistory();
String nextDeleteHistoryEntry = "";
for (String entry : deleteHistory) {
nextDeleteHistoryEntry = Hash.hash(Config.DEFAULT.getHashingAlgorithm(), nextDeleteHistoryEntry + entry);
}
// add latest change too
nextDeleteHistoryEntry = Hash.hash(Config.DEFAULT.getHashingAlgorithm(), nextDeleteHistoryEntry + deleteType.name());
deleteHistory.add(nextDeleteHistoryEntry);
this.objectManager.writeObject(pathObject);
}
示例13: testVersionManager
import org.rmatil.sync.persistence.exceptions.InputOutputException; //导入依赖的package包/类
@Test
public void testVersionManager()
throws IOException, InputOutputException {
// test constructor
String expectedJson = "{\n" +
" \"paths\": {}\n" +
"}";
byte[] content = Files.readAllBytes(ROOT_TEST_DIR.resolve(objectManager.getIndexFileName()));
String json = new String(content, StandardCharsets.UTF_8);
assertEquals("Json content is not the same", expectedJson, json);
// wait a bit for the file creation
try {
Thread.sleep(1000L);
} catch (InterruptedException e) {
e.printStackTrace();
}
// now let's create another version manager for the same root test dir
// which then should read the index from the created file again
ObjectManager objectManager2 = new ObjectManager("index.json", "objects", new LocalStorageAdapter(ROOT_TEST_DIR));
}
示例14: testGetChildren
import org.rmatil.sync.persistence.exceptions.InputOutputException; //导入依赖的package包/类
@Test
public void testGetChildren()
throws InputOutputException {
objectManager.writeObject(pathObject);
PathObject dirObject = new PathObject("dir", "somePath/to", PathType.DIRECTORY, AccessType.WRITE, false, new Delete(null, new ArrayList<>()), null, new HashSet<>(), new ArrayList<>());
objectManager.writeObject(dirObject);
List<PathObject> children = objectManager.getChildren("somePath/to/dir");
assertFalse("Children contain a path", children.isEmpty());
assertEquals("Children contain only one path", 1, children.size());
assertEquals("PathObject is not equal", pathObject.toJson(), children.get(0).toJson());
objectManager.removeObject(Hash.hash(Config.DEFAULT.getHashingAlgorithm(), dirObject.getAbsolutePath()));
objectManager.removeObject(Hash.hash(Config.DEFAULT.getHashingAlgorithm(), pathObject.getAbsolutePath()));
}
示例15: testOnCreateFile
import org.rmatil.sync.persistence.exceptions.InputOutputException; //导入依赖的package包/类
@Test
public void testOnCreateFile()
throws IOException, InterruptedException, InputOutputException {
if (! Files.exists(testFile)) {
Files.createFile(testFile);
}
// wait a bit for file creation
Thread.sleep(100L);
objectStore1.onCreateFile(ROOT_TEST_DIR.relativize(testFile).toString(), "myHash");
PathObject pathObject = objectStore1.getObjectManager().getObject(Hash.hash(Config.DEFAULT.getHashingAlgorithm(), testFile.getFileName().toString()));
assertEquals("Name is not equal", testFile.getFileName().toString(), pathObject.getName());
assertEquals("Versions are not present", 1, pathObject.getVersions().size());
assertEquals("Hash is not equal", "myHash", pathObject.getVersions().get(0).getHash());
assertEquals("PathType is not a file ", PathType.FILE, pathObject.getPathType());
assertTrue("Index does not contain file", objectStore1.getObjectManager().getIndex().getPaths().containsKey(ROOT_TEST_DIR.relativize(testFile).toString()));
}