Projekt

Obecné

Profil

Stáhnout (2.54 KB) Statistiky
| Větev: | Tag: | Revize:
1
package jdeserialize;
2
import java.io.*;
3
import java.util.*;
4

    
5
/**
6
 * <p>
7
 * This object contains embedded information about a serialization that failed, throwing
8
 * an exception.  It includes the actual exception object (which was serialized by the
9
 * ObjectOutputStream) and the raw bytes of the stream data that was read before the
10
 * exception was recognized.
11
 * </p>
12
 *
13
 * <p>
14
 * For the mechanics of exception serialization, see the Object Serialization
15
 * Specification.
16
 * </p>
17
 */
18
public class exceptionstate extends contentbase {
19
    /**
20
     * The serialized exception object.
21
     */
22
    public content exceptionobj;
23
    
24
    /**
25
     * <p>
26
     * An array of bytes representing the data read before the exception was encountered.
27
     * Generally, this starts with the first "tc" byte (cf. protocol spec), which is an
28
     * ObjectStreamConstants value and ends with 0x78 (the tc byte corresponding to
29
     * TC_EXCEPTION).  However, this isn't guaranteed; it may include *more* data.  
30
     * </p>
31
     *
32
     * <p>
33
     * In other words, this is the incomplete object that was being written while the
34
     * exception was caught by the ObjectOutputStream.  It is not likely to be cleanly
35
     * parseable.
36
     * </p>
37
     *
38
     * <p>
39
     * The uncertainty centers around the fact that this data is gathered by jdeserialize
40
     * using a LoggerInputStream, and the underlying DataInputStream may have read more
41
     * than is necessary.  In all tests conducted so far, the above description is
42
     * accurate.
43
     * </p>
44
     */
45
    public byte[] streamdata;
46

    
47
    /**
48
     * Consturctor.
49
     * @param exobj the serialized exception object 
50
     * @param data the array of stream bytes that led up to the exception
51
     */
52
    public exceptionstate(content exobj, byte[] data) {
53
        super(contenttype.EXCEPTIONSTATE);
54
        this.exceptionobj = exobj;
55
        this.streamdata = data;
56
        this.handle = exobj.getHandle();
57
    }
58
    public String toString() {
59
        StringBuffer sb = new StringBuffer();
60
        sb.append("[exceptionstate object " + exceptionobj.toString() + "  buflen " + streamdata.length);
61
        if(streamdata.length > 0) {
62
            for(int i = 0; i < streamdata.length; i++) {
63
                if((i % 16) == 0) {
64
                    sb.append(jdeserialize.linesep).append(String.format("%7x: ", Integer.valueOf(i)));
65
                }
66
                sb.append(" ").append(jdeserialize.hexnoprefix(streamdata[i]));
67
            }
68
            sb.append(jdeserialize.linesep);
69
        }
70
        sb.append("]");
71
        return sb.toString();
72
    }
73
}
(15-15/20)