Tabnine Logo
HttpServerResponse.sendFile
Code IndexAdd Tabnine to your IDE (free)

How to use
sendFile
method
in
reactor.netty.http.server.HttpServerResponse

Best Java code snippets using reactor.netty.http.server.HttpServerResponse.sendFile (Showing top 17 results out of 315)

origin: spring-projects/spring-framework

@Override
public Mono<Void> writeWith(Path file, long position, long count) {
  return doCommit(() -> this.response.sendFile(file, position, count).then());
}
origin: org.springframework/spring-web

@Override
public Mono<Void> writeWith(Path file, long position, long count) {
  return doCommit(() -> this.response.sendFile(file, position, count).then());
}
origin: reactor/reactor-netty

@Override
public HttpServerRoutes directory(String uri, Path directory,
    Function<HttpServerResponse, HttpServerResponse> interceptor) {
  Objects.requireNonNull(directory, "directory");
  return route(HttpPredicate.prefix(uri), (req, resp) -> {
    String prefix = URI.create(req.uri())
              .getPath()
              .replaceFirst(uri, "");
    if(prefix.charAt(0) == '/'){
      prefix = prefix.substring(1);
    }
    Path p = directory.resolve(prefix);
    if (Files.isReadable(p)) {
      if (interceptor != null) {
        return interceptor.apply(resp)
                 .sendFile(p);
      }
      return resp.sendFile(p);
    }
    return resp.sendNotFound();
  });
}
origin: io.projectreactor.netty/reactor-netty

/**
 * Listen for HTTP GET on the passed path to be used as a routing condition. The
 * file on the provided {@link Path} is served.
 * <p>
 * Additional regex matching is available e.g.
 * "/test/{param}". Params are resolved using {@link HttpServerRequest#param(CharSequence)}
 *
 * @param uri The {@link HttpPredicate} to use to trigger the route, pattern matching
 * and capture are supported
 * @param path the Path to the file to serve
 * @param interceptor a channel pre-intercepting handler e.g. for content type header
 *
 * @return this {@link HttpServerRoutes}
 */
default HttpServerRoutes file(Predicate<HttpServerRequest> uri, Path path,
    @Nullable Function<HttpServerResponse, HttpServerResponse> interceptor) {
  Objects.requireNonNull(path, "path");
  return route(uri, (req, resp) -> {
    if (!Files.isReadable(path)) {
      return resp.send(ByteBufFlux.fromPath(path));
    }
    if (interceptor != null) {
      return interceptor.apply(resp)
               .sendFile(path);
    }
    return resp.sendFile(path);
  });
}
origin: io.projectreactor.netty/reactor-netty

@Override
public HttpServerRoutes directory(String uri, Path directory,
    Function<HttpServerResponse, HttpServerResponse> interceptor) {
  Objects.requireNonNull(directory, "directory");
  return route(HttpPredicate.prefix(uri), (req, resp) -> {
    String prefix = URI.create(req.uri())
              .getPath()
              .replaceFirst(uri, "");
    if(prefix.charAt(0) == '/'){
      prefix = prefix.substring(1);
    }
    Path p = directory.resolve(prefix);
    if (Files.isReadable(p)) {
      if (interceptor != null) {
        return interceptor.apply(resp)
                 .sendFile(p);
      }
      return resp.sendFile(p);
    }
    return resp.sendNotFound();
  });
}
origin: apache/servicemix-bundles

@Override
public Mono<Void> writeWith(File file, long position, long count) {
  return doCommit(() -> this.response.sendFile(file.toPath(), position, count).then());
}
origin: reactor/reactor-netty

/**
 * Listen for HTTP GET on the passed path to be used as a routing condition. The
 * file on the provided {@link Path} is served.
 * <p>
 * Additional regex matching is available e.g.
 * "/test/{param}". Params are resolved using {@link HttpServerRequest#param(CharSequence)}
 *
 * @param uri The {@link HttpPredicate} to use to trigger the route, pattern matching
 * and capture are supported
 * @param path the Path to the file to serve
 * @param interceptor a channel pre-intercepting handler e.g. for content type header
 *
 * @return this {@link HttpServerRoutes}
 */
default HttpServerRoutes file(Predicate<HttpServerRequest> uri, Path path,
    @Nullable Function<HttpServerResponse, HttpServerResponse> interceptor) {
  Objects.requireNonNull(path, "path");
  return route(uri, (req, resp) -> {
    if (!Files.isReadable(path)) {
      return resp.send(ByteBufFlux.fromPath(path));
    }
    if (interceptor != null) {
      return interceptor.apply(resp)
               .sendFile(path);
    }
    return resp.sendFile(path);
  });
}
origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.spring-web

@Override
public Mono<Void> writeWith(Path file, long position, long count) {
  return doCommit(() -> this.response.sendFile(file, position, count).then());
}
origin: reactor/reactor-netty

@Test
public void sendZipFileDefault() throws IOException {
  Path path = Files.createTempFile(null, ".zip");
  Files.copy(this.getClass().getResourceAsStream("/zipFile.zip"), path, StandardCopyOption.REPLACE_EXISTING);
  path.toFile().deleteOnExit();
  try (FileSystem zipFs = FileSystems.newFileSystem(path, null)) {
    Path fromZipFile = zipFs.getPath("/largeFile.txt");
    long fileSize = Files.size(fromZipFile);
    assertSendFile(out -> out.sendFile(fromZipFile, 0, fileSize));
  }
}
origin: reactor/reactor-netty

@Test
public void sendZipFileCompressionPredicate_1() throws IOException {
  Path path = Files.createTempFile(null, ".zip");
  Files.copy(this.getClass().getResourceAsStream("/zipFile.zip"), path, StandardCopyOption.REPLACE_EXISTING);
  path.toFile().deleteOnExit();
  try (FileSystem zipFs = FileSystems.newFileSystem(path, null)) {
    Path fromZipFile = zipFs.getPath("/largeFile.txt");
    long fileSize = Files.size(fromZipFile);
    assertSendFile(out -> out.sendFile(fromZipFile, 0, fileSize), true, -1, (req, res) -> true);
  }
}
origin: reactor/reactor-netty

@Test
public void sendZipFileCompressionSize_3() throws IOException {
  Path path = Files.createTempFile(null, ".zip");
  Files.copy(this.getClass().getResourceAsStream("/zipFile.zip"), path, StandardCopyOption.REPLACE_EXISTING);
  path.toFile().deleteOnExit();
  try (FileSystem zipFs = FileSystems.newFileSystem(path, null)) {
    Path fromZipFile = zipFs.getPath("/largeFile.txt");
    long fileSize = Files.size(fromZipFile);
    assertSendFile(out -> out.addHeader(HttpHeaderNames.CONTENT_LENGTH, "1245")
                 .sendFile(fromZipFile, 0, fileSize), true, 512, null);
  }
}
origin: reactor/reactor-netty

@Test
public void sendZipFileCompressionOn() throws IOException {
  Path path = Files.createTempFile(null, ".zip");
  Files.copy(this.getClass().getResourceAsStream("/zipFile.zip"), path, StandardCopyOption.REPLACE_EXISTING);
  path.toFile().deleteOnExit();
  try (FileSystem zipFs = FileSystems.newFileSystem(path, null)) {
    Path fromZipFile = zipFs.getPath("/largeFile.txt");
    long fileSize = Files.size(fromZipFile);
    assertSendFile(out -> out.compression(true).sendFile(fromZipFile, 0, fileSize), true, -1, (req, res) -> false);
  }
}
origin: reactor/reactor-netty

@Test
public void sendZipFileCompressionSize_1() throws IOException {
  Path path = Files.createTempFile(null, ".zip");
  Files.copy(this.getClass().getResourceAsStream("/zipFile.zip"), path, StandardCopyOption.REPLACE_EXISTING);
  path.toFile().deleteOnExit();
  try (FileSystem zipFs = FileSystems.newFileSystem(path, null)) {
    Path fromZipFile = zipFs.getPath("/largeFile.txt");
    long fileSize = Files.size(fromZipFile);
    assertSendFile(out -> out.addHeader(HttpHeaderNames.CONTENT_LENGTH, "1245")
                 .sendFile(fromZipFile, 0, fileSize), true, 2048, null);
  }
}
origin: reactor/reactor-netty

@Test
public void sendZipFileCompressionSize_2() throws IOException {
  Path path = Files.createTempFile(null, ".zip");
  Files.copy(this.getClass().getResourceAsStream("/zipFile.zip"), path, StandardCopyOption.REPLACE_EXISTING);
  path.toFile().deleteOnExit();
  try (FileSystem zipFs = FileSystems.newFileSystem(path, null)) {
    Path fromZipFile = zipFs.getPath("/largeFile.txt");
    long fileSize = Files.size(fromZipFile);
    assertSendFile(out -> out.addHeader(HttpHeaderNames.CONTENT_LENGTH, "1245")
                 .sendFile(fromZipFile, 0, fileSize), true, 2048, (req, res) -> true);
  }
}
origin: reactor/reactor-netty

@Test
public void sendZipFileCompressionSize_4() throws IOException {
  Path path = Files.createTempFile(null, ".zip");
  Files.copy(this.getClass().getResourceAsStream("/zipFile.zip"), path, StandardCopyOption.REPLACE_EXISTING);
  path.toFile().deleteOnExit();
  try (FileSystem zipFs = FileSystems.newFileSystem(path, null)) {
    Path fromZipFile = zipFs.getPath("/largeFile.txt");
    long fileSize = Files.size(fromZipFile);
    assertSendFile(out -> out.addHeader(HttpHeaderNames.CONTENT_LENGTH, "1245")
                 .sendFile(fromZipFile, 0, fileSize), true, 512, (req, res) -> false);
  }
}
origin: reactor/reactor-netty

@Test
public void sendZipFileCompressionPredicate_2() throws IOException {
  Path path = Files.createTempFile(null, ".zip");
  Files.copy(this.getClass().getResourceAsStream("/zipFile.zip"), path, StandardCopyOption.REPLACE_EXISTING);
  path.toFile().deleteOnExit();
  try (FileSystem zipFs = FileSystems.newFileSystem(path, null)) {
    Path fromZipFile = zipFs.getPath("/largeFile.txt");
    long fileSize = Files.size(fromZipFile);
    assertSendFile(out -> out.addHeader("test", "test").sendFile(fromZipFile, 0, fileSize), true,
        -1, (req, res) -> res.responseHeaders().contains("test"));
  }
}
origin: reactor/reactor-netty

@Test
public void sendZipFileCompressionPredicate_3() throws IOException {
  Path path = Files.createTempFile(null, ".zip");
  Files.copy(this.getClass().getResourceAsStream("/zipFile.zip"), path, StandardCopyOption.REPLACE_EXISTING);
  path.toFile().deleteOnExit();
  try (FileSystem zipFs = FileSystems.newFileSystem(path, null)) {
    Path fromZipFile = zipFs.getPath("/largeFile.txt");
    long fileSize = Files.size(fromZipFile);
    assertSendFile(out -> out.addHeader("test", "test").sendFile(fromZipFile, 0, fileSize), true,
        -1, (req, res) -> !res.responseHeaders().contains("test"));
  }
}
reactor.netty.http.serverHttpServerResponsesendFile

Popular methods of HttpServerResponse

  • status
  • send
  • responseHeaders
    Return headers sent back to the clients
  • sendWebsocket
    Upgrade connection to Websocket. Mono and Callback are invoked on handshake success, otherwise the r
  • header
    Set an outbound header, replacing any pre-existing value.
  • addCookie
    Add an outbound cookie
  • addHeader
    Add an outbound http header, appending the value if the header already exist.
  • alloc
  • sendGroups
  • sendNotFound
    Send 404 status HttpResponseStatus#NOT_FOUND.
  • sendObject
  • sendString
  • sendObject,
  • sendString,
  • chunkedTransfer,
  • compression,
  • headers,
  • options,
  • sendByteArray,
  • sendFileChunked,
  • sendHeaders

Popular in Java

  • Creating JSON documents from java classes using gson
  • setContentView (Activity)
  • onRequestPermissionsResult (Fragment)
  • getSharedPreferences (Context)
  • FileOutputStream (java.io)
    An output stream that writes bytes to a file. If the output file exists, it can be replaced or appen
  • MalformedURLException (java.net)
    This exception is thrown when a program attempts to create an URL from an incorrect specification.
  • URLConnection (java.net)
    A connection to a URL for reading or writing. For HTTP connections, see HttpURLConnection for docume
  • MessageFormat (java.text)
    Produces concatenated messages in language-neutral way. New code should probably use java.util.Forma
  • TreeMap (java.util)
    Walk the nodes of the tree left-to-right or right-to-left. Note that in descending iterations, next
  • CountDownLatch (java.util.concurrent)
    A synchronization aid that allows one or more threads to wait until a set of operations being perfor
  • Best plugins for Eclipse
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now