@Override public boolean isFile() { return this.gzipped.isFile(); }
@Override public boolean isFile() { return this.gzipped.isFile(); }
@Override public boolean isFile() { return this.encoded.isFile(); }
@Override public boolean isFile() { return this.original.isFile(); }
@Override public boolean isFile() { return this.encoded.isFile(); }
@Override public boolean isFile() { return this.original.isFile(); }
@Override public boolean isFile() { return this.encoded.isFile(); }
@Override public boolean isFile() { return this.original.isFile(); }
@Override public boolean isFile() { return this.gzipped.isFile(); }
/** * This implementation returns a File reference for the given URI-identified * resource, provided that it refers to a file in the file system. * @since 5.0 * @see #getFile(URI) */ protected boolean isFile(URI uri) { try { if (uri.getScheme().startsWith(ResourceUtils.URL_PROTOCOL_VFS)) { return VfsResourceDelegate.getResource(uri).isFile(); } return ResourceUtils.URL_PROTOCOL_FILE.equals(uri.getScheme()); } catch (IOException ex) { return false; } }
@Override public boolean isFile() { try { URL url = getURL(); if (url.getProtocol().startsWith(ResourceUtils.URL_PROTOCOL_VFS)) { return VfsResourceDelegate.getResource(url).isFile(); } return ResourceUtils.URL_PROTOCOL_FILE.equals(url.getProtocol()); } catch (IOException ex) { return false; } }
/** * This implementation returns a File reference for the given URI-identified * resource, provided that it refers to a file in the file system. * @since 5.0 * @see #getFile(URI) */ protected boolean isFile(URI uri) { try { if (uri.getScheme().startsWith(ResourceUtils.URL_PROTOCOL_VFS)) { return VfsResourceDelegate.getResource(uri).isFile(); } return ResourceUtils.URL_PROTOCOL_FILE.equals(uri.getScheme()); } catch (IOException ex) { return false; } }
private static Optional<Mono<Void>> zeroCopy(Resource resource, @Nullable ResourceRegion region, ReactiveHttpOutputMessage message, Map<String, Object> hints) { if (message instanceof ZeroCopyHttpOutputMessage && resource.isFile()) { try { File file = resource.getFile(); long pos = region != null ? region.getPosition() : 0; long count = region != null ? region.getCount() : file.length(); if (logger.isDebugEnabled()) { String formatted = region != null ? "region " + pos + "-" + (count) + " of " : ""; logger.debug(Hints.getLogPrefix(hints) + "Zero-copy " + formatted + "[" + resource + "]"); } return Optional.of(((ZeroCopyHttpOutputMessage) message).writeWith(file, pos, count)); } catch (IOException ex) { // should not happen } } return Optional.empty(); }
@Override public boolean isFile() { try { URL url = getURL(); if (url.getProtocol().startsWith(ResourceUtils.URL_PROTOCOL_VFS)) { return VfsResourceDelegate.getResource(url).isFile(); } return ResourceUtils.URL_PROTOCOL_FILE.equals(url.getProtocol()); } catch (IOException ex) { return false; } }
private static Optional<Mono<Void>> zeroCopy(Resource resource, @Nullable ResourceRegion region, ReactiveHttpOutputMessage message, Map<String, Object> hints) { if (message instanceof ZeroCopyHttpOutputMessage && resource.isFile()) { try { File file = resource.getFile(); long pos = region != null ? region.getPosition() : 0; long count = region != null ? region.getCount() : file.length(); if (logger.isDebugEnabled()) { String formatted = region != null ? "region " + pos + "-" + (count) + " of " : ""; logger.debug(Hints.getLogPrefix(hints) + "Zero-copy " + formatted + "[" + resource + "]"); } return Optional.of(((ZeroCopyHttpOutputMessage) message).writeWith(file, pos, count)); } catch (IOException ex) { // should not happen } } return Optional.empty(); }
/** * Read the given {@code Resource} into a {@code Flux} of {@code DataBuffer}s * starting at the given position. * <p>If the resource is a file, it is read into an * {@code AsynchronousFileChannel} and turned to {@code Flux} via * {@link #readAsynchronousFileChannel(Callable, DataBufferFactory, int)} or else * fall back on {@link #readByteChannel(Callable, DataBufferFactory, int)}. * Closes the channel when the flux is terminated. * @param resource the resource to read from * @param position the position to start reading from * @param dataBufferFactory the factory to create data buffers with * @param bufferSize the maximum size of the data buffers * @return a flux of data buffers read from the given channel */ public static Flux<DataBuffer> read( Resource resource, long position, DataBufferFactory dataBufferFactory, int bufferSize) { try { if (resource.isFile()) { File file = resource.getFile(); return readAsynchronousFileChannel( () -> AsynchronousFileChannel.open(file.toPath(), StandardOpenOption.READ), position, dataBufferFactory, bufferSize); } } catch (IOException ignore) { // fallback to resource.readableChannel(), below } Flux<DataBuffer> result = readByteChannel(resource::readableChannel, dataBufferFactory, bufferSize); return position == 0 ? result : skipUntilByteCount(result, position); }
/** * Read the given {@code Resource} into a {@code Flux} of {@code DataBuffer}s * starting at the given position. * <p>If the resource is a file, it is read into an * {@code AsynchronousFileChannel} and turned to {@code Flux} via * {@link #readAsynchronousFileChannel(Callable, DataBufferFactory, int)} or else * fall back on {@link #readByteChannel(Callable, DataBufferFactory, int)}. * Closes the channel when the flux is terminated. * @param resource the resource to read from * @param position the position to start reading from * @param dataBufferFactory the factory to create data buffers with * @param bufferSize the maximum size of the data buffers * @return a flux of data buffers read from the given channel */ public static Flux<DataBuffer> read( Resource resource, long position, DataBufferFactory dataBufferFactory, int bufferSize) { try { if (resource.isFile()) { File file = resource.getFile(); return readAsynchronousFileChannel( () -> AsynchronousFileChannel.open(file.toPath(), StandardOpenOption.READ), position, dataBufferFactory, bufferSize); } } catch (IOException ignore) { // fallback to resource.readableChannel(), below } Flux<DataBuffer> result = readByteChannel(resource::readableChannel, dataBufferFactory, bufferSize); return position == 0 ? result : skipUntilByteCount(result, position); }
@Override public boolean isFile() { return this.gzipped.isFile(); }
@Override public boolean isFile() { return this.original.isFile(); }
@Override public boolean isFile() { try { URL url = getURL(); if (url.getProtocol().startsWith(ResourceUtils.URL_PROTOCOL_VFS)) { return VfsResourceDelegate.getResource(url).isFile(); } return ResourceUtils.URL_PROTOCOL_FILE.equals(url.getProtocol()); } catch (IOException ex) { return false; } }