@Override public Path write(Path path, byte[] bytes, OpenOption... options) throws IOException, UnsupportedOperationException, SecurityException { if (!authManager.authorize(toResource(path), getUser())) { throw new SecurityException(); } return service.write(path, bytes); }
@Override public Path save(final Path resource, final ModuleRepositories moduleRepositories, final String comment) { try { ioService.write(Paths.convert(resource), contentHandler.toString(moduleRepositories)); return resource; } catch (Exception e) { throw ExceptionUtilities.handleException(e); } }
@Override public Path save(final Path resource, final ProjectRepositories projectRepositories, final String comment) { try { ioService.write(Paths.convert(resource), contentHandler.toString(projectRepositories)); return resource; } catch (Exception e) { throw ExceptionUtilities.handleException(e); } }
private void save(final Path path, final POM content) throws IOException, XmlPullParserException { ioService.write(Paths.convert(path), pomContentHandler.toString(content, loadPomXMLString(path))); } }
public void createModuleWhiteList(final Path packageNamesWhiteListPath) { if (ioService.exists(Paths.convert(packageNamesWhiteListPath))) { throw new FileAlreadyExistsException(packageNamesWhiteListPath.toString()); } else { ioService.write(Paths.convert(packageNamesWhiteListPath), ""); } }
protected void store(org.uberfire.java.nio.file.Path path, byte[] content) { try { ioService.startBatch(path.getFileSystem()); ioService.write(path, content); } finally { ioService.endBatch(); } }
@Override public void saveGridPreferences(GridPreferencesStore preferences) { Path preferencesPath = userServicesBackend.buildPath(identity.getIdentifier(), "datagrid-preferences", preferences.getGlobalPreferences().getKey()); ioServiceConfig.write(preferencesPath, xs.toXML(preferences)); }
protected void writeFile(final IOService ioService, final Path path, final FileItem uploadedItem) throws IOException { try { ioService.startBatch(path.getFileSystem()); ioService.write(path, IOUtils.toByteArray(uploadedItem.getInputStream())); } finally { uploadedItem.getInputStream().close(); ioService.endBatch(); } }
@Test public void testWrite() { final String content = "some-content-goes-here"; tested.write(ROOT_PATH, content); verify(ioService, times(1)) .write(any(org.uberfire.java.nio.file.Path.class), eq(content)); }
public void saveProjectImports(final Path path) { if (ioService.exists(Paths.convert(path))) { throw new FileAlreadyExistsException(path.toString()); } else { ioService.write(Paths.convert(path), projectConfigurationContentHandler.toString(createProjectImports())); } }
private Path writeFile(final String fileName) { final Path path = getBasePath(this.getClass().getSimpleName()).resolve(fileName); ioService().write(path, "content", Collections.<OpenOption>emptySet()); return path; } }
@Override public Path save(Path path, FormModelerContent content, Metadata metadata, String comment) { ioService.write(Paths.convert(path), formDefinitionSerializer.serialize(content.getDefinition()), metadataService.setUpAttributes(path, metadata), commentedOptionFactory.makeCommentedOption(comment)); return path; }
@Test public void testProjectImportsLoad_NotExists() throws URISyntaxException { when(ioService.exists(any(org.uberfire.java.nio.file.Path.class))).thenReturn(false); final ProjectImports projectImports = projectImportsService.load(pathToImports); verify(ioService, times(1)).write(any(org.uberfire.java.nio.file.Path.class), importsArgumentCaptor.capture()); assertExternalDataObjects(importsArgumentCaptor.getValue()); // projects imports need always to contain java.lang.Number // because of the guided rule editor assertTrue(projectImports.getImports().contains(new Import(Number.class))); }
private void updateLastIndexFile( Path directory, String lastIndex ) { Path lastFileIndex = directory.resolve( Constants.LAST_FILE_INDEX.name() ); try { getIoService().startBatch( lastFileIndex.getFileSystem() ); getIoService().write( lastFileIndex, lastIndex ); } finally { getIoService().endBatch(); } }
@Override protected FormDefinition createModelFormDefinition(String modelType, GenerationContext<Path> context) { FormDefinition form = super.createModelFormDefinition(modelType, context); org.uberfire.java.nio.file.Path path = Paths.convert(context.getSource()).getParent().resolve(form.getName() + "." + FormResourceTypeDefinition.EXTENSION); ioService.write(path, formSerializer.serialize(form), commentedOptionFactory.makeCommentedOption("Automatically generated form")); return form; }
@Test(expected = FileAlreadyExistsException.class) public void copyFileAlreadyExistsException() { final Path path = getDirectoryPath().resolveSibling("alreadyExistsTest"); ioService().deleteIfExists(path); ioService().createDirectories(path); ioService().write(path.resolve("myFile.txt"), "ooooo!"); ioService().write(path.resolve("mytarget"), "xooooo!"); ioService().copy(path.resolve("myFile.txt"), path.resolve("mytarget")); }
@Test public void testReadAllStringFromExistentFile() { final Path filePath = getFilePath(); ioService().createFile(filePath); ioService().write(filePath, "text"); String content = ioService().readAllString(filePath); assertEquals("text", content); }
@Test(expected = FileAlreadyExistsException.class) public void newByteChannelFileAlreadyExistsException() { final Path path = getFilePath().resolveSibling("alreadyExists.txt"); ioService().deleteIfExists(path); ioService().write(path, "ooooo!"); ioService().newByteChannel(path); }
@Test(expected = DirectoryNotEmptyException.class) public void deleteDirectoryNotEmptyException() { final Path path = getDirectoryPath().resolveSibling("dirToBug"); ioService().createDirectories(path); ioService().write(path.resolve("myFile.txt"), "ooooo!"); ioService().delete(path); }
@Test(expected = DirectoryNotEmptyException.class) public void deleteIfExistsDirectoryNotEmptyException() { final Path path = getDirectoryPath().resolveSibling("dirToBugIfExists"); ioService().createDirectories(path); ioService().write(path.resolve("myFile.txt"), "ooooo!"); ioService().deleteIfExists(path); }