public static Data readFileAsData(String locationURL,String mime) throws IOException, NoSuchAlgorithmException { URL url = new URL(locationURL); URLConnection connection = url.openConnection(); if (!connection.getContentType().equalsIgnoreCase(mime)) { return null; } InputStream in = url.openStream(); ByteArrayOutputStream byteOut = new ByteArrayOutputStream(); byte[] block = new byte[10240]; int len; while ((len = in.read(block)) >= 0) { byteOut.write(block, 0, len); } in.close(); byte[] body = byteOut.toByteArray(); Data data = new Data(); data.setSize(body.length); data.setBodyHash(MessageDigest.getInstance("MD5").digest(body)); data.setBody(body); return data; }
@Override public boolean equals(Object that) { if (that == null) return false; if (that instanceof Data) return this.equals((Data)that); return false; }
public boolean equals(Data that) { if (that == null) return false; boolean this_present_bodyHash = true && this.isSetBodyHash(); boolean that_present_bodyHash = true && that.isSetBodyHash(); if (this_present_bodyHash || that_present_bodyHash) { if (!(this_present_bodyHash && that_present_bodyHash)) return false; if (TBaseHelper.compareTo(this.bodyHash, that.bodyHash) != 0) return false; } boolean this_present_size = true && this.isSetSize(); boolean that_present_size = true && that.isSetSize(); if (this_present_size || that_present_size) { if (!(this_present_size && that_present_size)) return false; if (this.size != that.size) return false; } boolean this_present_body = true && this.isSetBody(); boolean that_present_body = true && that.isSetBody(); if (this_present_body || that_present_body) { if (!(this_present_body && that_present_body)) return false; if (TBaseHelper.compareTo(this.body, that.body) != 0) return false; } return true; }
/** * Performs a deep copy on <i>other</i>. */ public Data(Data other) { System.arraycopy(other.__isset_vector, 0, __isset_vector, 0, other.__isset_vector.length); if (other.isSetBodyHash()) { this.bodyHash = new byte[other.bodyHash.length]; System.arraycopy(other.bodyHash, 0, bodyHash, 0, other.bodyHash.length); } this.size = other.size; if (other.isSetBody()) { this.body = new byte[other.body.length]; System.arraycopy(other.body, 0, body, 0, other.body.length); } }
public void write(TProtocol oprot) throws TException { validate(); oprot.writeStructBegin(STRUCT_DESC); if (this.bodyHash != null) { if (isSetBodyHash()) { oprot.writeFieldBegin(BODY_HASH_FIELD_DESC); oprot.writeBinary(this.bodyHash); oprot.writeFieldEnd(); } } if (isSetSize()) { oprot.writeFieldBegin(SIZE_FIELD_DESC); oprot.writeI32(this.size); oprot.writeFieldEnd(); } if (this.body != null) { if (isSetBody()) { oprot.writeFieldBegin(BODY_FIELD_DESC); oprot.writeBinary(this.body); oprot.writeFieldEnd(); } } oprot.writeFieldStop(); oprot.writeStructEnd(); }
case 3: // DATA if (field.type == TType.STRUCT) { this.data = new Data(); this.data.read(iprot); } else { TProtocolUtil.skip(iprot, field.type); case 9: // RECOGNITION if (field.type == TType.STRUCT) { this.recognition = new Data(); this.recognition.read(iprot); } else { TProtocolUtil.skip(iprot, field.type); case 13: // ALTERNATE_DATA if (field.type == TType.STRUCT) { this.alternateData = new Data(); this.alternateData.read(iprot); } else { TProtocolUtil.skip(iprot, field.type);
public Data deepCopy() { return new Data(this); }
/** * Create an ENML <en-media> tag for the specified Resource object. */ public static String createEnMediaTag(Resource resource) { return "<en-media hash=\"" + bytesToHex(resource.getData().getBodyHash()) + "\" type=\"" + resource.getMime() + "\"/>"; }
public void write(TProtocol oprot) throws TException { validate(); oprot.writeStructBegin(STRUCT_DESC); if (this.bodyHash != null) { if (isSetBodyHash()) { oprot.writeFieldBegin(BODY_HASH_FIELD_DESC); oprot.writeBinary(this.bodyHash); oprot.writeFieldEnd(); } } if (isSetSize()) { oprot.writeFieldBegin(SIZE_FIELD_DESC); oprot.writeI32(this.size); oprot.writeFieldEnd(); } if (this.body != null) { if (isSetBody()) { oprot.writeFieldBegin(BODY_FIELD_DESC); oprot.writeBinary(this.body); oprot.writeFieldEnd(); } } oprot.writeFieldStop(); oprot.writeStructEnd(); }
case 3: // DATA if (field.type == TType.STRUCT) { this.data = new Data(); this.data.read(iprot); } else { TProtocolUtil.skip(iprot, field.type); case 9: // RECOGNITION if (field.type == TType.STRUCT) { this.recognition = new Data(); this.recognition.read(iprot); } else { TProtocolUtil.skip(iprot, field.type); case 13: // ALTERNATE_DATA if (field.type == TType.STRUCT) { this.alternateData = new Data(); this.alternateData.read(iprot); } else { TProtocolUtil.skip(iprot, field.type);
public Data deepCopy() { return new Data(this); }
String hexHash = EvernoteUtil.bytesToHex(r.getData().getBodyHash()); noteContent.append("<en-media type=" + '"').append(r.getMime()); noteContent.append('"');
/** * Performs a deep copy on <i>other</i>. */ public Data(Data other) { System.arraycopy(other.__isset_vector, 0, __isset_vector, 0, other.__isset_vector.length); if (other.isSetBodyHash()) { this.bodyHash = new byte[other.bodyHash.length]; System.arraycopy(other.bodyHash, 0, bodyHash, 0, other.bodyHash.length); } this.size = other.size; if (other.isSetBody()) { this.body = new byte[other.body.length]; System.arraycopy(other.body, 0, body, 0, other.body.length); } }
public boolean equals(Data that) { if (that == null) return false; boolean this_present_bodyHash = true && this.isSetBodyHash(); boolean that_present_bodyHash = true && that.isSetBodyHash(); if (this_present_bodyHash || that_present_bodyHash) { if (!(this_present_bodyHash && that_present_bodyHash)) return false; if (TBaseHelper.compareTo(this.bodyHash, that.bodyHash) != 0) return false; } boolean this_present_size = true && this.isSetSize(); boolean that_present_size = true && that.isSetSize(); if (this_present_size || that_present_size) { if (!(this_present_size && that_present_size)) return false; if (this.size != that.size) return false; } boolean this_present_body = true && this.isSetBody(); boolean that_present_body = true && that.isSetBody(); if (this_present_body || that_present_body) { if (!(this_present_body && that_present_body)) return false; if (TBaseHelper.compareTo(this.body, that.body) != 0) return false; } return true; }
resource.setData(data); resource.setMime(mime); hexHash = EvernoteUtil.bytesToHex(data.getBodyHash()); note.addToResources(resource); noteContent += "<en-media type=" + '"' + resource.getMime() + '"' + " hash=" + '"' + hexHash + '"' + "/>";
@Override public boolean equals(Object that) { if (that == null) return false; if (that instanceof Data) return this.equals((Data)that); return false; }
Data typedOther = (Data)other; lastComparison = Boolean.valueOf(isSetBodyHash()).compareTo(typedOther.isSetBodyHash()); if (lastComparison != 0) { return lastComparison; if (isSetBodyHash()) { lastComparison = TBaseHelper.compareTo(this.bodyHash, typedOther.bodyHash); if (lastComparison != 0) { return lastComparison; lastComparison = Boolean.valueOf(isSetSize()).compareTo(typedOther.isSetSize()); if (lastComparison != 0) { return lastComparison; if (isSetSize()) { lastComparison = TBaseHelper.compareTo(this.size, typedOther.size); if (lastComparison != 0) { return lastComparison; lastComparison = Boolean.valueOf(isSetBody()).compareTo(typedOther.isSetBody()); if (lastComparison != 0) { return lastComparison; if (isSetBody()) { lastComparison = TBaseHelper.compareTo(this.body, typedOther.body); if (lastComparison != 0) { return lastComparison;
if (!(this_present_data && that_present_data)) return false; if (!this.data.equals(that.data)) return false; if (!(this_present_recognition && that_present_recognition)) return false; if (!this.recognition.equals(that.recognition)) return false; if (!(this_present_alternateData && that_present_alternateData)) return false; if (!this.alternateData.equals(that.alternateData)) return false;