diff --git a/.classpath b/.classpath new file mode 100644 index 0000000..e461bea --- /dev/null +++ b/.classpath @@ -0,0 +1,6 @@ + + + + + + diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ae3c172 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/bin/ diff --git a/.project b/.project new file mode 100644 index 0000000..eb69a7c --- /dev/null +++ b/.project @@ -0,0 +1,17 @@ + + + Restful + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + diff --git a/.settings/org.eclipse.core.resources.prefs b/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..379a0e3 --- /dev/null +++ b/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding//src/org/ntlab/radishforandroidstudio/framework/network/HttpAsyncConnection.java=UTF-8 diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..bb35fa0 --- /dev/null +++ b/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,11 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve +org.eclipse.jdt.core.compiler.compliance=1.8 +org.eclipse.jdt.core.compiler.debug.lineNumber=generate +org.eclipse.jdt.core.compiler.debug.localVariable=generate +org.eclipse.jdt.core.compiler.debug.sourceFile=generate +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.8 diff --git a/src/main/Main.java b/src/main/Main.java new file mode 100644 index 0000000..79279d5 --- /dev/null +++ b/src/main/Main.java @@ -0,0 +1,28 @@ +package main; + +import java.util.ArrayList; + +import main.RestApi.Method; + +public class Main { + + public static void main(String[] args) { + RestApi api = new RestApi(); + ArrayList queryParam = new ArrayList<>(); + ArrayList formParam = new ArrayList<>(); + ArrayList pathParam = new ArrayList<>(); + final int ACCOUNT_NUM = 2; + for (int i = 0; i < ACCOUNT_NUM; i++) { + api.setAccount("http://nitta-lab-www.is.konan-u.ac.jp:8080/CactusServer/rest/accounts/"); + } + formParam.add(new RestParam("userID", "dee")); + formParam.add(new RestParam("userName", "abc")); + formParam.add(new RestParam("userPass", "abc")); + api.setupRestTest(Method.GET, queryParam, formParam, pathParam); + api.doRestTest(); + for (int i = 0; i < ACCOUNT_NUM; i++) { + System.out.println(api.getResult(i)); + } + } + +} diff --git a/src/main/RestAccount.java b/src/main/RestAccount.java new file mode 100644 index 0000000..3cc824c --- /dev/null +++ b/src/main/RestAccount.java @@ -0,0 +1,12 @@ +package main; + +import org.ntlab.radishforandroidstudio.framework.network.HttpAsyncConnection; + +public class RestAccount extends HttpAsyncConnection { + + public RestAccount(String url) { + super(url); + // TODO Auto-generated constructor stub + } + +} diff --git a/src/main/RestApi.java b/src/main/RestApi.java new file mode 100644 index 0000000..e6cc871 --- /dev/null +++ b/src/main/RestApi.java @@ -0,0 +1,76 @@ +package main; + +import java.util.ArrayList; + +public class RestApi { + private ArrayList accounts = new ArrayList<>(); + private ArrayList result = new ArrayList<>(); + private Method type; + private ArrayList queryParam; + private ArrayList formParam; + private ArrayList pathParam; + + public void setAccount(String url) { + accounts.add(new RestAccount(url)); + } + + public RestAccount getAccount(int num) { + return accounts.get(num); + } + + public String getResult(int num) { + return result.get(num); + } + + public void setupRestTest(Method method, ArrayList queryParam, ArrayList formParam, + ArrayList pathParam) { + this.type = method; + this.queryParam = queryParam; + this.formParam = formParam; + this.pathParam = pathParam; + } + + public void doRestTest() { + if (type == null) + return; + for (RestAccount account : accounts) { + switch (type) { + case GET: + account.doGet(); + break; + case POST: + account.doPost(); + break; + case PUT: + account.doPut(); + break; + case DELETE: + account.doDelete(); + break; + } + addParam(account); + account.doAnything(); + result.add(account.doReceive()); + } + } + + private void addParam(RestAccount account) { + if (queryParam != null) + for (RestParam param : queryParam) { + account.addQueryParam(param.key, param.value); + } + if (formParam != null && type != Method.GET) + for (RestParam param : formParam) { + account.addFormParam(param.key, param.value); + } + if (pathParam != null) + for (String param : pathParam) { + account.addPathParam(param); + } + } + + public enum Method { + GET, POST, PUT, DELETE + }; + +} diff --git a/src/main/RestParam.java b/src/main/RestParam.java new file mode 100644 index 0000000..2f10b51 --- /dev/null +++ b/src/main/RestParam.java @@ -0,0 +1,11 @@ +package main; + +public class RestParam { + public String key; + public String value; + + public RestParam(String key, String value) { + this.key = key; + this.value = value; + } +} diff --git a/src/org/ntlab/radishforandroidstudio/framework/network/CallBack.java b/src/org/ntlab/radishforandroidstudio/framework/network/CallBack.java new file mode 100644 index 0000000..1e9238b --- /dev/null +++ b/src/org/ntlab/radishforandroidstudio/framework/network/CallBack.java @@ -0,0 +1,6 @@ +package org.ntlab.radishforandroidstudio.framework.network; + + +public interface CallBack { + public void onResponse(String response); +} diff --git a/src/org/ntlab/radishforandroidstudio/framework/network/HttpAsyncConnection.java b/src/org/ntlab/radishforandroidstudio/framework/network/HttpAsyncConnection.java new file mode 100644 index 0000000..0df92c3 --- /dev/null +++ b/src/org/ntlab/radishforandroidstudio/framework/network/HttpAsyncConnection.java @@ -0,0 +1,170 @@ +package org.ntlab.radishforandroidstudio.framework.network; + +import java.io.BufferedReader; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.OutputStream; +import java.net.HttpURLConnection; +import java.net.URL; + +abstract public class HttpAsyncConnection { + + private HttpURLConnection conn = null; + private String baseUrl = null; + private String queryParams = ""; + private String pathParams = ""; + private String formParams = ""; + private CallBack callBack = null; + + private String method; + private static String clientSessionID = null; + + public HttpAsyncConnection(String url) { + baseUrl = url; + } + + public void doPost() { + setMethod("POST"); + } + + public void doGet() { + setMethod("GET"); + } + + public void doPut() { + setMethod("PUT"); + } + + public void doDelete() { + setMethod("DELETE"); + } + + public void setCallBack(CallBack callBack) { + this.callBack = callBack; + } + + private void setMethod(String method) { + this.method = method; + } + + // request + public void doAnything() { + try { + if (conn == null) { + if (queryParams == null || queryParams.length() == 0) { + conn = (HttpURLConnection) new URL(baseUrl + pathParams).openConnection(); + } else { + conn = (HttpURLConnection) new URL(baseUrl + pathParams + "?" + queryParams).openConnection(); + } + } + conn.setReadTimeout(10000 /* milliseconds */); + conn.setConnectTimeout(15000 /* milliseconds */); + // POST or GET or PUT or DELETE + conn.setRequestMethod(method); + + if (formParams.length() > 0) { + conn.setDoOutput(true); + if (clientSessionID != null) { + conn.setRequestProperty("Cookie", clientSessionID); + } + OutputStream out = conn.getOutputStream(); + out.write(formParams.getBytes("UTF-8")); + out.flush(); + out.close(); + formParams = ""; + } + pathParams = ""; + queryParams = ""; + + conn.connect(); + + if (clientSessionID == null) { + clientSessionID = conn.getHeaderField("Set-Cookie"); + + } + } catch (IOException e) { + notConnection(); + e.printStackTrace(); + } + } + + // response + public String doReceive() { + BufferedReader reader; + InputStream in = null; + try { + System.out.println(conn.getResponseCode()); + in = conn.getInputStream(); + reader = new BufferedReader(new InputStreamReader(in)); + String line; + StringBuilder builder = new StringBuilder(); + while ((line = reader.readLine()) != null) + builder.append(line); + reader.close(); + if (conn != null) + conn.disconnect(); + return builder.toString(); + } catch (FileNotFoundException e) { // IOException をキャッチするより先に FileNotFoundException をキャッチしないと IOException + // のキャッチブロックに行くのでこうする + System.err.println(e); + InputStream err = null; + try { + err = conn.getErrorStream(); + System.out.println(err.read()); + // 4xx または 5xx なレスポンスのボディーを読み取る + // ... + } catch (IOException e2) { + System.err.println(e2); + } finally { + if (err != null) { + try { + err.close(); + } catch (IOException e3) { + System.err.println(e3); + } + } + } + } catch (IOException e) { + System.err.println(e); + } finally { + if (in != null) { + try { + in.close(); + } catch (IOException e) { + System.err.println(e); + } + } + if (conn != null) { + conn.disconnect(); + } + } + return null; + } + + public void notConnection() { + }; + + /** + * @param key + * @param value + */ + public void addQueryParam(String key, String value) { + if (queryParams.length() > 0) { + queryParams += ("&"); + } + queryParams += (key + "=" + value); + } + + public void addFormParam(String key, String value) { + if (formParams.length() > 0) { + formParams += "&"; + } + formParams += (key + "=" + value); + } + + public void addPathParam(String param) { + pathParams += "/" + param; + } +} diff --git a/src/org/ntlab/radishforandroidstudio/framework/network/HttpClient.java b/src/org/ntlab/radishforandroidstudio/framework/network/HttpClient.java new file mode 100644 index 0000000..1f21afe --- /dev/null +++ b/src/org/ntlab/radishforandroidstudio/framework/network/HttpClient.java @@ -0,0 +1,262 @@ +package org.ntlab.radishforandroidstudio.framework.network; + +import java.io.BufferedWriter; +import java.io.IOException; +import java.io.OutputStreamWriter; +import java.net.HttpURLConnection; +import java.net.MalformedURLException; +import java.net.URL; +import java.util.logging.Logger; +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; +import java.util.Queue; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.LinkedBlockingQueue; + +/** + * * * @author ���� �a�P * + */ +public abstract class HttpClient { + + private URL url; + private static String clientSessionID; + // ���b�Z�[�WID���L�[�Ƃ��� + private Map HttpReceiverContainer; + private Queue HttpMessageContainer; + private String sendMsg; + private long latestSentMsgID; + private int maxConnection; + /** + * ���V�[�o�[�̐������E���ԁi�~���b�j + */ + private long receiverAliveTime; + + public HttpClient(String url) { + try { + this.url = new URL(url); + } catch (MalformedURLException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + this.latestSentMsgID = -1L; + // �f�t�H���g�̍ő�R�l�N�V������ + this.maxConnection = 5; + // �f�t�H���g�̃��V�[�o�[�̐������ԁi�~���b�j + this.receiverAliveTime = 60000L; + this.HttpReceiverContainer = // �X���b�h�Z�[�t��Map + new ConcurrentHashMap(); + this.HttpMessageContainer = new LinkedBlockingQueue(); + } + + /** + * ���V�[�o�[��new���邽�߂����̃N���X + * + * @param http + * :���V�[�o�[�̃R���X�g���N�^�ɓn�� + * @param msgID + * :���V�[�o�[�̃R���X�g���N�^�ɓn�� + * @param client + * :���V�[�o�[�̃R���X�g���N�^�ɓn�� + * @return ���V�[�o�[�̃C���X�^���X + */ + protected abstract HttpReceiver createReceiver(HttpURLConnection http, String msgID, HttpClient client); + + /** + * �T�[�o�[�ւ̍ő�ڑ�����ݒ肷�� + * + * @param maxConnection + * :�T�[�o�ւ̍ő�ڑ����i�f�t�H���g��5�j + */ + public void setMaxConnection(int maxConnection) { + this.maxConnection = maxConnection; + } + + /** + * ���V�[�o�[�̐����”\���Ԃ�ݒ肷�� ���̎��Ԃ��߂���ƁA��M�𒆎~���܂� + * + * @param aliveTime + */ + public void setReceiverAliveTime(long aliveTime) { + this.receiverAliveTime = aliveTime; + } + + /** + * �T�[�o�[�ɑ���f�[�^�����b�Z�[�W�Ƃ��ăZ�b�g���� + * + * @param name + * :�p�����[�^�� + * @param value + * :�p�����[�^�̒l + */ + public void setParameter(String name, String value) { + if (this.sendMsg == null) { + this.sendMsg = name + "=" + value; + } else { + this.sendMsg += ("&" + name + "=" + value); + } + } + + /** + * �T�[�o�[�Ƀ��b�Z�[�W�𑗐M���� �i���b�Z�[�W��setParameter()�ō쐬�����j + * + * @return:���b�Z�[�WID + */ + public String send() { + try { + this.latestSentMsgID++; + if (this.latestSentMsgID == Long.MAX_VALUE) { + // long�����E�l�ɒB�����烊�Z�b�g + this.latestSentMsgID = 0L; + } + if (this.maxConnection < this.HttpReceiverContainer.size()) { + this.HttpMessageContainer.offer(new HttpMessage(Long.toString(this.latestSentMsgID), this.sendMsg)); + } else { + HttpReceiver r = this.createReceiver(this.sendMsgToServer(this.sendMsg), + Long.toString(this.latestSentMsgID), this); + r.start(); + this.HttpReceiverContainer.put(r.getMsgID(), r); + } + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + // ������ + this.sendMsg = null; + // ���b�Z�[�WID ��Ԃ� + return Long.toString(this.latestSentMsgID); + } + + /** + * msgID�ɍ��v����Receiver��ArrayList����폜���� ��HttpReceiver�ȊO����̌Ăяo���֎~�� + * + * @param msgID + * :���b�Z�[�WID + */ + void removeTerminatedReceiver(String msgID) { + this.HttpReceiverContainer.remove(msgID); + try { + /* HttpMessageContainer�ɕۗ�����Ă��郁�b�Z�[�W���������� */ + HttpMessage httpMsg; + if ((httpMsg = this.HttpMessageContainer.poll()) != null) { + HttpReceiver r = this.createReceiver(this.sendMsgToServer(httpMsg.getMessage()), httpMsg.getMsgID(), + this); + r.start(); + this.HttpReceiverContainer.put(r.getMsgID(), r); + } + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + /** + * �T�[�o�[����̕ԐM����M�������ǂ�����Ԃ� + * + * @param msgID + * :���b�Z�[�WID + * @return true :��M�ς� false :��M�� / + */ + public boolean hasReceived(String msgID) { // HttpMessageContainer���猟�� + int arraySize = this.HttpMessageContainer.size(); + HttpMessage[] arrayHttpMessage = this.HttpMessageContainer.toArray(new HttpMessage[arraySize]); + for (int i = 0; i < arraySize; i++) { + // �L���[��z��ɂ��āA�S�Ă̗v�f��msgID���`�F�b�N���Ă��� + if (arrayHttpMessage[i].getMsgID().equals(msgID)) { + return false; + } + } + /* + * HttpReceiverContainer���猟�� + */ + // �X���b�h�̊J�n���Ԃ��`�F�b�N���āA���Ԃ��o�������Ă�����j������ + HttpReceiver receiver = this.HttpReceiverContainer.get(msgID); + if (receiver != null) { + long nowTime = System.currentTimeMillis(); + long passedTime = nowTime - receiver.getStartTime(); + if (this.receiverAliveTime < (nowTime - receiver.getStartTime())) { + // ���V�[�o�[�����X�g����폜���� + this.removeTerminatedReceiver(msgID); + // ��M�𒆒f���� + receiver.stopReceive(); + // �X���b�h�����荞�ݏ�Ԃɂ��� + receiver.interrupt(); + // �x����\�� + Logger.getLogger(Logger.GLOBAL_LOGGER_NAME) + .warning("Connection time out: " + Long.toString(passedTime) + " (ms)"); + } + // HttpReceiver�̃��X�g�Ɋ܂܂�Ă�����false��Ԃ� + return false; + } + /* + * HttpMessageContainer��HttpReceiverContainer����A �w���msgID�����‚���Ȃ��ꍇ�́A ��M�����������Ƃ݂Ȃ� + * �i���݂��Ȃ�msgID����M���������Ƃ݂Ȃ����j + */ + return true; + } + + /** + * msgID�Ŏw�肵�����b�Z�[�W���A���Ă���܂ŁA�҂� + * + * @param msgID + * :���b�Z�[�WID + */ + public void waitForResponse(String msgID) { + try { + while (!this.hasReceived(msgID)) { + Thread.sleep(1L); + } + } catch (InterruptedException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + public HttpReceiver getReceiver(String msgID) { + return this.HttpReceiverContainer.get(msgID); + } + + /** + * �T�[�o�[�Ƀ��b�Z�[�W�𑗐M���A��M��ԂɈڍs����HttpURLConnection��Ԃ� + * + * @param sendMsg + * :�T�[�o�[�ɑ��郁�b�Z�[�W + * @return ���b�Z�[�W���M�ς݂�HttpURLConncection + * @throws IOException + */ + private HttpURLConnection sendMsgToServer(String sendMsg) throws IOException { + /* + * HttpURLConnection�́A �C���X�^���X�����˃T�[�o�[�ւ̃��N�G�X�g�i�f�[�^���M�j�˃T�[�o�[����̃��X�|���X�i�f�[�^��M�j + * �Ƃ����T�C�N�����Ƃ�Ȃ��Ƃ����Ȃ��B + */ + HttpURLConnection http; + http = (HttpURLConnection) this.url.openConnection(); // �T�[�o�[�ɐڑ� + http.setRequestMethod("POST"); + http.setDoOutput(true); + // keepAlive���Ȃ��ݒ� + // http.setRequestProperty("Connection", "close"); + if (this.clientSessionID != null) { + // �Z�b�V����ID���ݒ肳��Ă�����t�����đ��M + http.setRequestProperty("Cookie", this.clientSessionID); + } + // ���b�Z�[�W���M + BufferedWriter writer = new BufferedWriter( + // ���{��̕��������h�~�̂��߃T�[�o�[�ɑ��M���镶���R�[�h���w�肷�� + new OutputStreamWriter(http.getOutputStream(), "UTF-8")); + if (sendMsg == null) { + // sendMsg��null�Ȃ�A�����Ȃ�������𑗂� + sendMsg = ""; + } + writer.write(sendMsg); + writer.flush(); + writer.close(); + /* + * �f�[�^�̑��M�̑O�ɁA�f�[�^�̎�M�͏o���Ȃ��̂ŁA�����ɋL�q���� + */ + if (this.clientSessionID == null) { + // �Z�b�V�����������Ƃ��́A�ݒ肵�Ă��� + this.clientSessionID = http.getHeaderField("Set-Cookie"); + } + return http; + } +} \ No newline at end of file diff --git a/src/org/ntlab/radishforandroidstudio/framework/network/HttpMessage.java b/src/org/ntlab/radishforandroidstudio/framework/network/HttpMessage.java new file mode 100644 index 0000000..c35b0e7 --- /dev/null +++ b/src/org/ntlab/radishforandroidstudio/framework/network/HttpMessage.java @@ -0,0 +1,20 @@ +package org.ntlab.radishforandroidstudio.framework.network; + +public class HttpMessage { + + private String msgID; + private String message; + + public HttpMessage(String msgID, String message) { + this.msgID = msgID; + this.message = message; + } + + public String getMsgID() { + return this.msgID; + } + + public String getMessage() { + return this.message; + } +} \ No newline at end of file diff --git a/src/org/ntlab/radishforandroidstudio/framework/network/HttpReceiver.java b/src/org/ntlab/radishforandroidstudio/framework/network/HttpReceiver.java new file mode 100644 index 0000000..29bf465 --- /dev/null +++ b/src/org/ntlab/radishforandroidstudio/framework/network/HttpReceiver.java @@ -0,0 +1,143 @@ +package org.ntlab.radishforandroidstudio.framework.network; + +import java.io.BufferedReader; +import java.io.DataInputStream; +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStreamReader; +import java.net.HttpURLConnection; +import java.net.URL; + +/** + * * HTTP�ɂ��T�[�o�[����̃��b�Z�[�W�̎�M�y�уt�@�C���̃_�E�����[�h���o����N���X * @author ���� �a�P * + */ +public abstract class HttpReceiver extends Thread { + + private final HttpURLConnection http; + private final String msgID; + private HttpClient httpClient; + /** + * ���̃X���b�h���J�n�������� + */ + private long taskStartTime; + + public HttpReceiver(HttpURLConnection http, String msgID, HttpClient client) { + this.http = http; + this.msgID = msgID; + this.httpClient = client; + // �X���b�h���J�n�����܂ł̃^�C�����O������̂ŁA�C���X�^���X�����܂ꂽ���Ԃ��L�^ + this.taskStartTime = System.currentTimeMillis(); + } + + public abstract void recieve(String s); + + public void run() { + // �J�n���Ԃ��L�^ + this.taskStartTime = System.currentTimeMillis(); + try { + // �T�[�o�[����̕ԐM����M���A���V�[�o�[�ɓn�� + String s = this.receiveFromServer(http); + recieve(s); + // System.out.println(s); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + // ���g���AHttpClient��List����폜 + this.httpClient.removeTerminatedReceiver(this.msgID); + } + + /** + * ���b�Z�[�WID���擾���� + * + * @return ���b�Z�[�WID + */ + public String getMsgID() { + return this.msgID; + } + + /** + * @return ���̃X���b�h���J�n�������� + */ + long getStartTime() { + return this.taskStartTime; + } + + /** + * �t�@�C���̃_�E�����[�h������ + * + * @param url + * �T�[�o�[��̃t�@�C����URL + * @param outputFilePath + * �����o����̃p�X + */ + protected void download(String url, String outputFilePath) { + try { + // �����̃p�X�����ɐ�΃p�X��File�̃C���X�^���X����� + File outputFile = (new File(outputFilePath)).getAbsoluteFile(); + // �t�@�C���ۑ���ɕK�v�ȃf�B���N�g�����쐬 + outputFile.getParentFile().mkdirs(); + System.out.println("download from " + url + "\n save to " + outputFile.getAbsolutePath()); + /* + * �ۑ�����t�@�C���� FileOutputStream ���\�z���܂��B + */ + FileOutputStream fos = new FileOutputStream(outputFile); + HttpURLConnection urlConnection = (HttpURLConnection) (new URL(url)).openConnection(); + urlConnection.connect(); + // �t�@�C���T�C�Y���擾 + int fileSize = urlConnection.getContentLength(); + int num; + // �t�@�C�������o�C�g�P�ʂŎ�M���邩��ݒ肷�� + byte buf[] = new byte[fileSize]; + /* DataInputStream���g�p���ăt�@�C���ɏ����o���܂��B */ + DataInputStream dis = new DataInputStream(urlConnection.getInputStream()); + while ((num = dis.read(buf)) != -1) { + fos.write(buf, 0, num); + } + dis.close(); + fos.close(); + } catch (Exception e) { + e.printStackTrace(); + } + } + + /** + * �T�[�o�[����̃��b�Z�[�W����M���邽�߂̃��[�_�[ ���̃X���b�h�����~���ꂽ�ꍇ�AHttpClient���烊�[�_�[��close���閽�߂𑗂邽�� �����ɒu�� + */ + private BufferedReader reader; + + /** + * �T�[�o�[����̕ԐM����M���� + * + * @param http + * :���b�Z�[�W���T�[�o�[�ɑ��M�ς݂�HttpURLConnection + * @return �T�[�o�[����̕ԐM + * @throws IOException + */ + private String receiveFromServer(HttpURLConnection http) throws IOException { + this.reader = new BufferedReader( + // ���{��̕��������h�~�̂��߂ɂ����ŕ����R�[�h���w�肷�� + new InputStreamReader(http.getInputStream(), "UTF-8")); + StringBuffer buf = new StringBuffer(); + // readLine��null�ɂȂ�܂ő����� + for (String line = ""; line != null; line = this.reader.readLine()) { + // �V����line��A�� + buf.append(line); + } + this.reader.close(); + return buf.toString(); + } + + /** + * ��M�𒆎~���� + */ + void stopReceive() { + try { + this.reader.close(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } +} \ No newline at end of file