View | Details | Raw Unified | Return to bug 41003
Collapse All | Expand All

(-)java/tests/src/org/apache/xindice/core/meta/inline/ResourceTypeReaderTest.java (-6 / +4 lines)
Lines 18-26 Link Here
18
18
19
package org.apache.xindice.core.meta.inline;
19
package org.apache.xindice.core.meta.inline;
20
20
21
import org.apache.xindice.core.meta.inline.InlineMetaException;
21
import org.apache.xindice.core.data.Value;
22
import org.apache.xindice.core.meta.inline.InlineMetaMap;
23
import org.apache.xindice.core.meta.inline.ResourceTypeReader;
24
22
25
import junit.framework.TestCase;
23
import junit.framework.TestCase;
26
24
Lines 43-56 Link Here
43
41
44
        InlineMetaMap map;
42
        InlineMetaMap map;
45
43
46
        map = reader.read(binaryData, 2, 1);
44
        map = reader.read(new Value(binaryData, 2, 1));
47
        assertEquals(ResourceTypeReader.BINARY, map.get("type"));
45
        assertEquals(ResourceTypeReader.BINARY, map.get("type"));
48
46
49
        map = reader.read(xmlData, 2, 1);
47
        map = reader.read(new Value(xmlData, 2, 1));
50
        assertEquals(ResourceTypeReader.XML, map.get("type"));
48
        assertEquals(ResourceTypeReader.XML, map.get("type"));
51
        
49
        
52
        try {
50
        try {
53
            reader.read(evilData, 2, 1);
51
            reader.read(new Value(evilData, 2, 1));
54
            fail("failed to throw InlineMetaException on bad type value (3)");
52
            fail("failed to throw InlineMetaException on bad type value (3)");
55
        } catch (InlineMetaException e) {
53
        } catch (InlineMetaException e) {
56
            // expected exception
54
            // expected exception
(-)java/src/org/apache/xindice/core/meta/inline/InlineMetaService.java (-6 / +6 lines)
Lines 22-28 Link Here
22
import org.apache.commons.logging.LogFactory;
22
import org.apache.commons.logging.LogFactory;
23
import org.apache.xindice.core.FaultCodes;
23
import org.apache.xindice.core.FaultCodes;
24
import org.apache.xindice.core.data.Value;
24
import org.apache.xindice.core.data.Value;
25
import org.apache.xindice.core.data.Record;
26
25
27
/**
26
/**
28
 * If the documents in a collection have headers, the Collection
27
 * If the documents in a collection have headers, the Collection
Lines 119-140 Link Here
119
     *         the header is corrupted.
118
     *         the header is corrupted.
120
     */
119
     */
121
    public DatabaseEntry readDatabaseEntry(Value rawValue) throws InlineMetaException {
120
    public DatabaseEntry readDatabaseEntry(Value rawValue) throws InlineMetaException {
122
        byte[] rawData = rawValue.getData();
123
        if (log.isDebugEnabled()) {
121
        if (log.isDebugEnabled()) {
124
            log.debug("readDatabaseEntry: rawData: length=" + rawData.length + " byte 0: " + rawData[0] + " byte 1: " + rawData[1]);
122
            log.debug("readDatabaseEntry: rawData: length=" + rawValue.getLength() +
123
                      " byte 0: " + rawValue.byteAt(0) + " byte 1: " + rawValue.byteAt(1));
125
        }
124
        }
126
125
127
        /*
126
        /*
128
         * Read the header.
127
         * Read the header.
129
         */
128
         */
130
129
131
        int version = rawData[1];
130
        int headerLen = rawValue.byteAt(0);
131
        int version = rawValue.byteAt(1);
132
        if (!haveReaderForVersion(version)) {
132
        if (!haveReaderForVersion(version)) {
133
            throw new InlineMetaException(FaultCodes.GEN_CRITICAL_ERROR,
133
            throw new InlineMetaException(FaultCodes.GEN_CRITICAL_ERROR,
134
                                          "No inline metadata reader available for version " + version);
134
                                          "No inline metadata reader available for version " + version);
135
        }
135
        }
136
        final InlineMetaReader reader = readerByVersion[version];
136
        final InlineMetaReader reader = readerByVersion[version];
137
        InlineMetaMap map = reader.read(rawData, 2, rawData[0] - 2);
137
        InlineMetaMap map = reader.read(rawValue.getSubvalue(2, headerLen - 2));
138
        if (log.isDebugEnabled()) {
138
        if (log.isDebugEnabled()) {
139
            log.debug("readDatabaseEntry: map: type=" + map.get("type"));
139
            log.debug("readDatabaseEntry: map: type=" + map.get("type"));
140
        }
140
        }
Lines 143-149 Link Here
143
         * Exract the data into a Value object.
143
         * Exract the data into a Value object.
144
         */
144
         */
145
145
146
        Value value = new Value(rawData, rawData[0], rawData.length - rawData[0]);
146
        Value value = rawValue.getSubvalue(headerLen, rawValue.getLength() - headerLen);
147
        // FIXME: May be Record should be used instead? new Record(null, value, map);
147
        // FIXME: May be Record should be used instead? new Record(null, value, map);
148
        return new DatabaseEntry(map, value);
148
        return new DatabaseEntry(map, value);
149
    }
149
    }
(-)java/src/org/apache/xindice/core/meta/inline/InlineMetaReader.java (-5 / +4 lines)
Lines 18-23 Link Here
18
18
19
package org.apache.xindice.core.meta.inline;
19
package org.apache.xindice.core.meta.inline;
20
20
21
import org.apache.xindice.core.data.Value;
22
21
/**
23
/**
22
 * The <code>Value</code> associated with a <code>Record</code>
24
 * The <code>Value</code> associated with a <code>Record</code>
23
 * can be prefixed by a header containing 'inline' metadata.
25
 * can be prefixed by a header containing 'inline' metadata.
Lines 40-52 Link Here
40
     * When a header is read, it generates a <code>Map</code>
42
     * When a header is read, it generates a <code>Map</code>
41
     * containing the attributes carried by the header.
43
     * containing the attributes carried by the header.
42
     *
44
     *
43
     * @param data array in which the header is embedded
45
     * @param data Value object in which the header is embedded
44
     * @param offset from the beginning of the data array to the
45
     *        beginning of the header.
46
     * @param length of the header data
47
     * @return Map containing the attributes read from the header
46
     * @return Map containing the attributes read from the header
48
     * @throws InlineMetaException if the header data is corrupted or of
47
     * @throws InlineMetaException if the header data is corrupted or of
49
     *         the wrong length
48
     *         the wrong length
50
     */
49
     */
51
    InlineMetaMap read(byte[] data, int offset, int length) throws InlineMetaException;
50
    InlineMetaMap read(Value data) throws InlineMetaException;
52
}
51
}
(-)java/src/org/apache/xindice/core/meta/inline/ResourceTypeReader.java (-12 / +6 lines)
Lines 21-26 Link Here
21
import org.apache.commons.logging.Log;
21
import org.apache.commons.logging.Log;
22
import org.apache.commons.logging.LogFactory;
22
import org.apache.commons.logging.LogFactory;
23
import org.apache.xindice.core.FaultCodes;
23
import org.apache.xindice.core.FaultCodes;
24
import org.apache.xindice.core.data.Value;
24
25
25
/**
26
/**
26
 *
27
 *
Lines 41-66 Link Here
41
    }
42
    }
42
43
43
    /**
44
    /**
44
     * @see org.apache.xindice.core.meta.inline.InlineMetaReader#read(byte[], int, int)
45
     * @see org.apache.xindice.core.meta.inline.InlineMetaReader#read(Value)
45
     */
46
     */
46
    public InlineMetaMap read(byte[] data, int offset, int length) throws InlineMetaException {
47
    public InlineMetaMap read(Value data) throws InlineMetaException {
47
        if (log.isDebugEnabled()) {
48
        if (log.isDebugEnabled()) {
48
            log.debug("ResourceTypeReader.read: data length=" + data.length + " offset=" + offset + " length=" + length);
49
            log.debug("ResourceTypeReader.read: data length=" + data.getLength());
49
        }
50
        }
50
51
51
        if (length != 1) {
52
        if (data.getLength() != 1) {
52
            throw new InlineMetaException(FaultCodes.COL_DOCUMENT_MALFORMED, "Expecting header length of 1");
53
            throw new InlineMetaException(FaultCodes.COL_DOCUMENT_MALFORMED, "Expecting header length of 1");
53
        }
54
        }
54
55
55
        Integer type;
56
        Integer type;
56
        try {
57
        type = new Integer(data.byteAt(0));
57
            type = new Integer(data[offset]);
58
        } catch (ArrayIndexOutOfBoundsException e) {
59
            throw new InlineMetaException(
60
                    FaultCodes.COL_DOCUMENT_MALFORMED,
61
                    "Error reading from data (data length " + data.length + ", offset=" + offset + ", header length " + length + ")",
62
                    e);
63
        }
64
58
65
        if (!XML.equals(type) && !BINARY.equals(type)) {
59
        if (!XML.equals(type) && !BINARY.equals(type)) {
66
            throw new InlineMetaException(FaultCodes.COL_DOCUMENT_MALFORMED, "Unexpected type value: " + type);
60
            throw new InlineMetaException(FaultCodes.COL_DOCUMENT_MALFORMED, "Unexpected type value: " + type);
(-)java/src/org/apache/xindice/core/meta/inline/NullReader.java (-3 / +4 lines)
Lines 19-24 Link Here
19
package org.apache.xindice.core.meta.inline;
19
package org.apache.xindice.core.meta.inline;
20
20
21
import org.apache.xindice.core.FaultCodes;
21
import org.apache.xindice.core.FaultCodes;
22
import org.apache.xindice.core.data.Value;
22
23
23
/**
24
/**
24
 * Read metadata of length zero.  Handy for comparing performance
25
 * Read metadata of length zero.  Handy for comparing performance
Lines 37-47 Link Here
37
    }
38
    }
38
39
39
    /**
40
    /**
40
     * @see org.apache.xindice.core.meta.inline.InlineMetaReader#read(byte[], int, int)
41
     * @see org.apache.xindice.core.meta.inline.InlineMetaReader#read(Value)
41
     */
42
     */
42
    public InlineMetaMap read(byte[] data, int offset, int length) throws InlineMetaException {
43
    public InlineMetaMap read(Value data) throws InlineMetaException {
43
44
44
        if (length != 0) {
45
        if (data.getLength() != 0) {
45
            throw new InlineMetaException(FaultCodes.COL_DOCUMENT_MALFORMED, "Expecting header length of 0");
46
            throw new InlineMetaException(FaultCodes.COL_DOCUMENT_MALFORMED, "Expecting header length of 0");
46
        }
47
        }
47
48
(-)java/src/org/apache/xindice/core/data/Value.java (-1 / +32 lines)
Lines 52-57 Link Here
52
    }
52
    }
53
53
54
    public Value(byte[] data, int pos, int len) {
54
    public Value(byte[] data, int pos, int len) {
55
        if (pos >= data.length || pos < 0 || pos + len > data.length) {
56
            throw new ArrayIndexOutOfBoundsException("Value cannot be created");
57
        }
55
        this.data = data;
58
        this.data = data;
56
        this.pos = pos;
59
        this.pos = pos;
57
        this.len = len;
60
        this.len = len;
Lines 82-87 Link Here
82
    }
85
    }
83
86
84
    /**
87
    /**
88
     * Returns the byte at the specified index.
89
     *
90
     * @param index byte index
91
     * @return the byte at the specified index.
92
     * @throws ArrayIndexOutOfBoundsException if index is negative number or
93
     *         is not less that the length of Value data
94
     */
95
    public final byte byteAt(int index) {
96
        if (index < 0 || index >= len) {
97
            throw new ArrayIndexOutOfBoundsException(index);
98
        }
99
        return data[pos + index];
100
    }
101
102
    /**
103
     * Get a new Value that is part of this Value object.
104
     *
105
     * @param start beginning index
106
     * @param len length of the new Value
107
     * @return Value object
108
     * @throws ArrayIndexOutOfBoundsException if start index is either negative
109
     *         or isn't less then length of original Value
110
     */
111
    public final Value getSubvalue(int start, int len) {
112
        return new Value(data, start, len);
113
    }
114
115
    /**
85
     * getLength retrieves the length of the data being stored by the Value.
116
     * getLength retrieves the length of the data being stored by the Value.
86
     *
117
     *
87
     * @return The Value length
118
     * @return The Value length
Lines 129-135 Link Here
129
    }
160
    }
130
161
131
    public boolean equals(Value value) {
162
    public boolean equals(Value value) {
132
        return len == value.len ? compareTo(value) == 0 : false;
163
        return len == value.len && compareTo(value) == 0;
133
    }
164
    }
134
165
135
    public boolean equals(Object obj) {
166
    public boolean equals(Object obj) {

Return to bug 41003