我是谷歌云存储 API 以及使用服务器的新手。我正在尝试使用 Eclipse 的 IDE 用 Java 编写一个 Web 应用程序,以读取存储在谷歌云存储中的文件。我有要在服务器端读取文件的代码,但不知道如何修改客户端的示例代码,以便它支持 httpServlet 而不是 RemoteServiceServlet。任何帮助或建议将不胜感激!
下面是我在服务器端的代码。
package com.google.gwt.sample.interfacecloud.server;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.nio.channels.Channels;
import java.util.ArrayList;
import javax.servlet.http.*;
import com.google.gwt.sample.interfacecloud.client.GreetingService;
import com.google.appengine.api.files.AppEngineFile;
import com.google.appengine.api.files.FileReadChannel;
import com.google.appengine.api.files.FileService;
import com.google.appengine.api.files.FileServiceFactory;
import com.google.appengine.api.files.FileWriteChannel;
import com.google.appengine.api.files.GSFileOptions.GSFileOptionsBuilder;
@SuppressWarnings("serial")
public class CloudInteraction extends HttpServlet implements GreetingService{
public static final String BUCKETNAME = "obd_data";
public static final String FILENAME = "data.txt";
@Override
public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException
{
resp.setContentType("text/plain");
String filename = "/gs/" + BUCKETNAME + "/" + FILENAME;
FileService fileService = FileServiceFactory.getFileService();
AppEngineFile readableFile = new AppEngineFile(filename);
FileReadChannel readChannel =
fileService.openReadChannel(readableFile, false);
BufferedReader reader =
new BufferedReader(Channels.newReader(readChannel, "UTF8"));
String line = reader.readLine();
resp.getWriter().println("READ:"+line);
System.out.println(line);
readChannel.close();
}
@Override
public String greetServer(String name) throws IllegalArgumentException {
// TODO Auto-generated method stub
return null;
}
}