/**
*
* Downloads a file.
*
* @param exportUrl the full url of the export link to download the file from.
* @param filepath path and name of the object to be saved as.
*
* @throws IOException
* @throws MalformedURLException
* @throws ServiceException
* @throws DocumentListException
*/
public void downloadFile(URL exportUrl, String filepath, DocsService client) throws IOException,
MalformedURLException, ServiceException, DocumentListException {
if (exportUrl == null || filepath == null) {
throw new DocumentListException("null passed in for required parameters");
}
MediaContent mc = new MediaContent();
mc.setUri(exportUrl.toString());
MediaSource ms = client.getMedia(mc);
InputStream inStream = null;
FileOutputStream outStream = null;
try {
inStream = ms.getInputStream();
outStream = new FileOutputStream(filepath);
int c;
while ((c = inStream.read()) != -1) {
outStream.write(c);
}
} finally {
if (inStream != null) {
inStream.close();
}
if (outStream != null) {
outStream.flush();
outStream.close();
}
}
}
java.net.ConnectException: Operation timed out
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:351)
at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:213)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:200)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:432)
at java.net.Socket.connect(Socket.java:529)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.connect(SSLSocketImpl.java:564)
at com.sun.net.ssl.internal.ssl.BaseSSLSocketImpl.connect(BaseSSLSocketImpl.java:141)
at sun.net.NetworkClient.doConnect(NetworkClient.java:163)
at sun.net.www.http.HttpClient.openServer(HttpClient.java:395)
at sun.net.www.http.HttpClient.openServer(HttpClient.java:530)
at sun.net.www.protocol.https.HttpsClient.<init>(HttpsClient.java:272)
at sun.net.www.protocol.https.HttpsClient.New(HttpsClient.java:329)
at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.getNewHttpClient(AbstractDelegateHttpsURLConnection.java:172)
at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:911)
at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:158)
at sun.net.www.protocol.https.HttpsURLConnectionImpl.connect(HttpsURLConnectionImpl.java:133)
at com.google.gdata.client.http.HttpGDataRequest.execute(HttpGDataRequest.java:503)
at com.google.gdata.client.http.GoogleGDataRequest.execute(GoogleGDataRequest.java:535)
at com.google.gdata.client.media.MediaService.getMediaResource(MediaService.java:234)
at com.google.gdata.client.media.MediaService.getMedia(MediaService.java:276)
at com.google.gdata.client.media.MediaService.getMedia(MediaService.java:302)
at com.mwp.google.tools.documents.DocumentList.downloadFile(DocumentList.java:699)
at com.mwp.google.tools.documents.Documents.delegateDocumentCopy(Documents.java:427)
at com.mwp.google.tools.documents.Documents.copyAllDocumentEntries(Documents.java:1010)
at com.mwp.google.tools.documents.Documents.migrateDocs(Documents.java:548)
at com.mwp.google.tools.documents.Documents.delegateMigrate(Documents.java:526)
at com.mwp.google.tools.documents.Documents.executeCommandArgs(Documents.java:1474)
at com.mwp.google.tools.documents.Documents.executeCommand(Documents.java:1446)
at com.mwp.google.tools.documents.Documents.run(Documents.java:1523)
at com.mwp.google.tools.documents.Documents.main(Documents.java:1613
Are you still having this issue? How long is it timing out after, the
download might be taking longer than that. You might need to set the
connect and read timeouts longer, uisng service.setConnectTimeout [1]
and service.setReadTimeout [2]
[1] http://code.google.com/apis/gdata/javadoc/com/google/gdata/client/Service.html#setConnectTimeout(int)
[2] http://code.google.com/apis/gdata/javadoc/com/google/gdata/client/Service.html#setReadTimeout(int)
Regards
--
Ali Afshar | www.googplus.org/ali | Google Developer Relations