ASF Bugzilla – Attachment 19142 Details for
Bug 41003
InlineMetaService creates unnecessary copies of data
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
Patch
copyvalue.patch (text/plain), 9.77 KB, created by
Natalia Shilenkova
on 2006-11-19 10:27:52 UTC
(
hide
)
Description:
Patch
Filename:
MIME Type:
Creator:
Natalia Shilenkova
Created:
2006-11-19 10:27:52 UTC
Size:
9.77 KB
patch
obsolete
>Index: java/tests/src/org/apache/xindice/core/meta/inline/ResourceTypeReaderTest.java >=================================================================== >--- java/tests/src/org/apache/xindice/core/meta/inline/ResourceTypeReaderTest.java (revision 474103) >+++ java/tests/src/org/apache/xindice/core/meta/inline/ResourceTypeReaderTest.java (working copy) >@@ -18,9 +18,7 @@ > > package org.apache.xindice.core.meta.inline; > >-import org.apache.xindice.core.meta.inline.InlineMetaException; >-import org.apache.xindice.core.meta.inline.InlineMetaMap; >-import org.apache.xindice.core.meta.inline.ResourceTypeReader; >+import org.apache.xindice.core.data.Value; > > import junit.framework.TestCase; > >@@ -43,14 +41,14 @@ > > InlineMetaMap map; > >- map = reader.read(binaryData, 2, 1); >+ map = reader.read(new Value(binaryData, 2, 1)); > assertEquals(ResourceTypeReader.BINARY, map.get("type")); > >- map = reader.read(xmlData, 2, 1); >+ map = reader.read(new Value(xmlData, 2, 1)); > assertEquals(ResourceTypeReader.XML, map.get("type")); > > try { >- reader.read(evilData, 2, 1); >+ reader.read(new Value(evilData, 2, 1)); > fail("failed to throw InlineMetaException on bad type value (3)"); > } catch (InlineMetaException e) { > // expected exception >Index: java/src/org/apache/xindice/core/meta/inline/InlineMetaService.java >=================================================================== >--- java/src/org/apache/xindice/core/meta/inline/InlineMetaService.java (revision 474103) >+++ java/src/org/apache/xindice/core/meta/inline/InlineMetaService.java (working copy) >@@ -22,7 +22,6 @@ > import org.apache.commons.logging.LogFactory; > import org.apache.xindice.core.FaultCodes; > import org.apache.xindice.core.data.Value; >-import org.apache.xindice.core.data.Record; > > /** > * If the documents in a collection have headers, the Collection >@@ -119,22 +118,23 @@ > * the header is corrupted. > */ > public DatabaseEntry readDatabaseEntry(Value rawValue) throws InlineMetaException { >- byte[] rawData = rawValue.getData(); > if (log.isDebugEnabled()) { >- log.debug("readDatabaseEntry: rawData: length=" + rawData.length + " byte 0: " + rawData[0] + " byte 1: " + rawData[1]); >+ log.debug("readDatabaseEntry: rawData: length=" + rawValue.getLength() + >+ " byte 0: " + rawValue.byteAt(0) + " byte 1: " + rawValue.byteAt(1)); > } > > /* > * Read the header. > */ > >- int version = rawData[1]; >+ int headerLen = rawValue.byteAt(0); >+ int version = rawValue.byteAt(1); > if (!haveReaderForVersion(version)) { > throw new InlineMetaException(FaultCodes.GEN_CRITICAL_ERROR, > "No inline metadata reader available for version " + version); > } > final InlineMetaReader reader = readerByVersion[version]; >- InlineMetaMap map = reader.read(rawData, 2, rawData[0] - 2); >+ InlineMetaMap map = reader.read(rawValue.getSubvalue(2, headerLen - 2)); > if (log.isDebugEnabled()) { > log.debug("readDatabaseEntry: map: type=" + map.get("type")); > } >@@ -143,7 +143,7 @@ > * Exract the data into a Value object. > */ > >- Value value = new Value(rawData, rawData[0], rawData.length - rawData[0]); >+ Value value = rawValue.getSubvalue(headerLen, rawValue.getLength() - headerLen); > // FIXME: May be Record should be used instead? new Record(null, value, map); > return new DatabaseEntry(map, value); > } >Index: java/src/org/apache/xindice/core/meta/inline/InlineMetaReader.java >=================================================================== >--- java/src/org/apache/xindice/core/meta/inline/InlineMetaReader.java (revision 474103) >+++ java/src/org/apache/xindice/core/meta/inline/InlineMetaReader.java (working copy) >@@ -18,6 +18,8 @@ > > package org.apache.xindice.core.meta.inline; > >+import org.apache.xindice.core.data.Value; >+ > /** > * The <code>Value</code> associated with a <code>Record</code> > * can be prefixed by a header containing 'inline' metadata. >@@ -40,13 +42,10 @@ > * When a header is read, it generates a <code>Map</code> > * containing the attributes carried by the header. > * >- * @param data array in which the header is embedded >- * @param offset from the beginning of the data array to the >- * beginning of the header. >- * @param length of the header data >+ * @param data Value object in which the header is embedded > * @return Map containing the attributes read from the header > * @throws InlineMetaException if the header data is corrupted or of > * the wrong length > */ >- InlineMetaMap read(byte[] data, int offset, int length) throws InlineMetaException; >+ InlineMetaMap read(Value data) throws InlineMetaException; > } >Index: java/src/org/apache/xindice/core/meta/inline/ResourceTypeReader.java >=================================================================== >--- java/src/org/apache/xindice/core/meta/inline/ResourceTypeReader.java (revision 474103) >+++ java/src/org/apache/xindice/core/meta/inline/ResourceTypeReader.java (working copy) >@@ -21,6 +21,7 @@ > import org.apache.commons.logging.Log; > import org.apache.commons.logging.LogFactory; > import org.apache.xindice.core.FaultCodes; >+import org.apache.xindice.core.data.Value; > > /** > * >@@ -41,26 +42,19 @@ > } > > /** >- * @see org.apache.xindice.core.meta.inline.InlineMetaReader#read(byte[], int, int) >+ * @see org.apache.xindice.core.meta.inline.InlineMetaReader#read(Value) > */ >- public InlineMetaMap read(byte[] data, int offset, int length) throws InlineMetaException { >+ public InlineMetaMap read(Value data) throws InlineMetaException { > if (log.isDebugEnabled()) { >- log.debug("ResourceTypeReader.read: data length=" + data.length + " offset=" + offset + " length=" + length); >+ log.debug("ResourceTypeReader.read: data length=" + data.getLength()); > } > >- if (length != 1) { >+ if (data.getLength() != 1) { > throw new InlineMetaException(FaultCodes.COL_DOCUMENT_MALFORMED, "Expecting header length of 1"); > } > > Integer type; >- try { >- type = new Integer(data[offset]); >- } catch (ArrayIndexOutOfBoundsException e) { >- throw new InlineMetaException( >- FaultCodes.COL_DOCUMENT_MALFORMED, >- "Error reading from data (data length " + data.length + ", offset=" + offset + ", header length " + length + ")", >- e); >- } >+ type = new Integer(data.byteAt(0)); > > if (!XML.equals(type) && !BINARY.equals(type)) { > throw new InlineMetaException(FaultCodes.COL_DOCUMENT_MALFORMED, "Unexpected type value: " + type); >Index: java/src/org/apache/xindice/core/meta/inline/NullReader.java >=================================================================== >--- java/src/org/apache/xindice/core/meta/inline/NullReader.java (revision 474103) >+++ java/src/org/apache/xindice/core/meta/inline/NullReader.java (working copy) >@@ -19,6 +19,7 @@ > package org.apache.xindice.core.meta.inline; > > import org.apache.xindice.core.FaultCodes; >+import org.apache.xindice.core.data.Value; > > /** > * Read metadata of length zero. Handy for comparing performance >@@ -37,11 +38,11 @@ > } > > /** >- * @see org.apache.xindice.core.meta.inline.InlineMetaReader#read(byte[], int, int) >+ * @see org.apache.xindice.core.meta.inline.InlineMetaReader#read(Value) > */ >- public InlineMetaMap read(byte[] data, int offset, int length) throws InlineMetaException { >+ public InlineMetaMap read(Value data) throws InlineMetaException { > >- if (length != 0) { >+ if (data.getLength() != 0) { > throw new InlineMetaException(FaultCodes.COL_DOCUMENT_MALFORMED, "Expecting header length of 0"); > } > >Index: java/src/org/apache/xindice/core/data/Value.java >=================================================================== >--- java/src/org/apache/xindice/core/data/Value.java (revision 474103) >+++ java/src/org/apache/xindice/core/data/Value.java (working copy) >@@ -52,6 +52,9 @@ > } > > public Value(byte[] data, int pos, int len) { >+ if (pos >= data.length || pos < 0 || pos + len > data.length) { >+ throw new ArrayIndexOutOfBoundsException("Value cannot be created"); >+ } > this.data = data; > this.pos = pos; > this.len = len; >@@ -82,6 +85,34 @@ > } > > /** >+ * Returns the byte at the specified index. >+ * >+ * @param index byte index >+ * @return the byte at the specified index. >+ * @throws ArrayIndexOutOfBoundsException if index is negative number or >+ * is not less that the length of Value data >+ */ >+ public final byte byteAt(int index) { >+ if (index < 0 || index >= len) { >+ throw new ArrayIndexOutOfBoundsException(index); >+ } >+ return data[pos + index]; >+ } >+ >+ /** >+ * Get a new Value that is part of this Value object. >+ * >+ * @param start beginning index >+ * @param len length of the new Value >+ * @return Value object >+ * @throws ArrayIndexOutOfBoundsException if start index is either negative >+ * or isn't less then length of original Value >+ */ >+ public final Value getSubvalue(int start, int len) { >+ return new Value(data, start, len); >+ } >+ >+ /** > * getLength retrieves the length of the data being stored by the Value. > * > * @return The Value length >@@ -129,7 +160,7 @@ > } > > public boolean equals(Value value) { >- return len == value.len ? compareTo(value) == 0 : false; >+ return len == value.len && compareTo(value) == 0; > } > > public boolean equals(Object obj) {
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 41003
: 19142