1
簡而言之,由於GAE無法寫入文件系統,因此我決定將數據保存到數據存儲中(使用JDO)。現在,我希望逐字節地檢索數據並將其作爲輸入流傳遞給客戶端。 gwtupload庫(http://code.google.com/p/gwtupload/)中有代碼(見下文),它在GAE上中斷,因爲它寫入系統文件系統。我希望能夠提供一個GAE移植解決方案。如何從appengine數據存儲中逐字節讀取實體對象
public static void copyFromInputStreamToOutputStream(InputStream in, OutputStream out) throws IOException {
byte[] buffer = new byte[100000];
while (true) {
synchronized (buffer) {
int amountRead = in.read(buffer);
if (amountRead == -1) {
break;
}
out.write(buffer, 0, amountRead);
}
}
in.close();
out.flush();
out.close();
}
一個解決我已經試過(沒有工作)是檢索數據存儲中的數據作爲一個像這樣的資源:
InputStream resourceAsStream = null;
PersistenceManager pm = PMF.get().getPersistenceManager();
try {
Query q = pm.newQuery(ImageFile.class);
lf = q.execute();
resourceAsStream = getServletContext().getResourceAsStream((String) pm.getObjectById(lf));
} finally {
pm.close();
}
if (lf != null) {
response.setContentType(receivedContentTypes.get(fieldName));
copyFromInputStreamToOutputStream(resourceAsStream, response.getOutputStream());
}
我歡迎您的建議。
問候
您是否試圖序列化客戶端/服務器之間的POJO? – 2011-04-07 02:58:17
不!我基本上試圖將文件上傳到GAE,使用GWT作爲客戶端。在進行上傳時,我想逐字節地監視它,如進度條或%讀數。 – drecute 2011-04-10 17:37:24