Skip to content

Instantly share code, notes, and snippets.

@ddbj-repo
Created December 15, 2017 05:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ddbj-repo/bd58a6ca09c2d380d5ceafd4905a0e2e to your computer and use it in GitHub Desktop.
Save ddbj-repo/bd58a6ca09c2d380d5ceafd4905a0e2e to your computer and use it in GitHub Desktop.
import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.net.URL;
import java.net.HttpURLConnection;
/*
* (中略)
*/
/*
* この例では取得した画像をファイルに保存する。
*/
File outputFile = ....;
/*
* 覚えておいた Request ID を使って GET する。
*/
String requestId = "wabi_blast_1111-1111-1111-11-111-111111";
URL url = new URL("http://ddbj.nig.ac.jp/wabi/blast/" + requestId + "?imageId=" + imageId);
HttpURLConnection http = (HttpURLConnection)url.openConnection();
http.setRequestMethod("GET");
http.connect();
int responseCode = http.getResponseCode();
if (200<=responseCode && responseCode<=299) {
BufferedInputStream inputStream = new BufferedInputStream(http.getInputStream());
outputFile.createNewFile();
FileOutputStream outputStream new FileOutputStream(outputFile);
for (int data = inputStream.read(); -1!=(data = inputStream.read());) {
outputStream.write(data);
}
inputStream.close();
outputStream.close();
} else if (400<=responseCode && responseCode<=499) {
/*
* 入力値エラー等。
*/
} else {
/*
* その他
*/
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment