syncloud.google.docs.GDocsRetryingFileCreator Maven / Gradle / Ivy
package syncloud.google.docs;
import syncloud.core.log.Logger;
import syncloud.google.docs.model.DocsUrl;
import syncloud.google.docs.model.DocsContent;
import syncloud.google.docs.model.Entry;
import syncloud.storage.IFile;
import syncloud.storage.InputStreamProvider;
import java.io.IOException;
import java.io.InputStream;
public class GDocsRetryingFileCreator extends ExponentialBackoff {
private static Logger logger = Logger.getLogger(GDocsRetryingFileCreator.class);
private InputStreamProvider inputStreamProvider;
private long length;
private String name;
private ResumableUploader resumableUploader = new ResumableUploader();
private GDocsFolder folder;
GDocsRetryingFileCreator(GDocsFolder folder) {
this.folder = folder;
}
public ResumableUploader getResumableUploader() {
return resumableUploader;
}
public IFile create(InputStreamProvider is, long length, String name) throws IOException {
this.inputStreamProvider = is;
this.length = length;
this.name = name;
return run();
}
@Override
public IFile process() throws NotReady, IOException {
try {
InputStream stream = inputStreamProvider.getData();
Entry fileContent = resumableUploader.createFileContent(
folder.getRequestFactory(),
DocsUrl.resumableUploadLink(folder.getEntry().getResumable()),
stream,
length,
"image/jpeg",
DocsContent.createFileContent(name));
return new GDocsFile(fileContent, folder.getRequestFactory(), folder);
} catch (Throwable e) {
logger.debug(e.getMessage());
logger.info("will start over resumable upload");
throw new NotReady();
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy