/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package nz.ac.canterbury.kraken;
import java.io.IOException;
import java.io.InputStream;
import java.util.logging.Level;
import java.util.logging.Logger;
import nz.co.wetstone.http.SimpleHTTPClient;
import nz.co.wetstone.util.JSONHelper;
import org.json.JSONException;
import org.json.JSONObject;
/**
*
* @author davidm
*/
public final class JKrakenResult {
private boolean success;
private String filename;
private long originalSize;
private long krakedSize;
private long savedBytes;
private String krakedUrl;
private String id;
private String error;
private InputStream krakedFile;
public JKrakenResult(JSONObject j) throws JSONException {
setError(JSONHelper.getStringSafe(j, "error"));
setFilename(JSONHelper.getStringSafe(j, "file_name"));
setId(JSONHelper.getStringSafe(j, "id"));
setKrakedSize(JSONHelper.getLongSafe(j, "kraked_size"));
setKrakedUrl(JSONHelper.getStringSafe(j, "kraked_url"));
setOriginalSize(JSONHelper.getLongSafe(j, "original_size"));
setSavedBytes(JSONHelper.getLongSafe(j, "saved_bytes"));
setSuccess(JSONHelper.getBooleanSafe(j, "success"));
SimpleHTTPClient client = new SimpleHTTPClient();
try {
setKrakedFile(client.grabRawStream(getKrakedUrl()));
} catch (IllegalStateException ex) {
Logger.getLogger(JKrakenResult.class.getName()).log(Level.SEVERE, "", ex);
} catch (IOException ex) {
Logger.getLogger(JKrakenResult.class.getName()).log(Level.SEVERE, "", ex);
}
}
public JKrakenResult() {
}
public InputStream getKrakedFile() {
return krakedFile;
}
public void setKrakedFile(InputStream krakedFile) {
this.krakedFile = krakedFile;
}
public String getError() {
return error;
}
public void setError(String error) {
this.error = error;
}
public boolean isSuccess() {
return success;
}
public void setSuccess(boolean success) {
this.success = success;
}
public String getFilename() {
return filename;
}
public void setFilename(String filename) {
this.filename = filename;
}
public long getOriginalSize() {
return originalSize;
}
public void setOriginalSize(long originalSize) {
this.originalSize = originalSize;
}
public long getKrakedSize() {
return krakedSize;
}
public void setKrakedSize(long krakedSize) {
this.krakedSize = krakedSize;
}
public long getSavedBytes() {
return savedBytes;
}
public void setSavedBytes(long savedBytes) {
this.savedBytes = savedBytes;
}
public String getKrakedUrl() {
return krakedUrl;
}
public void setKrakedUrl(String krakedUrl) {
this.krakedUrl = krakedUrl;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
}