コード例 #1
0
ファイル: JerseyContent.java プロジェクト: j1cken/nexus
  protected boolean exists(final Location location, final String uri) {
    try {
      final ClientResponse response = getNexusClient().uri(uri).head();
      if (!ClientResponse.Status.OK.equals(response.getClientResponseStatus())) {
        if (ClientResponse.Status.NOT_FOUND.equals(response.getClientResponseStatus())) {
          return false;
        }

        throw getNexusClient()
            .convert(
                new ContextAwareUniformInterfaceException(response) {
                  @Override
                  public String getMessage(final int status) {
                    if (status == Response.Status.NOT_FOUND.getStatusCode()) {
                      return String.format("Inexistent path: %s", location);
                    }
                    return null;
                  }
                });
      }
      return true;
    } catch (ClientHandlerException e) {
      throw getNexusClient().convert(e);
    }
  }
コード例 #2
0
ファイル: JerseyContent.java プロジェクト: j1cken/nexus
  protected void download(final Location location, final String uri, final OutputStream target)
      throws IOException {
    try {
      final ClientResponse response = getNexusClient().uri(uri).get(ClientResponse.class);

      if (!ClientResponse.Status.OK.equals(response.getClientResponseStatus())) {
        throw getNexusClient()
            .convert(
                new ContextAwareUniformInterfaceException(response) {
                  @Override
                  public String getMessage(final int status) {
                    if (status == Response.Status.NOT_FOUND.getStatusCode()) {
                      return String.format("Inexistent path: %s", location);
                    }
                    return null;
                  }
                });
      }

      try {
        IOUtil.copy(response.getEntityInputStream(), target);
      } finally {
        response.close();
      }
    } catch (ClientHandlerException e) {
      throw getNexusClient().convert(e);
    }
  }