@Override public OutputStream newOutputStream(Path path, OpenOption... options) throws IllegalArgumentException, UnsupportedOperationException, IOException, SecurityException { if (!authManager.authorize(toResource(path), getUser())) { throw new SecurityException(); } return service.newOutputStream(path, options); }
@Override public OutputStream openFile(Path path){ if (!isActive()) { return null; } checkNotNull( "path", path ); return getIOService().newOutputStream(path); }
@Override public OutputStream openFile(Path path) { checkNotNull( "path", path ); return ioService.newOutputStream(path, StandardOpenOption.TRUNCATE_EXISTING); }
private Path loadXLSFile( final Path basePath, final String fileName ) throws IOException { final Path path = basePath.resolve( fileName ); final InputStream is = this.getClass().getResourceAsStream( fileName ); final OutputStream os = ioService().newOutputStream( path ); IOUtils.copy( is, os ); os.flush(); os.close(); return path; }
private Path loadXLSFile(final Path basePath, final String fileName) throws IOException { final Path path = basePath.resolve(fileName); final InputStream is = this.getClass().getResourceAsStream(fileName); final OutputStream os = ioService().newOutputStream(path); IOUtils.copy(is, os); os.flush(); os.close(); return path; } }
private Path loadXLSFile( final Path basePath, final String fileName ) throws IOException { final Path path = basePath.resolve( fileName ); final InputStream is = this.getClass().getResourceAsStream( fileName ); final OutputStream os = ioService().newOutputStream( path ); IOUtils.copy( is, os ); os.flush(); os.close(); return path; }
private Path loadXLSFile(final Path basePath, final String fileName) throws IOException { final Path path = basePath.resolve(fileName); final InputStream is = this.getClass().getResourceAsStream(fileName); final OutputStream os = ioService().newOutputStream(path); IOUtils.copy(is, os); os.flush(); os.close(); return path; } }
private Path loadXLSFile(final Path basePath, final String fileName) throws IOException { final Path path = basePath.resolve(fileName); final InputStream is = this.getClass().getResourceAsStream(fileName); final OutputStream os = ioService().newOutputStream(path); IOUtils.copy(is, os); os.flush(); os.close(); return path; } }
private Path loadXLSFile( final Path basePath, final String fileName ) throws IOException { final Path path = basePath.resolve( fileName ); final InputStream is = this.getClass().getResourceAsStream( fileName ); final OutputStream os = ioService().newOutputStream( path ); IOUtils.copy( is, os ); os.flush(); os.close(); return path; }
private Path loadXLSFile(final Path basePath, final String fileName) throws IOException { final Path path = basePath.resolve(fileName); final InputStream is = this.getClass().getResourceAsStream(fileName); final OutputStream os = ioService().newOutputStream(path); IOUtils.copy(is, os); os.flush(); os.close(); return path; } }
@Before public void setup() throws IOException { when( authenticationService.getUser() ).thenReturn( user ); when( user.getIdentifier() ).thenReturn( "user" ); when( path.toURI() ).thenReturn( "default://p0/src/main/resources/dtable.xls" ); when( inputstream.read( anyObject() ) ).thenReturn( -1 ); when( ioService.newOutputStream( any( org.uberfire.java.nio.file.Path.class ), commentedOptionArgumentCaptor.capture() ) ).thenReturn( outputStream ); }
@Before public void setup() throws IOException { when( authenticationService.getUser() ).thenReturn( user ); when( user.getIdentifier() ).thenReturn( "user" ); when( path.toURI() ).thenReturn( "default://p0/src/main/resources/dtable.xls" ); when( inputstream.read( anyObject() ) ).thenReturn( -1 ); when( ioService.newOutputStream( any( org.uberfire.java.nio.file.Path.class ), commentedOptionArgumentCaptor.capture() ) ).thenReturn( outputStream ); }
@Test public void testRegularLoad() throws IOException { Path path = fileSystem.getPath(storage.getStoragePath()); ioService.write(path, IOUtils.toString(getClass().getResourceAsStream("/test/global/regularFeatures.txt"), Charset.defaultCharset())); storage.init(); verifyInit(); verify(ioService, times(2)).exists(any()); verify(ioService).newInputStream(any()); verify(ioService, never()).newOutputStream(any()); verify(ioService, never()).startBatch(fileSystem); verify(ioService, never()).endBatch(); verifyLoadedFeatures(new ArrayList<>(storage.getFeatures()), new ExperimentalFeatureImpl(GLOBAL_FEATURE_1, true), new ExperimentalFeatureImpl(GLOBAL_FEATURE_2, false), new ExperimentalFeatureImpl(GLOBAL_FEATURE_3, true)); }
@Test public void testStoreFeature() throws IOException { testRegularLoad(); storage.store(new ExperimentalFeatureImpl(GLOBAL_FEATURE_1, true)); verify(ioService, never()).newOutputStream(any()); verify(ioService, never()).startBatch(fileSystem); verify(ioService, never()).endBatch(); storage.store(new ExperimentalFeatureImpl(FEATURE_1, false)); verify(ioService).newOutputStream(any()); verify(ioService).startBatch(fileSystem); verify(ioService).endBatch(); verifyLoadedFeatures(new ArrayList<>(storage.getFeatures()), new ExperimentalFeatureImpl(FEATURE_1, false), new ExperimentalFeatureImpl(FEATURE_2, false), new ExperimentalFeatureImpl(FEATURE_3, true)); }
@Test public void testMissingFeaturesLoad() throws IOException { Path path = fileSystem.getPath(storage.getStoragePath()); ioService.write(path, IOUtils.toString(getClass().getResourceAsStream("/test/global/missingFeatures.txt"), Charset.defaultCharset())); storage.init(); verifyInit(); verify(ioService, times(2)).exists(any()); verify(ioService).newInputStream(any()); verify(ioService).newOutputStream(any()); verify(ioService).startBatch(fileSystem); verify(ioService).endBatch(); verifyLoadedFeatures(new ArrayList<>(storage.getFeatures()), new ExperimentalFeatureImpl(GLOBAL_FEATURE_1, true), new ExperimentalFeatureImpl(GLOBAL_FEATURE_2, false), new ExperimentalFeatureImpl(GLOBAL_FEATURE_3, true)); }
@Test public void testExtraFeaturesLoad() throws IOException { Path path = fileSystem.getPath(storage.getStoragePath()); ioService.write(path, IOUtils.toString(getClass().getResourceAsStream("/test/global/extraFeatures.txt"), Charset.defaultCharset())); storage.init(); verifyInit(); verify(ioService, times(2)).exists(any()); verify(ioService).newInputStream(any()); verify(ioService).newOutputStream(any()); verify(ioService).startBatch(fileSystem); verify(ioService).endBatch(); verifyLoadedFeatures(new ArrayList<>(storage.getFeatures()), new ExperimentalFeatureImpl(GLOBAL_FEATURE_1, true), new ExperimentalFeatureImpl(GLOBAL_FEATURE_2, false), new ExperimentalFeatureImpl(GLOBAL_FEATURE_3, true)); }
@Test public void testMissingFeaturesLoad() throws IOException { Path path = fileSystem.getPath(storage.getStoragePath()); ioService.write(path, IOUtils.toString(getClass().getResourceAsStream("/test/user/missingFeatures.txt"), Charset.defaultCharset())); storage.init(); verifyInit(); List<ExperimentalFeatureImpl> features = new ArrayList<>(storage.getFeatures()); verify(ioService, times(2)).exists(any()); verify(ioService).newInputStream(any()); verify(ioService).newOutputStream(any()); verify(ioService).startBatch(fileSystem); verify(ioService).endBatch(); verifyLoadedFeatures(features, new ExperimentalFeatureImpl(FEATURE_1, true), new ExperimentalFeatureImpl(FEATURE_2, false), new ExperimentalFeatureImpl(FEATURE_3, true)); }
@Test public void testFirstLoad() { storage.init(); verifyInit(); List<ExperimentalFeatureImpl> features = new ArrayList<>(storage.getFeatures()); verify(ioService).exists(any()); verify(ioService, never()).newInputStream(any()); verify(ioService).newOutputStream(any()); verify(ioService).startBatch(fileSystem); verify(ioService).endBatch(); verifyLoadedFeatures(features, new ExperimentalFeatureImpl(FEATURE_1, false), new ExperimentalFeatureImpl(FEATURE_2, false), new ExperimentalFeatureImpl(FEATURE_3, false)); }
@Test public void testFirstLoad() { storage.init(); verifyInit(); verify(ioService).exists(any()); verify(ioService).newOutputStream(any()); verify(ioService).startBatch(fileSystem); verify(ioService).endBatch(); verifyLoadedFeatures(new ArrayList<>(storage.getFeatures()), new ExperimentalFeatureImpl(GLOBAL_FEATURE_1, false), new ExperimentalFeatureImpl(GLOBAL_FEATURE_2, false), new ExperimentalFeatureImpl(GLOBAL_FEATURE_3, false)); }
@Test public void testFirstLoad() { storage.init(); verifyInit(); verify(ioService).exists(any()); verify(ioService).newOutputStream(any()); verify(ioService).startBatch(fileSystem); verify(ioService).endBatch(); verifyLoadedFeatures(new ArrayList<>(storage.getFeatures()), new ExperimentalFeatureImpl(GLOBAL_FEATURE_1, false), new ExperimentalFeatureImpl(GLOBAL_FEATURE_2, false), new ExperimentalFeatureImpl(GLOBAL_FEATURE_3, false)); }