if (!uploadedFilename.equals(request.getParameter("uploadedFilename"))) {
throw new IllegalStateException("Uploaded filename is incorrect: expecting " + request.getParameter("uploadedFilename") + " but got " + uploadedFilename);
}
GcsService service = GcsServiceFactory.createGcsService();
String mimeType;
ServletOutputStream outputStream = response.getOutputStream();
if (gsObjectName.contains("fake")) { //GCS Local File Upload Implementation is broken
log.warning("Using hacked blobstore-gcs hybrid test because the local gcs implementation is broken");
String blobKeyString = gsObjectName.substring(gsObjectName.indexOf("-") + 1, gsObjectName.lastIndexOf("-"));
DatastoreService datastoreService = DatastoreServiceFactory.getDatastoreService();
BlobInfoFactory blobInfoFactory = new BlobInfoFactory(datastoreService);
mimeType = blobInfoFactory.loadBlobInfo(new BlobKey(blobKeyString)).getContentType();
ByteArrayInputStream bais = new ByteArrayInputStream(BlobstoreServiceFactory.getBlobstoreService().fetchData(new BlobKey(blobKeyString), 0, BlobstoreService.MAX_BLOB_FETCH_SIZE - 1));
IOUtils.copyStream(bais, outputStream);
outputStream.write("_123".getBytes());
} else {
GcsFilename filename = new GcsFilename("GcsBucket", gsObjectName);
GcsFileMetadata metadata = service.getMetadata(filename);
if (metadata == null) {
throw new IllegalStateException("Null GCS metadata: " + filename);
}
mimeType = metadata.getOptions().getMimeType();
try (InputStream inputStream = Channels.newInputStream(service.openReadChannel(metadata.getFilename(), 0))) {
IOUtils.copyStream(inputStream, outputStream);
}
outputStream.write("_123".getBytes());
}