/** * This implementation returns {@link Channels#newChannel(InputStream)} * with the result of {@link #getInputStream()}. * <p>This is the same as in {@link Resource}'s corresponding default method * but mirrored here for efficient JVM-level dispatching in a class hierarchy. */ @Override public ReadableByteChannel readableChannel() throws IOException { return Channels.newChannel(getInputStream()); }
/** * This implementation returns {@link Channels#newChannel(InputStream)} * with the result of {@link #getInputStream()}. * <p>This is the same as in {@link Resource}'s corresponding default method * but mirrored here for efficient JVM-level dispatching in a class hierarchy. */ @Override public ReadableByteChannel readableChannel() throws IOException { return Channels.newChannel(getInputStream()); }
/** * This implementation reads the entire InputStream to calculate the * content length. Subclasses will almost always be able to provide * a more optimal version of this, e.g. checking a File length. * @see #getInputStream() */ @Override public long contentLength() throws IOException { InputStream is = getInputStream(); try { long size = 0; byte[] buf = new byte[256]; int read; while ((read = is.read(buf)) != -1) { size += read; } return size; } finally { try { is.close(); } catch (IOException ex) { } } }
/** * This implementation checks whether a File can be opened, * falling back to whether an InputStream can be opened. * This will cover both directories and content resources. */ @Override public boolean exists() { // Try file existence: can we find the file in the file system? try { return getFile().exists(); } catch (IOException ex) { // Fall back to stream existence: can we open the stream? try { getInputStream().close(); return true; } catch (Throwable isEx) { return false; } } }
/** * This implementation reads the entire InputStream to calculate the * content length. Subclasses will almost always be able to provide * a more optimal version of this, e.g. checking a File length. * @see #getInputStream() */ @Override public long contentLength() throws IOException { InputStream is = getInputStream(); try { long size = 0; byte[] buf = new byte[256]; int read; while ((read = is.read(buf)) != -1) { size += read; } return size; } finally { try { is.close(); } catch (IOException ex) { } } }
/** * This implementation checks whether a File can be opened, * falling back to whether an InputStream can be opened. * This will cover both directories and content resources. */ @Override public boolean exists() { // Try file existence: can we find the file in the file system? try { return getFile().exists(); } catch (IOException ex) { // Fall back to stream existence: can we open the stream? try { getInputStream().close(); return true; } catch (Throwable isEx) { return false; } } }
/** * This implementation reads the entire InputStream to calculate the * content length. Subclasses will almost always be able to provide * a more optimal version of this, e.g. checking a File length. * @see #getInputStream() */ public long contentLength() throws IOException { InputStream is = getInputStream(); try { long size = 0; byte[] buf = new byte[255]; int read; while ((read = is.read(buf)) != -1) { size += read; } return size; } finally { try { is.close(); } catch (IOException ex) { } } }
/** * This implementation checks whether a File can be opened, * falling back to whether an InputStream can be opened. * This will cover both directories and content resources. */ public boolean exists() { // Try file existence: can we find the file in the file system? try { return getFile().exists(); } catch (IOException ex) { // Fall back to stream existence: can we open the stream? try { InputStream is = getInputStream(); is.close(); return true; } catch (Throwable isEx) { return false; } } }
/** * This implementation returns {@link Channels#newChannel(InputStream)} * with the result of {@link #getInputStream()}. * <p>This is the same as in {@link Resource}'s corresponding default method * but mirrored here for efficient JVM-level dispatching in a class hierarchy. */ @Override public ReadableByteChannel readableChannel() throws IOException { return Channels.newChannel(getInputStream()); }
private void initNonSpringWorkflowDefinitions() throws IOException, ReflectiveOperationException { try (BufferedReader br = new BufferedReader(new InputStreamReader(nonSpringWorkflowsListing.getInputStream(), UTF_8))) { String row; while ((row = br.readLine()) != null) { logger.info("Preparing workflow {}", row); @SuppressWarnings("unchecked") Class<WorkflowDefinition<? extends WorkflowState>> clazz = (Class<WorkflowDefinition<? extends WorkflowState>>) Class.forName(row); addWorkflowDefinition(clazz.getDeclaredConstructor().newInstance()); } } }
/** * This implementation reads the entire InputStream to calculate the * content length. Subclasses will almost always be able to provide * a more optimal version of this, e.g. checking a File length. * @see #getInputStream() */ @Override public long contentLength() throws IOException { InputStream is = getInputStream(); try { long size = 0; byte[] buf = new byte[256]; int read; while ((read = is.read(buf)) != -1) { size += read; } return size; } finally { try { is.close(); } catch (IOException ex) { } } }
private void initNonSpringWorkflowDefinitions() throws IOException, ReflectiveOperationException { try (BufferedReader br = new BufferedReader(new InputStreamReader(nonSpringWorkflowsListing.getInputStream(), UTF_8))) { String row; while ((row = br.readLine()) != null) { logger.info("Preparing workflow {}", row); @SuppressWarnings("unchecked") Class<WorkflowDefinition<? extends WorkflowState>> clazz = (Class<WorkflowDefinition<? extends WorkflowState>>) Class.forName(row); addWorkflowDefinition(clazz.newInstance()); } } }
/** * This implementation checks whether a File can be opened, * falling back to whether an InputStream can be opened. * This will cover both directories and content resources. */ @Override public boolean exists() { // Try file existence: can we find the file in the file system? try { return getFile().exists(); } catch (IOException ex) { // Fall back to stream existence: can we open the stream? try { getInputStream().close(); return true; } catch (Throwable isEx) { return false; } } }
/** * This implementation checks whether a File can be opened, * falling back to whether an InputStream can be opened. * This will cover both directories and content resources. */ public boolean exists() { // Try file existence: can we find the file in the file system? try { return getFile().exists(); } catch (IOException ex) { // Fall back to stream existence: can we open the stream? try { InputStream is = getInputStream(); is.close(); return true; } catch (IOException ex2) { return false; } } }
/** * This implementation checks whether a File can be opened, * falling back to whether an InputStream can be opened. * This will cover both directories and content resources. */ public boolean exists() { // Try file existence: can we find the file in the file system? try { return getFile().exists(); } catch (IOException ex) { // Fall back to stream existence: can we open the stream? try { InputStream is = getInputStream(); is.close(); return true; } catch (Throwable isEx) { return false; } } }
/** * This implementation checks whether a File can be opened, * falling back to whether an InputStream can be opened. * This will cover both directories and content resources. */ @Override public boolean exists() { // Try file existence: can we find the file in the file system? try { return getFile().exists(); } catch (IOException ex) { // Fall back to stream existence: can we open the stream? try { getInputStream().close(); return true; } catch (Throwable isEx) { return false; } } }
private String resolveUsernameFromExternalGroovyScript(final Principal principal, final Service service, final String scriptFile) { try { LOGGER.debug("Found groovy script to execute"); val resourceFrom = ResourceUtils.getResourceFrom(scriptFile); val script = IOUtils.toString(resourceFrom.getInputStream(), StandardCharsets.UTF_8); val result = getGroovyAttributeValue(principal, script); if (result != null) { LOGGER.debug("Found username [{}] from script [{}]", result, scriptFile); return result.toString(); } } catch (final IOException e) { LOGGER.error(e.getMessage(), e); } LOGGER.warn("Groovy script [{}] returned no value for username attribute. Fallback to default [{}]", this.groovyScript, principal.getId()); return principal.getId(); }
@Override public Collection<? extends MetadataResolver> resolve(final SamlRegisteredService service) { val metadataLocation = service.getMetadataLocation(); LOGGER.info("Loading SAML metadata from [{}]", metadataLocation); try (val in = ResourceUtils.getResourceFrom(metadataLocation).getInputStream()) { LOGGER.debug("Parsing metadata from [{}]", metadataLocation); val document = this.configBean.getParserPool().parse(in); val metadataRoot = document.getDocumentElement(); val metadataProvider = new DOMMetadataResolver(metadataRoot); configureAndInitializeSingleMetadataResolver(metadataProvider, service); return CollectionUtils.wrap(metadataProvider); } catch (final Exception e) { LOGGER.error(e.getMessage(), e); } return new ArrayList<>(0); }