バイトを読み取って、システム コンソールに出力できます。しかし、GAE はファイル作成をサポートしていないため、StackOverflow を検索したところ、GAE blobstore に書き込むことができることがわかりました。しかし、私はGAEが初めてなので、どうすればいいのかわかりません..
public void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException {
resp.setContentType("text/html;charset=UTF-8");
// resp.setContentType("text/plain");
PrintWriter out = resp.getWriter();
try {
ServletFileUpload upload = new ServletFileUpload();
FileItemIterator iterator = upload.getItemIterator(req);
// out.println("<html><body>");
while (iterator.hasNext()) {
FileItemStream item = iterator.next();
InputStream in = item.openStream();
if (item.isFormField()) {
out.println("<br />Got a form field: " + item.getFieldName());
} else {
out.println("<br />Got an uploaded file: " + item.getFieldName() + ", name = " + item.getName());
ZipInputStream zis = new ZipInputStream(
new BufferedInputStream( in ));
ZipEntry entry;
// Read each entry from the ZipInputStream until no
// more entry found indicated by a null return value
// of the getNextEntry() method.
byte[] buf = new byte[10244];
int len;
while ((entry = zis.getNextEntry()) != null) {
out.println("Unzipping: " + entry.getName());
FileService fileService = FileServiceFactory.getFileService();
AppEngineFile file = fileService.createNewBlobFile("text/plain");
boolean lock = false;
FileWriteChannel writeChannel = fileService.openWriteChannel(file, lock);
PrintWriter outter = new PrintWriter(Channels.newWriter(writeChannel, "UTF8"));
StringBuilder sb = new StringBuilder(buf.length);
if (entry.getName().equalsIgnoreCase("booking.csv")) {
int count = 0;
while ((len = zis.read(buf, 0, buf.length)) != -1) {
//I'm trying to write byte[] into blobstore instead of printing using
//System.out.write(buf, 0, len);
}
何かアドバイス?