예제 #1
0
  public void doStreamed(
      final EntityManager em, final ArtifactEntity ae, final ThrowingConsumer<Path> fileConsumer)
      throws IOException {
    final Path tmp = StreamServiceHelper.createTempFile(ae.getName());

    try {
      try (OutputStream os = new BufferedOutputStream(new FileOutputStream(tmp.toFile()))) {
        streamArtifact(
            em,
            ae,
            (ai, in) -> {
              ByteStreams.copy(in, os);
            });
      }

      try {
        fileConsumer.accept(tmp);
      } catch (final IOException e) {
        throw e;
      } catch (final Exception e) {
        throw new RuntimeException(e);
      }
    } finally {
      Files.deleteIfExists(tmp);
    }
  }
예제 #2
0
  public void streamArtifact(
      final EntityManager em,
      final ArtifactEntity artifact,
      final ThrowingConsumer<InputStream> consumer)
      throws IOException {
    checkOpen();

    final FilesystemBlobStoreProcessor currentFilesystem = this.filesystem.get();
    if (currentFilesystem != null) {
      if (currentFilesystem.streamArtifact(artifact.getId(), consumer)) {
        return;
      }
    }

    try {
      this.database.internalStreamArtifact(em, artifact, consumer);
    } catch (final SQLException e) {
      throw new IOException(e);
    }
  }