< Previous | Contents | Next >

4.3.2 Partial Content Transfers

HCP supports HTTP/1.1 partial content transfers. Partial content transfers allow you to download byte ranges from an object. You can perform partial content transfers in Apache by adding a header to specify a range to download. Let’s modify our simple download program from Section 2.1.1 to retrieve the first five bytes of the object examples/world.txt.

1 public static void get() throws IOException {

2 //specify namespace URL - eg. namespace.tenant.HCP.DOMAIN.com/rest/path

3 String url = "http://example-namespace.example-tenant.cluster59h-

4 vm3.lab.archivas.com/rest/examples/world.txt";

5

6 //create a new HttpClient object and a GET request object

7 HttpClient client = HttpClientBuilder.create().build();

8 HttpGet request = new HttpGet(url);

9

10 //add authorization header for user(base64) "exampleuser" with password(md5) "passw0rd"

11 request.addHeader("Authorization", "HCP ZXhhbXBsZXVzZXI=:bed128365216c019988915ed3add75fb");

12 request.addHeader("Range", "bytes=0-4");

13

14 //execute the request

15 HttpResponse response = client.execute(request);

16

17 //print response status to console

18 System.out.println("Response Code : "

19 + response.getStatusLine().getStatusCode() + " " +

20 response.getStatusLine().getReasonPhrase());

21

22

//get response content

23

BufferedReader rd = new BufferedReader(

24

new InputStreamReader(response.getEntity().getContent()));

25

26

//print response content to console

27

StringBuffer result = new StringBuffer();

28

String line = "";

29

while ((line = rd.readLine()) != null) {

30

result.append(line);

31

}

32

System.out.println(result.toString());

33

}


NOTE


The performance impact of partial content transfers is more pronounced when working on a namespace with compression enabled, or if the byte range specified is small.

NOTE


The performance impact of partial content transfers is more pronounced when working on a namespace with compression enabled, or if the byte range specified is small.


image