try { SwiftObject object = api.getObjectApi(regionId, containerName) .get(objectName, org.jclouds.http.options.GetOptions.Builder.range(begin, end));
try { SwiftObject object = api.getObjectApi(regionId, containerName) .get(objectName, org.jclouds.http.options.GetOptions.Builder.range(begin, end));
@Override public byte[] call() { IOException lastException = null; for (int retry = 0; retry < retryCountLimit; retry++) { try { long time = System.nanoTime(); SwiftObject object = api.getObjectApi(regionId, containerName) .get(objectName, org.jclouds.http.options.GetOptions.Builder.range(begin, end)); byte[] downloadedBlock = ByteStreams.toByteArray(object.getPayload().openStream()); return downloadedBlock; } catch (IOException e) { logger.debug(e.toString()); lastException = e; continue; } } throw new RuntimeException("After " + retryCountLimit + " retries: " + lastException); } }
@Override public Void call() { IOException lastException = null; for (int retry = 0; retry < retryCountLimit; retry++) { try { SwiftObject object = api.getObjectApi(regionId, containerName) .get(objectName, org.jclouds.http.options.GetOptions.Builder.range(begin, end)); // Download first, this is the part that usually fails byte[] targetArray = ByteStreams.toByteArray(object.getPayload().openStream()); // Map file region MappedByteBuffer out = raf.getChannel().map(FileChannel.MapMode.READ_WRITE, begin, end - begin + 1); out.put(targetArray); out.force(); // JDK-4715154 ; TODO: Java 8 FileChannels if (System.getProperty("os.name").toLowerCase().contains("windows")) { closeDirectBuffer(out); } } catch (IOException e) { lastException = e; continue; } // Success! return null; } throw new RuntimeException("After " + retryCountLimit + " retries: " + lastException); }
@Override public byte[] call() { IOException lastException = null; for (int retry = 0; retry < retryCountLimit; retry++) { try { long time = System.nanoTime(); SwiftObject object = api.getObjectApi(regionId, containerName) .get(objectName, org.jclouds.http.options.GetOptions.Builder.range(begin, end)); byte[] downloadedBlock; InputStream is = object.getPayload().openStream(); try { downloadedBlock = ByteStreams.toByteArray(is); } finally { Closeables.closeQuietly(is); } return downloadedBlock; } catch (IOException e) { logger.debug(e.toString()); lastException = e; continue; } } throw new RuntimeException("After " + retryCountLimit + " retries: " + lastException); } }
@Override public byte[] call() { IOException lastException = null; for (int retry = 0; retry < retryCountLimit; retry++) { try { long time = System.nanoTime(); SwiftObject object = api.getObjectApi(regionId, containerName) .get(objectName, org.jclouds.http.options.GetOptions.Builder.range(begin, end)); byte[] downloadedBlock; InputStream is = object.getPayload().openStream(); try { downloadedBlock = ByteStreams.toByteArray(is); } finally { Closeables.closeQuietly(is); } return downloadedBlock; } catch (IOException e) { logger.debug(e.toString()); lastException = e; continue; } } throw new RuntimeException("After " + retryCountLimit + " retries: " + lastException); } }
@Test(expectedExceptions = IllegalArgumentException.class) public void testRangeNegative2() { range(0, -1); }
@Test(expectedExceptions = IllegalArgumentException.class) public void testRangeNegative1() { range(-1, 0); }
@Test(expectedExceptions = IllegalArgumentException.class) public void testRangeNegative() { range(-1, -1); }
@Test(expectedExceptions = IllegalArgumentException.class) public void testRangeNegative1() { range(-1, 0); }
@Test public void testRangeStatic() { GetOptions options = range(0, 1024); bytes1to1024(options); }
@Test(expectedExceptions = IllegalArgumentException.class) public void testRangeNegative2() { range(0, -1); }
@Test(expectedExceptions = IllegalArgumentException.class) public void testRangeNegative() { range(-1, -1); }
@Test public void testRangeStatic() { GetOptions options = range(0, 1024); bytes1to1024(options); }