/** * Creates a new instance of {@link COSInputStream}. * * @param bucketName the name of the bucket * @param key the key of the file * @param client the client for COS * @param position the position to begin reading from * @param multiRangeChunkSize the chunk size to use on this stream */ COSInputStream(String bucketName, String key, COSClient client, long position, long multiRangeChunkSize) throws IOException { super(multiRangeChunkSize); mBucketName = bucketName; mKey = key; mCosClient = client; mPos = position; ObjectMetadata meta = mCosClient.getObjectMetadata(mBucketName, key); mContentLength = meta == null ? 0 : meta.getContentLength(); }
@Override protected ObjectStatus getObjectStatus(String key) { try { ObjectMetadata meta = mClient.getObjectMetadata(mBucketNameInternal, key); if (meta == null) { return null; } return new ObjectStatus(key, meta.getETag(), meta.getContentLength(), meta.getLastModified().getTime()); } catch (CosClientException e) { LOG.warn("Failed to get Object {}, return null", key, e); return null; } }
@Override public ObjectMetadata getObjectMetadata(String bucketName, String key) throws CosClientException, CosServiceException { return getObjectMetadata(new GetObjectMetadataRequest(bucketName, key)); }
@Override public ObjectMetadata getObjectMetadata(String bucketName, String key) throws CosClientException, CosServiceException { return getObjectMetadata(new GetObjectMetadataRequest(bucketName, key)); }
@Override public boolean doesObjectExist(String bucketName, String objectName) throws CosClientException, CosServiceException { try { getObjectMetadata(bucketName, objectName); return true; } catch (CosServiceException cse) { if (cse.getStatusCode() == 404) { return false; } throw cse; } }
@Override public boolean doesObjectExist(String bucketName, String objectName) throws CosClientException, CosServiceException { try { getObjectMetadata(bucketName, objectName); return true; } catch (CosServiceException cse) { if (cse.getStatusCode() == 404) { return false; } throw cse; } }