Details
-
Type:
Bug
-
Status:
Closed
-
Priority:
Blocker
-
Resolution: Fixed
-
Affects Version/s: 1.0-beta3a
-
Fix Version/s: 1.0-beta3b
-
Component/s: core
-
Labels:None
-
Environment:JDK 1.4.2_04
WinXP Pro
-
Number of attachments :
Description
An exception is thrown when marshalling an element that contains more than 4k of data. If the element contains less than 4k of data the marshalling compleates normally. Some good sample output with 850 bytes of data is included at the end. I havn't tested unmarshalling larg elements yet.
>>>>>>>>>>>>>> EXCEPTION >>>>>>>>>>>>>>>>>
java.lang.ArrayIndexOutOfBoundsException: 4096
at
org.jibx.runtime.impl.UTF8StreamWriter.writeTextContent(UTF8StreamWriter.java:277)
at
org.jibx.runtime.impl.MarshallingContext.element(MarshallingContext.java:638)
at
ky.mindshare.net.group.services.ftp.FileTransferDescriptor.JiBX_File_Transfer_Protocol_marshal_1_0(FileTransferDescriptor.java)
at
ky.mindshare.net.group.services.ftp.JiBX_File_Transfer_ProtocolFileTransferDescriptor_access.marshal()
at
ky.mindshare.net.group.services.ftp.FileTransferDescriptor.marshal(FileTransferDescriptor.java)
at
org.jibx.runtime.impl.MarshallingContext.marshalRoot(MarshallingContext.java:907)
at
org.jibx.runtime.impl.MarshallingContext.marshalDocument(MarshallingContext.java:955)
>>>>>>>>>>>>>> SOURCE >>>>>>>>>>>>>>>>>
/**
- @author Gareth Farrignton
- Created on Apr 13, 2004
*/
package ky.mindshare.net.group.services.ftp;
import java.io.*;
import org.jibx.runtime.*;
public class FileTransferDescriptor {
public String name; // something to identify the file, could be a name or an entire path
public int length; // In bytes
public int segmentSize; // size of one segment
private String segmentHashes; // SHA1 hashes of every segment strung together
private String infoHash; // 20 byte SHA1 hash of the name, context and segmentHashes fields
// concatanated together, in that order. 'Should' uniquly identify this file. */
// JiBX XML stuff:
private static IBindingFactory bindingFactory;
private static IUnmarshallingContext fromXML;
private IMarshallingContext toXML;
static {
try
catch (JiBXException e)
{ throw new RuntimeException(e); }}
private FileTransferDescriptor() {
}
protected FileTransferDescriptor(FtpFile file) { this.name = new String(file.name); length = file.length; segmentSize = file.segmentSize; setHashes(file.segmentHashes); setInfoHash(file.infoHash); }
public void setHashes(byte[] hashes) { this.segmentHashes = new sun.misc.BASE64Encoder().encodeBuffer(hashes); System.out.println("Segment hases size: " + segmentHashes.length() + " bytes"); }
public byte[] getSegmentHashes() {
try { return new sun.misc.BASE64Decoder().decodeBuffer(segmentHashes); } catch (IOException e) { throw new RuntimeException(e); }
}
public void setInfoHash(byte[] infoHash)
{ this.infoHash = new sun.misc.BASE64Encoder().encodeBuffer(infoHash); } public byte[] getInfoHash() {
try
catch (IOException e)
{ throw new RuntimeException(e); }}
/**
* Create a FileTransferDescriptor from a source of bytes
* @param bytes bytes of XML to convert into an object
*/
public static FileTransferDescriptor loadTransferDescriptor(byte[] bytes) {
ByteArrayInputStream baos = new ByteArrayInputStream(bytes);
try { return (FileTransferDescriptor)fromXML.unmarshalDocument(baos, "UTF-8"); } catch (JiBXException e) { throw new RuntimeException(e); }
}
/**
- convert this object into bytes
- @return bytes of XML
*/
public byte[] saveTransferDescriptor()Unknown macro: { ByteArrayOutputStream baos = new ByteArrayOutputStream(); try { toXML = bindingFactory.createMarshallingContext(); toXML.setIndent(-1); toXML.marshalDocument(this, "UTF-8", null, baos); return baos.toByteArray(); } catch (JiBXException e) { throw new RuntimeException(e); } }}
>>>>>>>>>>>>>> BINDING >>>>>>>>>>>>>>>>>
<binding>
<mapping name="file-info"
class="ky.mindshare.net.group.services.ftp.FileTransferDescriptor">
<value name="name" field="name"/>
<value name="length" field="length"/>
<value name="segment-size" field="segmentSize"/>
<value name="hashes" field="segmentHashes"/>
<value name="info-hash" field="infoHash"/>
</mapping>
</binding>
>>>>>>>>>>>>>> SAMPLE OUTPUT >>>>>>>>>>>>>>>>>
<?xml version="1.0" encoding="UTF-8"?>
<file-info>
<name>thunderbird-win32.zip</name>
<length>7941400</length>
<segment-size>262144</segment-size>
<hashes>UiVZ2x7TJcHLB4qN1+FdLY+wNawb0HKM8WDPtbUiQeqD7ItOpxvFX9f97zs4fU7N9G1VRXbhqjoE
8SKD4oQfVGDvvbmTUiNuMIc3ib7OPlnWUek1wJsVzGAC9YwJC7Yauu5Cg/MQeGjAx7soxBuLF3wB
XCba2khgjh1z26+NMjULmnLFfa/ryQTIsm4iGgR0WIwvi5WDJCDNrhF3U9fw78x0G24kEG0p/dzD
PweaBfvyZrY7AQpEYawQbil2vWuTpSBDKseJRNkT7AoMGVu3uw+ZwNCJUwZHq0ussos21RKnl3wn
KXpsdH8LSsXq1kWhnYccnVtMIp2MF7PGh71BdP9FD/4HyXjhVhi5oNp7zVvMb3r9zB92doKq+vXo
YIXeIqPRUaqrQafnYdbt9bGrbcHn9RE961aUlYGUjO2lTYdvJ/oZR0jXhYwHNLwpUHWRIQJkvrks
2hQ8hQ4AfnQisC5MqnWvT9mIbNN/yXFNeX9klPeQMugCFvEr2nQQ+Mp89/+FPMxBOx44IJoywu3G
aFHEjo5oNKPNwF1pV9ssmjnJ9WmazSARJ+JMsCm1EYCp4iEdCjG6hKMuVemxw4Klne4tO37yFZ7e
NL2AfScNGTULHVR8yQta6VMEQe3D84SLW0UqT2/Ghpc9PysgWhFVLxLWNS2941CExukV5j03z0Nj
HYKXIXYhn1oT/SHNp37WABdWel3fphA6CiKgczChhfn+xgTkvj43OlaPfwOyEUEp5bw9Cr+n0yEX
imUORk9UdUGX5vtv4LUP+ZaZ0mOFFqoDhTEFbs8uVQ+bnHPUnWa9dUMn+ttCzTy7Cfc=
</hashes>
<info-hash>oR6X2xZ5I3uoqobiWzBHq7NmT7Y=
</info-hash></file-info>
Sample output