📄 streaminitiation.java
字号:
return fDescription; } /** * Sets the description of the file * *@param aDescription The new description */ public void setDescription(String aDescription) { this.fDescription = aDescription; } /** * Gets the md5 hash of the file * *@return The md5 hash of the file, or <tt>null</tt> if it isn't available */ public String getHash() { return fHash; } /** * Sets the md5 hash of the file * *@param aHash The new md5 hash of the file */ public void setHash(String aHash) { this.fHash = aHash; } /** * Gets the creation date of the file * *@return The creation date of the file, or <tt>null</tt> if it isn't available */ public String getDate() { return fDate; } /** * Gets the <tt>File</tt> object for this file * *@return The <tt>File</tt> for this file, or <tt>null</tt> if it's not available */ public File getFile() { return fFile; } /** * Sets the <tt>File</tt> object for this file * *@param aFile The <tt>File</tt> object for this file */ public void setFile(File aFile) { this.fFile = aFile; } /** * Returns the XML representation of this packet * *@return Returns the XML representation of this packet */ public String getXML() { StringBuffer buf = new StringBuffer(); buf.append("<file xmlns=\"").append(PROFILE).append("\""); if (getFileName() != null) { buf.append(" name=\"").append(getFileName()).append("\""); } if (getFileSize() != 0) { buf.append(" size=\"").append(getFileSize()).append("\""); } if (getDate() != null) { buf.append(" date=\"").append(getDate()).append("\""); } if (getHash() != null) { buf.append(" hash=\"").append(getHash()).append("\""); } buf.append(">"); if (getDescription() != null) { buf.append("<desc>").append(getDescription()).append("</desc>"); } buf.append("</file>"); return buf.toString(); } /** * returns MD5 sum of a file * *@return returns the md5 sum of a file */ public String createMD5Sum() { String out = ""; try { byte[] digest; MessageDigest md = MessageDigest.getInstance("MD5"); BufferedInputStream bis = new BufferedInputStream(new FileInputStream(fFile)); byte[] buff = new byte[1024]; int chunk = 1024; int bytesRead = 0; while ((bytesRead = bis.read(buff, 0, chunk)) != -1) { md.update(buff, 0, bytesRead); } digest = md.digest(); String hexChar = null; if (digest != null) { for (int i = 0; i < digest.length; i++) { if (digest[i] > 0) { hexChar = Integer.toHexString(digest[i]); } else if (digest[i] < 0) { hexChar = Integer.toHexString(digest[i]).substring(6); } else { hexChar = "00"; } out += hexChar; } } return out; } catch (FileNotFoundException e) { return null; } catch (NoSuchAlgorithmException e) { return null; } catch (IOException e) { } return null; } } /** * class that will hold feature information re-using DataForm code to * */ public static class Feature { private final static String BYTESTREAMS_FEATURE = "http://jabber.org/protocol/bytestreams"; private final static String IBB_FEATURE = "http://jabber.org/protocol/ibb"; DataForm fDataForm; int preferred = -1; /** * Creates the "features" portion of the StreamInitiation packet */ public Feature(int type) { this("form"); preferred = type; createForm(); } public Feature() { this(-1); } /** * Adds the various data fields to the data form **/ private void createForm() { FormField field = new FormField("stream-method"); field.setType(FormField.TYPE_LIST_SINGLE); if(preferred == -1 || preferred == FileTransferManager.TYPE_SOCKS5) field.addOption(new FormField.Option("http://jabber.org/protocol/bytestreams")); if(preferred == -1 || preferred == FileTransferManager.TYPE_IBB) field.addOption(new FormField.Option("http://jabber.org/protocol/ibb")); fDataForm.addField(field); } /** * Creates the "features" portion of the StreamInitiation object * *@param aDataFormType The type of data form you wish to use for this packet */ public Feature(String aDataFormType) { fDataForm = new DataForm(aDataFormType); } /** * Returns the data form for this packet *@return the DataForm for this packet */ public DataForm getDataForm() { return fDataForm; } /** * Gets the XML representation of this part of the packet * *@return the XML representation of this part of the packet */ public String getXML() { StringBuffer buf = new StringBuffer(); buf.append("<feature xmlns=\"http://jabber.org/protocol/feature-neg\">"); if (fDataForm != null) { buf.append(fDataForm.toXML()); } buf.append("</feature>"); return buf.toString(); } /** * Sets the DataForm to be used * *@param fFeatureForm The new DataForm */ public void setDataForm(DataForm fFeatureForm) { this.fDataForm = fFeatureForm; } /** * Determines if this packet supports IBB * *@return <tt>true</tt> if this packet supports IBB */ public boolean providesIBBOption() { return providesOption(IBB_FEATURE); } /** * check if this Feature provides bytestream option this method works * with both "set" and "result" <si> requests, the one in form: * *@return <tt>true</tt> if this feature provides bytestreams */ public boolean providesBytestreamOption() { return providesOption(BYTESTREAMS_FEATURE); } /** * Checks if this packet supports a feature * *@param o The feature to check *@return <tt>true</tt> if the feature is supported */ private boolean providesOption(String o) { // check if the caller asks for bytestream feature Iterator iFields = fDataForm.getFields(); while (iFields.hasNext()) { FormField field = (FormField) iFields.next(); if (field.getVariable().equals("stream-method")) { Iterator iOptions = field.getOptions(); while (iOptions.hasNext()) { FormField.Option option = (FormField.Option) iOptions.next(); if (option.getValue().equals(o)) { return true; } } Iterator iValues = field.getValues(); while (iValues.hasNext()) { String value = (String) iValues.next(); if (value.equals(o)) { return true; } } } } return false; } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -