/** * {@inheritDoc} */ public boolean remove(String blobId) throws Exception { // the blobId is an absolute file system path FileSystemResource res = new FileSystemResource(fs, blobId); if (!res.exists()) { return false; } // delete resource and prune empty parent folders res.delete(true); return true; }
/** * {@inheritDoc} */ public void put(String blobId, InputStream in, long size) throws Exception { // the blobId is an absolute file system path FileSystemResource internalBlobFile = new FileSystemResource(fs, blobId); internalBlobFile.makeParentDirs(); OutputStream out = internalBlobFile.getOutputStream(); try { IOUtils.copy(in, out); } finally { out.close(); } }
public InputStream getStream() throws RepositoryException { try { return fsResource.getInputStream(); } catch (FileSystemException fse) { throw new RepositoryException(fsResource.getPath() + ": the specified resource does not exist", fse); } }
private CustomPrivilegeStore(FileSystemResource customPrivilegesResource) throws RepositoryException { this.customPrivilegesResource = customPrivilegesResource; try { // make sure path to resource exists if (!customPrivilegesResource.exists()) { customPrivilegesResource.makeParentDirs(); } } catch (FileSystemException e) { String error = "Internal error: Failed to access/create file system resource for custom privileges at " + customPrivilegesResource.getPath(); log.debug(error); throw new RepositoryException(error, e); } }
FileSystemResource uuidFile = new FileSystemResource( context.getFileSystem(), "/meta/rootUUID"); if (uuidFile.exists()) { InputStream in = uuidFile.getInputStream(); try { return NodeId.valueOf(IOUtils.toString(in, "US-ASCII")); uuidFile.makeParentDirs(); OutputStream out = uuidFile.getOutputStream(); try { out.write(ROOT_NODE_ID.toString().getBytes(StandardCharsets.US_ASCII));
/** * {@inheritDoc} */ public synchronized boolean exists(PropertyId id) throws ItemStateException { if (!initialized) { throw new IllegalStateException("not initialized"); } try { String propFilePath = buildPropFilePath(id); FileSystemResource propFile = new FileSystemResource(itemStateFS, propFilePath); return propFile.exists(); } catch (FileSystemException fse) { String msg = "failed to check existence of item state: " + id; log.error(msg, fse); throw new ItemStateException(msg, fse); } }
identifiersToDeleteFile = new FileSystemResource(fileSystem, FileSystem.SEPARATOR + IDENTIFIERS_TO_DELETE_FILE_KEY); && identifiersToDeleteFile.exists() && (identifiersToDeleteFile.lastModified() + (delayedDeleteSleep * 1000)) < System .currentTimeMillis()) { deleteDelayedIdentifiersTaskThread = new Thread( + identifiersToDeleteFile.getPath() + "'", e);
/** * Create a new instance of this class. * * @param session system session * @param fs file system for persisting locks * @param executor scheduled executor service for handling lock timeouts * @throws RepositoryException if an error occurs */ public LockManagerImpl( SessionImpl session, FileSystem fs, ScheduledExecutorService executor) throws RepositoryException { this.sysSession = session; this.locksFile = new FileSystemResource(fs, FileSystem.SEPARATOR + LOCKS_FILE); session.getWorkspace().getObservationManager(). addEventListener(this, Event.NODE_ADDED | Event.NODE_REMOVED, "/", true, null, null, true); try { if (locksFile.exists()) { load(); } } catch (FileSystemException e) { throw new RepositoryException("I/O error while reading locks from '" + locksFile.getPath() + "'", e); } timeoutHandler = executor.scheduleWithFixedDelay( new TimeoutHandler(), 1, 1, TimeUnit.SECONDS); }
Map<String, String> nsMapping; if (customPrivilegesResource.exists()) { InputStream in = customPrivilegesResource.getInputStream(); try { PrivilegeDefinitionReader pr = new PrivilegeDefinitionReader(in, "text/xml"); OutputStream out = customPrivilegesResource.getOutputStream(); try { PrivilegeDefinitionWriter pdw = new PrivilegeDefinitionWriter("text/xml");
private Map<Name, PrivilegeDefinition> load() throws FileSystemException, RepositoryException, ParseException, IOException { Map<Name, PrivilegeDefinition> stubs = new LinkedHashMap<Name, PrivilegeDefinition>(); if (customPrivilegesResource.exists()) { InputStream in = customPrivilegesResource.getInputStream(); try { PrivilegeDefinitionReader pr = new PrivilegeDefinitionReader(in, "text/xml"); for (PrivilegeDefinition def : pr.getPrivilegeDefinitions()) { Name privName = def.getName(); if (stubs.containsKey(privName)) { throw new RepositoryException("Duplicate entry for custom privilege with name " + privName.toString()); } stubs.put(privName, def); } } finally { in.close(); } } return stubs; }
/** * Creates a new hashmap index and loads the lookup tables from the * filesystem resource. If it does not exist yet, it will create a new one. * * @param file the filesystem resource that stores the lookup tables. * * @throws IOException if an I/O error occurs. * @throws FileSystemException if an I/O error occurs. */ public FileBasedIndex(FileSystemResource file) throws FileSystemException, IOException { this.file = file; if (!file.exists()) { file.makeParentDirs(); file.getOutputStream().close(); } load(); }
if (customNodeTypesResource.exists()) { in = customNodeTypesResource.getInputStream(); + customNodeTypesResource.getPath(); log.debug(error); throw new RepositoryException(error, fse); String error = "internal error: failed to read custom node type definitions stored in " + customNodeTypesResource.getPath(); log.debug(error); throw new RepositoryException(error, ioe); String error = "internal error: invalid custom node type definition stored in " + customNodeTypesResource.getPath(); log.debug(error); throw new RepositoryException(error, intde);
@Override protected void setUp() throws Exception { super.setUp(); resolver = ((SessionImpl) superuser); // setup the custom privilege file with cyclic references fs = ((RepositoryImpl) superuser.getRepository()).getConfig().getFileSystem(); FileSystemResource resource = new FileSystemResource(fs, "/privileges/custom_privileges.xml"); if (!resource.exists()) { resource.makeParentDirs(); } privilegeRegistry = new PrivilegeRegistry(superuser.getWorkspace().getNamespaceRegistry(), fs); }
/** * Purges the delayedDeletedFile. * * @return boolean true if it was successful otherwise false */ private boolean purgeDelayedDeleteFile() { BufferedWriter writer = null; try { writer = new BufferedWriter(new OutputStreamWriter( identifiersToDeleteFile.getOutputStream())); writer.write(""); return true; } catch (Exception e) { log.warn("I/O error while purging (stacktrace on DEBUG log level) the " + IDENTIFIERS_TO_DELETE_FILE_KEY + " file '" + identifiersToDeleteFile.getPath() + "': " + e.getMessage()); log.debug("Root cause: ", e); return false; } finally { IOUtils.closeQuietly(writer); } }
/** * Creates a new instance from a stream. * * @param fsResource the file system resource * @throws IOException */ private BLOBInResource(FileSystemResource fsResource) throws IOException { try { if (!fsResource.exists()) { throw new IOException(fsResource.getPath() + ": the specified resource does not exist"); } length = fsResource.length(); } catch (FileSystemException fse) { IOException e2 = new IOException(fsResource.getPath() + ": Error while creating value: " + fse.toString()); e2.initCause(fse); throw e2; } this.fsResource = fsResource; }
private FileSystem createFileSystem() { FileSystem fs = new MemoryFileSystem(); BufferedWriter writer = null; try { fs.createFolder("/"); FileSystemResource file = new FileSystemResource(fs, "/retention"); writer = new BufferedWriter(new OutputStreamWriter(file.getOutputStream())); writer.write(((NodeImpl) childN).getNodeId().toString()); } catch (FileSystemException e) { log.error(e.getMessage()); } catch (IOException e) { log.error(e.getMessage()); } finally { IOUtils.closeQuietly(writer); } return fs; }
public RetentionRegistryImpl(SessionImpl session, FileSystem fs) throws RepositoryException { this.session = session; this.retentionFile = new FileSystemResource(fs, FileSystem.SEPARATOR + FILE_NAME); // start listening to added/changed or removed holds and retention policies. Workspace wsp = session.getWorkspace(); // register event listener to be informed about new/removed holds and // retention policies. int types = Event.PROPERTY_ADDED | Event.PROPERTY_REMOVED | Event.PROPERTY_CHANGED; String[] ntFilter = new String[] {session.getJCRName(RetentionManagerImpl.REP_RETENTION_MANAGEABLE)}; wsp.getObservationManager().addEventListener(this, types, "/", true, null, ntFilter, false); // populate the retentionMap and the holdMap with the effective // holds and retention policies present within the content. try { readRetentionFile(); } catch (FileSystemException e) { throw new RepositoryException("Error while reading retention/holds from '" + retentionFile.getPath() + "'", e); } catch (IOException e) { throw new RepositoryException("Error while reading retention/holds from '" + retentionFile.getPath() + "'", e); } initialized = true; }
/** * {@inheritDoc} */ public FileSystemResource getResource(String blobId) throws Exception { // the blobId is an absolute file system path return new FileSystemResource(fs, blobId); } }
/** * Saves the lookup table to the filesystem resource. */ protected void save() { try { OutputStream out = file.getOutputStream(); try { Properties properties = new Properties(); for (Map.Entry<String, Integer> entry : stringToIndex.entrySet()) { properties.setProperty( entry.getKey(), entry.getValue().toString()); } properties.store(out, "string index"); } finally { out.close(); } lastModified = file.lastModified(); } catch (Exception e) { throw new IllegalStateException("Unable to store lookup table", e); } }
/** * Writes the given DataIdentifier to the delayedDeletedFile. * * @param identifier * @return boolean true if it was successful otherwise false */ private boolean writeDelayedDataIdentifier(DataIdentifier identifier) { BufferedWriter writer = null; try { File identifierFile = new File( ((LocalFileSystem) identifiersToDeleteFile.getFileSystem()).getPath(), identifiersToDeleteFile.getPath()); writer = new BufferedWriter(new FileWriter(identifierFile, true)); writer.write(identifier.toString()); return true; } catch (Exception e) { log.warn("I/O error while saving DataIdentifier (stacktrace on DEBUG log level) to '" + identifiersToDeleteFile.getPath() + "': " + e.getMessage()); log.debug("Root cause: ", e); return false; } finally { IOUtils.closeQuietly(writer); } }