hadoop-ozone/client/src/main/java/org/apache/hadoop/ozone/web/client/OzoneRestClient.java
public void putKey(String volumeName, String bucketName, String keyName,
      File file) throws OzoneException {
    OzoneUtils.verifyResourceName(volumeName);
    OzoneUtils.verifyResourceName(bucketName);

    if (StringUtils.isEmpty(keyName)) {
      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(getEndPointURI());
      builder.setPath("/" + volumeName + "/" + bucketName + "/" + keyName)
          .build();

      putRequest = 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));
      OzoneBucket.executePutKey(putRequest, httpClient);
    } catch (IOException | URISyntaxException ex) {
      throw new OzoneRestClientException(ex.getMessage(), ex);
    } finally {
      IOUtils.closeStream(fis);
      releaseConnection(putRequest);
    }
  }
/**
   * Puts a Key in Ozone Bucket.
   *
   * @param volumeName - Name of the Volume
   * @param bucketName - Name of the 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 volumeName - Name of the Volume
@param bucketName - Name of the 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 volumeName - Name of the Volume @param bucketName - Name of the Bucket @param keyName - Name of the Key @param file - Stream that gets read to be put into Ozone .
public void putKey(String volumeName, String bucketName, String keyName,
      File file) throws OzoneException {
    OzoneUtils.verifyResourceName(volumeName);
    OzoneUtils.verifyResourceName(bucketName);
    if (StringUtils.isEmpty(keyName)) {
      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(getEndPointURI());
      builder.setPath("/" + volumeName + "/" + bucketName + "/" + keyName)
          .build();
      putRequest = 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));
      OzoneBucket.executePutKey(putRequest, httpClient);
    } catch (IOException | URISyntaxException ex) {
      throw new OzoneRestClientException(ex.getMessage(), ex);
    } finally {
      IOUtils.closeStream(fis);
      releaseConnection(putRequest);
    }
  }
public void putKey ( String volumeName , String bucketName , String keyName , File file ) throws OzoneException { OzoneUtils . verifyResourceName ( volumeName ) ; OzoneUtils . verifyResourceName ( bucketName ) ; if ( StringUtils . isEmpty ( keyName ) ) { 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 ( getEndPointURI ( ) ) ; builder . setPath ( "/" + volumeName + "/" + bucketName + "/" + keyName ) . build ( ) ; putRequest = 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 ) ) ; OzoneBucket . executePutKey ( putRequest , httpClient ) ; } catch ( IOException | URISyntaxException ex ) { throw new OzoneRestClientException ( ex . getMessage ( ) , ex ) ; } finally { IOUtils . closeStream ( fis ) ; releaseConnection ( putRequest ) ; } }
Puts a Key in Ozone Bucket.
Puts a Key in Ozone Bucket .