hadoop-ozone/client/src/main/java/org/apache/hadoop/ozone/web/client/OzoneBucket.java
public void putKey(String keyName, File file)
      throws OzoneException {

    if ((keyName == null) || keyName.isEmpty()) {
      throw new OzoneRestClientException("Invalid key Name");
    }

    if (file == null) {
      throw new OzoneRestClientException("Invalid data stream");
    }

    HttpPut putRequest = null;
    FileInputStream fis = null;
    try (CloseableHttpClient httpClient = HddsClientUtils.newHttpClient()) {
      URIBuilder builder = new URIBuilder(volume.getClient().getEndPointURI());
      builder.setPath("/" + getVolume().getVolumeName() + "/" + getBucketName()
          + "/" + keyName).build();

      putRequest = getVolume().getClient().getHttpPut(builder.toString());

      FileEntity fileEntity = new FileEntity(file, ContentType
          .APPLICATION_OCTET_STREAM);
      putRequest.setEntity(fileEntity);

      fis = new FileInputStream(file);
      putRequest.setHeader(Header.CONTENT_MD5, DigestUtils.md5Hex(fis));
      executePutKey(putRequest, httpClient);

    } catch (IOException | URISyntaxException ex) {
      final OzoneRestClientException orce = new OzoneRestClientException(
          "Failed to putKey: keyName=" + keyName + ", file=" + file);
      orce.initCause(ex);
      LOG.trace("", orce);
      throw orce;
    } finally {
      IOUtils.closeStream(fis);
      releaseConnection(putRequest);
    }
  }
/**
   * Puts a Key in Ozone Bucket.
   *
   * @param keyName - Name of the Key
   * @param file    - Stream that gets read to be put into Ozone.
   * @throws OzoneException
   */
Puts a Key in Ozone Bucket.
@param keyName - Name of the Key
@param file    - Stream that gets read to be put into Ozone.
Puts a Key in Ozone Bucket . @param keyName - Name of the Key @param file - Stream that gets read to be put into Ozone .
public void putKey(String keyName, File file)
      throws OzoneException {
    if ((keyName == null) || keyName.isEmpty()) {
      throw new OzoneRestClientException("Invalid key Name");
    }
    if (file == null) {
      throw new OzoneRestClientException("Invalid data stream");
    }
    HttpPut putRequest = null;
    FileInputStream fis = null;
    try (CloseableHttpClient httpClient = HddsClientUtils.newHttpClient()) {
      URIBuilder builder = new URIBuilder(volume.getClient().getEndPointURI());
      builder.setPath("/" + getVolume().getVolumeName() + "/" + getBucketName()
          + "/" + keyName).build();
      putRequest = getVolume().getClient().getHttpPut(builder.toString());
      FileEntity fileEntity = new FileEntity(file, ContentType
          .APPLICATION_OCTET_STREAM);
      putRequest.setEntity(fileEntity);
      fis = new FileInputStream(file);
      putRequest.setHeader(Header.CONTENT_MD5, DigestUtils.md5Hex(fis));
      executePutKey(putRequest, httpClient);
    } catch (IOException | URISyntaxException ex) {
      final OzoneRestClientException orce = new OzoneRestClientException(
          "Failed to putKey: keyName=" + keyName + ", file=" + file);
      orce.initCause(ex);
      LOG.trace("", orce);
      throw orce;
    } finally {
      IOUtils.closeStream(fis);
      releaseConnection(putRequest);
    }
  }
public void putKey ( String keyName , File file ) throws OzoneException { if ( ( keyName == null ) || keyName . isEmpty ( ) ) { throw new OzoneRestClientException ( "Invalid key Name" ) ; } if ( file == null ) { throw new OzoneRestClientException ( "Invalid data stream" ) ; } HttpPut putRequest = null ; FileInputStream fis = null ; try ( CloseableHttpClient httpClient = HddsClientUtils . newHttpClient ( ) ) { URIBuilder builder = new URIBuilder ( volume . getClient ( ) . getEndPointURI ( ) ) ; builder . setPath ( "/" + getVolume ( ) . getVolumeName ( ) + "/" + getBucketName ( ) + "/" + keyName ) . build ( ) ; putRequest = getVolume ( ) . getClient ( ) . getHttpPut ( builder . toString ( ) ) ; FileEntity fileEntity = new FileEntity ( file , ContentType . APPLICATION_OCTET_STREAM ) ; putRequest . setEntity ( fileEntity ) ; fis = new FileInputStream ( file ) ; putRequest . setHeader ( Header . CONTENT_MD5 , DigestUtils . md5Hex ( fis ) ) ; executePutKey ( putRequest , httpClient ) ; } catch ( IOException | URISyntaxException ex ) { final OzoneRestClientException orce = new OzoneRestClientException ( "Failed to putKey: keyName=" + keyName + ", file=" + file ) ; orce . initCause ( ex ) ; LOG . trace ( "" , orce ) ; throw orce ; } finally { IOUtils . closeStream ( fis ) ; releaseConnection ( putRequest ) ; } }
Puts a Key in Ozone Bucket.
Puts a Key in Ozone Bucket .