use of org.gradle.internal.resource.metadata.DefaultExternalResourceMetaData in project gradle by gradle.
the class UrlExternalResource method openResource.
@Nullable
@Override
public ExternalResourceReadResponse openResource(final URI location, boolean revalidate) throws ResourceException {
try {
URL url = location.toURL();
final URLConnection connection = url.openConnection();
final InputStream inputStream = connection.getInputStream();
return new ExternalResourceReadResponse() {
@Override
public InputStream openStream() throws IOException {
return inputStream;
}
@Override
public ExternalResourceMetaData getMetaData() {
return new DefaultExternalResourceMetaData(location, connection.getLastModified(), connection.getContentLength(), connection.getContentType(), null, null);
}
@Override
public void close() throws IOException {
inputStream.close();
}
};
} catch (FileNotFoundException e) {
return null;
} catch (Exception e) {
throw ResourceExceptions.getFailed(location, e);
}
}
use of org.gradle.internal.resource.metadata.DefaultExternalResourceMetaData in project gradle by gradle.
the class UrlExternalResource method getMetaData.
@Nullable
@Override
public ExternalResourceMetaData getMetaData(URI location, boolean revalidate) throws ResourceException {
try {
URL url = location.toURL();
URLConnection connection = url.openConnection();
try {
return new DefaultExternalResourceMetaData(location, connection.getLastModified(), connection.getContentLength(), connection.getContentType(), null, null);
} finally {
connection.getInputStream().close();
}
} catch (FileNotFoundException e) {
return null;
} catch (Exception e) {
throw ResourceExceptions.getFailed(location, e);
}
}
use of org.gradle.internal.resource.metadata.DefaultExternalResourceMetaData in project gradle by gradle.
the class UrlExternalResource method openResource.
@Nullable
@Override
public ExternalResourceReadResponse openResource(final ExternalResourceName location, boolean revalidate) throws ResourceException {
try {
URL url = location.getUri().toURL();
final URLConnection connection = url.openConnection();
final InputStream inputStream = connection.getInputStream();
return new ExternalResourceReadResponse() {
@Override
public InputStream openStream() {
return inputStream;
}
@Override
public ExternalResourceMetaData getMetaData() {
return new DefaultExternalResourceMetaData(location.getUri(), connection.getLastModified(), connection.getContentLength(), connection.getContentType(), null, null);
}
@Override
public void close() throws IOException {
inputStream.close();
}
};
} catch (FileNotFoundException e) {
return null;
} catch (Exception e) {
throw ResourceExceptions.getFailed(location.getUri(), e);
}
}
use of org.gradle.internal.resource.metadata.DefaultExternalResourceMetaData in project gradle by gradle.
the class UrlExternalResource method getMetaData.
@Nullable
@Override
public ExternalResourceMetaData getMetaData(ExternalResourceName location, boolean revalidate) throws ResourceException {
try {
URL url = location.getUri().toURL();
URLConnection connection = url.openConnection();
try {
return new DefaultExternalResourceMetaData(location.getUri(), connection.getLastModified(), connection.getContentLength(), connection.getContentType(), null, null);
} finally {
connection.getInputStream().close();
}
} catch (FileNotFoundException e) {
return null;
} catch (Exception e) {
throw ResourceExceptions.getFailed(location.getUri(), e);
}
}
use of org.gradle.internal.resource.metadata.DefaultExternalResourceMetaData in project gradle by gradle.
the class S3ResourceConnector method getMetaData.
public ExternalResourceMetaData getMetaData(URI location, boolean revalidate) {
LOGGER.debug("Attempting to get resource metadata: {}", location);
S3Object s3Object = s3Client.getMetaData(location);
if (s3Object == null) {
return null;
}
try {
ObjectMetadata objectMetadata = s3Object.getObjectMetadata();
return new DefaultExternalResourceMetaData(location, objectMetadata.getLastModified().getTime(), objectMetadata.getContentLength(), objectMetadata.getContentType(), objectMetadata.getETag(), // Passing null for sha1 - TODO - consider using the etag which is an MD5 hash of the file (when less than 5Gb)
null);
} finally {
IoActions.closeQuietly(s3Object);
}
}
Aggregations