星期四, 7月 07, 2011

A Vaadin resource for the blobstore

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
public class BlobstoreResource implements ApplicationResource {
// variables skipped
public BlobstoreResource(String keyStr, Application application) {
this.application = application;
this.blobKey = new BlobKey(keyStr);
this.blobInfo = new BlobInfoFactory().loadBlobInfo(blobKey);
if (blobInfo == null)
; // handle missing blob here
application.addResource(this);
}
 
@Override
public String getMIMEType() {
return blobInfo.getContentType();
}
 
@Override
public DownloadStream getStream() {
InputStream inputStream;
try {
inputStream = new BlobstoreInputStream(blobKey);
} catch (IOException e) {
return null;
}
 
final DownloadStream ds = new DownloadStream(inputStream,
getMIMEType(), getFilename());
ds.setBufferSize(getBufferSize());
ds.setCacheTime(cacheTime);
return ds;
}
 
// other methods skipped ...
}

沒有留言: