/** * This method leverages the ability to open a stream from GCS from a given offset. When the * underlying stream has fewer bytes buffered than the skip request, the stream is closed, and * a new stream is opened starting at the requested offset. * * @param n number of bytes to skip * @return the number of bytes skipped */ @Override public long skip(long n) throws IOException { if (mInputStream.available() >= n) { return mInputStream.skip(n); } // The number of bytes to skip is possibly large, open a new stream from GCS. mInputStream.close(); mPos += n; try { mObject = mClient.getObject(mBucketName, mKey, null /* ignore ModifiedSince */, null /* ignore UnmodifiedSince */, null /* ignore MatchTags */, null /* ignore NoneMatchTags */, mPos /* byteRangeStart */, null /* ignore byteRangeEnd */); mInputStream = new BufferedInputStream(mObject.getDataInputStream()); } catch (ServiceException e) { throw new IOException(e); } return n; } }
/** * Creates a new instance of {@link GCSInputStream}, at a specific position. * * @param bucketName the name of the bucket * @param key the key of the file * @param client the client for GCS * @param pos the position to start * @throws ServiceException if a service exception occurs */ GCSInputStream(String bucketName, String key, GoogleStorageService client, long pos) throws ServiceException { mBucketName = bucketName; mKey = key; mClient = client; mPos = pos; // For an empty file setting start pos = 0 will throw a ServiceException if (mPos > 0) { mObject = mClient.getObject(mBucketName, mKey, null, null, null, null, mPos, null); } else { mObject = mClient.getObject(mBucketName, mKey); } mInputStream = new BufferedInputStream(mObject.getDataInputStream()); }
/** * This method leverages the ability to open a stream from GCS from a given offset. When the * underlying stream has fewer bytes buffered than the skip request, the stream is closed, and * a new stream is opened starting at the requested offset. * * @param n number of bytes to skip * @return the number of bytes skipped */ @Override public long skip(long n) throws IOException { if (mInputStream.available() >= n) { return mInputStream.skip(n); } // The number of bytes to skip is possibly large, open a new stream from GCS. mInputStream.close(); mPos += n; try { mObject = mClient.getObject(mBucketName, mKey, null /* ignore ModifiedSince */, null /* ignore UnmodifiedSince */, null /* ignore MatchTags */, null /* ignore NoneMatchTags */, mPos /* byteRangeStart */, null /* ignore byteRangeEnd */); mInputStream = new BufferedInputStream(mObject.getDataInputStream()); } catch (ServiceException e) { throw new IOException(e); } return n; } }
/** * Creates a new instance of {@link GCSInputStream}, at a specific position. * * @param bucketName the name of the bucket * @param key the key of the file * @param client the client for GCS * @param pos the position to start * @throws ServiceException if a service exception occurs */ GCSInputStream(String bucketName, String key, GoogleStorageService client, long pos) throws ServiceException { mBucketName = bucketName; mKey = key; mClient = client; mPos = pos; // For an empty file setting start pos = 0 will throw a ServiceException if (mPos > 0) { mObject = mClient.getObject(mBucketName, mKey, null, null, null, null, mPos, null); } else { mObject = mClient.getObject(mBucketName, mKey); } mInputStream = new BufferedInputStream(mObject.getDataInputStream()); }
@Override public byte[] getChunk(byte[] hash, long start, int len) throws IOException { String hashString = this.getHashName(hash); try { GSObject obj = gsService.getObject(this.name, hashString); byte[] data = new byte[(int) obj.getContentLength()]; DataInputStream in = new DataInputStream(obj.getDataInputStream()); in.readFully(data); obj.closeDataInputStream(); if (Main.chunkStoreEncryptionEnabled) data = EncryptUtils.decrypt(data); if (Main.compress) data = CompressionUtils.decompressZLIB(data); return data; } catch (Exception e) { // TODO Auto-generated catch block SDFSLogger.getLog() .error("unable to fetch block [" + hash + "]", e); throw new IOException("unable to read " + hashString); } }
new InputStreamReader(objectComplete.getDataInputStream())); String data; while ((data = reader.readLine()) != null) { downloadedObject.getDataInputStream(), "UTF-8"); boolean valid = downloadedObject.verifyData(textData.getBytes("UTF-8")); System.out.println("Object verified? " + valid);
new InputStreamReader(objectComplete.getDataInputStream())); String data; while ((data = reader.readLine()) != null) { downloadedObject.getDataInputStream(), "UTF-8"); boolean valid = downloadedObject.verifyData(textData.getBytes("UTF-8")); System.out.println("Object verified? " + valid);