Created
December 15, 2017 05:18
-
-
Save ddbj-repo/bd58a6ca09c2d380d5ceafd4905a0e2e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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