Skip to content

Commit 9500567

Browse files
committed
Undid XMLExporter saving buffer positions.
Not saving positions is intentional #2312 (comment)
1 parent fdaa7b7 commit 9500567

4 files changed

Lines changed: 18 additions & 68 deletions

File tree

jme3-plugins/src/test/java/com/jme3/export/InputOutputCapsuleTest.java

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -619,9 +619,6 @@ public void write(JmeExporter je) throws IOException {
619619
capsule.write(testIntBuffer, "testIntBuffer", null);
620620
capsule.write(testFloatBuffer, "testFloatBuffer", null);
621621

622-
capsule.write((ByteBuffer) BufferUtils.createByteBuffer(4).position(2), "testBufferPosition", null);
623-
capsule.write((ByteBuffer) BufferUtils.createByteBuffer(4).limit(2), "testBufferLimit", null);
624-
625622
capsule.write(BufferUtils.createByteBuffer(0), "emptyByteBuffer", null);
626623
capsule.write(BufferUtils.createShortBuffer(0), "emptyShortBuffer", null);
627624
capsule.write(BufferUtils.createIntBuffer(0), "emptyIntBuffer", null);
@@ -637,10 +634,6 @@ public void read(JmeImporter ji) throws IOException {
637634
Assert.assertEquals("readIntBuffer()", testIntBuffer, capsule.readIntBuffer("testIntBuffer", null));
638635
Assert.assertEquals("readFloatBuffer()", testFloatBuffer, capsule.readFloatBuffer("testFloatBuffer", null));
639636

640-
// BinaryExporter actually fails this one, so commenting it out for now
641-
//Assert.assertEquals("buffer position", 2, capsule.readByteBuffer("testBufferPosition", null).position());
642-
Assert.assertEquals("buffer limit", 2, capsule.readByteBuffer("testBufferLimit", null).limit());
643-
644637
Assert.assertEquals("readByteBuffer()", BufferUtils.createByteBuffer(0), capsule.readByteBuffer("emptyByteBuffer", null));
645638
Assert.assertEquals("readShortBuffer()", BufferUtils.createShortBuffer(0), capsule.readShortBuffer("emptyShortBuffer", null));
646639
Assert.assertEquals("readIntBuffer()", BufferUtils.createIntBuffer(0), capsule.readIntBuffer("emptyIntBuffer", null));

jme3-plugins/src/xml/java/com/jme3/export/xml/DOMInputCapsule.java

Lines changed: 4 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -704,17 +704,7 @@ public ByteBuffer readByteBuffer(String name, ByteBuffer defVal) throws IOExcept
704704
return defVal;
705705
}
706706

707-
int position = 0;
708-
String positionString = XMLUtils.getAttribute(importer.getFormatVersion(), element, XMLExporter.ATTRIBUTE_POSITION);
709-
if (!positionString.isEmpty()) {
710-
try {
711-
position = Integer.parseInt(positionString);
712-
} catch (NumberFormatException nfe) {
713-
throw new IOException(nfe);
714-
}
715-
}
716-
717-
return (ByteBuffer) BufferUtils.createByteBuffer(array.length).put(array).position(position);
707+
return (ByteBuffer) BufferUtils.createByteBuffer(array.length).put(array).rewind();
718708
}
719709

720710
@Override
@@ -727,17 +717,7 @@ public ShortBuffer readShortBuffer(String name, ShortBuffer defVal) throws IOExc
727717
return defVal;
728718
}
729719

730-
int position = 0;
731-
String positionString = XMLUtils.getAttribute(importer.getFormatVersion(), element, XMLExporter.ATTRIBUTE_POSITION);
732-
if (!positionString.isEmpty()) {
733-
try {
734-
position = Integer.parseInt(positionString);
735-
} catch (NumberFormatException nfe) {
736-
throw new IOException(nfe);
737-
}
738-
}
739-
740-
return (ShortBuffer) BufferUtils.createShortBuffer(array.length).put(array).position(position);
720+
return (ShortBuffer) BufferUtils.createShortBuffer(array.length).put(array).rewind();
741721
}
742722

743723
@Override
@@ -750,17 +730,7 @@ public IntBuffer readIntBuffer(String name, IntBuffer defVal) throws IOException
750730
return defVal;
751731
}
752732

753-
int position = 0;
754-
String positionString = XMLUtils.getAttribute(importer.getFormatVersion(), element, XMLExporter.ATTRIBUTE_POSITION);
755-
if (!positionString.isEmpty()) {
756-
try {
757-
position = Integer.parseInt(positionString);
758-
} catch (NumberFormatException nfe) {
759-
throw new IOException(nfe);
760-
}
761-
}
762-
763-
return (IntBuffer) BufferUtils.createIntBuffer(array.length).put(array).position(position);
733+
return (IntBuffer) BufferUtils.createIntBuffer(array.length).put(array).rewind();
764734
}
765735

766736
@Override
@@ -773,17 +743,7 @@ public FloatBuffer readFloatBuffer(String name, FloatBuffer defVal) throws IOExc
773743
return defVal;
774744
}
775745

776-
int position = 0;
777-
String positionString = XMLUtils.getAttribute(importer.getFormatVersion(), element, XMLExporter.ATTRIBUTE_POSITION);
778-
if (!positionString.isEmpty()) {
779-
try {
780-
position = Integer.parseInt(positionString);
781-
} catch (NumberFormatException nfe) {
782-
throw new IOException(nfe);
783-
}
784-
}
785-
786-
return (FloatBuffer) BufferUtils.createFloatBuffer(array.length).put(array).position(position);
746+
return (FloatBuffer) BufferUtils.createFloatBuffer(array.length).put(array).rewind();
787747
}
788748

789749
@Override

jme3-plugins/src/xml/java/com/jme3/export/xml/DOMOutputCapsule.java

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ private Element appendElement(String name) {
9090

9191
// helper function to reduce duplicate code. uses reflection to write an array of any primitive type.
9292
// also has optional position argument for writing buffers.
93-
private void writePrimitiveArrayHelper(Object value, String name, int position) throws IOException {
93+
private void writePrimitiveArrayHelper(Object value, String name) throws IOException {
9494
StringBuilder sb = new StringBuilder();
9595

9696
for(int i = 0; i < Array.getLength(value); i++) {
@@ -104,9 +104,7 @@ private void writePrimitiveArrayHelper(Object value, String name, int position)
104104
appendElement(name);
105105
XMLUtils.setAttribute(currentElement, XMLExporter.ATTRIBUTE_SIZE, String.valueOf(Array.getLength(value)));
106106
XMLUtils.setAttribute(currentElement, XMLExporter.ATTRIBUTE_DATA, sb.toString());
107-
if (position >= 0) {
108-
XMLUtils.setAttribute(currentElement, XMLExporter.ATTRIBUTE_POSITION, String.valueOf(position));
109-
}
107+
110108
currentElement = (Element) currentElement.getParentNode();
111109
}
112110

@@ -124,7 +122,7 @@ private void writePrimitiveArray2DHelper(Object[] value, String name) throws IOE
124122
String childName = childNamePrefix + i;
125123

126124
if (value[i] != null) {
127-
writePrimitiveArrayHelper(value[i], childName, -1);
125+
writePrimitiveArrayHelper(value[i], childName);
128126
} else {
129127
// empty tag
130128
appendElement(childName);
@@ -145,7 +143,7 @@ public void write(byte value, String name, byte defVal) throws IOException {
145143
@Override
146144
public void write(byte[] value, String name, byte[] defVal) throws IOException {
147145
if (!Arrays.equals(value, defVal)) {
148-
writePrimitiveArrayHelper(value, name, -1);
146+
writePrimitiveArrayHelper(value, name);
149147
}
150148
}
151149

@@ -166,7 +164,7 @@ public void write(short value, String name, short defVal) throws IOException {
166164
@Override
167165
public void write(short[] value, String name, short[] defVal) throws IOException {
168166
if (!Arrays.equals(value, defVal)) {
169-
writePrimitiveArrayHelper(value, name, -1);
167+
writePrimitiveArrayHelper(value, name);
170168
}
171169
}
172170

@@ -187,7 +185,7 @@ public void write(int value, String name, int defVal) throws IOException {
187185
@Override
188186
public void write(int[] value, String name, int[] defVal) throws IOException {
189187
if (!Arrays.equals(value, defVal)) {
190-
writePrimitiveArrayHelper(value, name, -1);
188+
writePrimitiveArrayHelper(value, name);
191189
}
192190
}
193191

@@ -208,7 +206,7 @@ public void write(long value, String name, long defVal) throws IOException {
208206
@Override
209207
public void write(long[] value, String name, long[] defVal) throws IOException {
210208
if (!Arrays.equals(value, defVal)) {
211-
writePrimitiveArrayHelper(value, name, -1);
209+
writePrimitiveArrayHelper(value, name);
212210
}
213211
}
214212

@@ -229,7 +227,7 @@ public void write(float value, String name, float defVal) throws IOException {
229227
@Override
230228
public void write(float[] value, String name, float[] defVal) throws IOException {
231229
if (!Arrays.equals(value, defVal)) {
232-
writePrimitiveArrayHelper(value, name, -1);
230+
writePrimitiveArrayHelper(value, name);
233231
}
234232
}
235233

@@ -250,7 +248,7 @@ public void write(double value, String name, double defVal) throws IOException {
250248
@Override
251249
public void write(double[] value, String name, double[] defVal) throws IOException {
252250
if (!Arrays.equals(value, defVal)) {
253-
writePrimitiveArrayHelper(value, name, -1);
251+
writePrimitiveArrayHelper(value, name);
254252
}
255253
}
256254

@@ -271,7 +269,7 @@ public void write(boolean value, String name, boolean defVal) throws IOException
271269
@Override
272270
public void write(boolean[] value, String name, boolean[] defVal) throws IOException {
273271
if (!Arrays.equals(value, defVal)) {
274-
writePrimitiveArrayHelper(value, name, -1);
272+
writePrimitiveArrayHelper(value, name);
275273
}
276274
}
277275

@@ -478,7 +476,7 @@ public void write(ByteBuffer value, String name, ByteBuffer defVal) throws IOExc
478476
value.get(array);
479477
value.position(position);
480478

481-
writePrimitiveArrayHelper(array, name, value.position());
479+
writePrimitiveArrayHelper(array, name);
482480
}
483481

484482
@Override
@@ -493,7 +491,7 @@ public void write(ShortBuffer value, String name, ShortBuffer defVal) throws IOE
493491
value.get(array);
494492
value.position(position);
495493

496-
writePrimitiveArrayHelper(array, name, value.position());
494+
writePrimitiveArrayHelper(array, name);
497495
}
498496

499497
@Override
@@ -508,7 +506,7 @@ public void write(IntBuffer value, String name, IntBuffer defVal) throws IOExcep
508506
value.get(array);
509507
value.position(position);
510508

511-
writePrimitiveArrayHelper(array, name, value.position());
509+
writePrimitiveArrayHelper(array, name);
512510
}
513511

514512
@Override
@@ -523,7 +521,7 @@ public void write(FloatBuffer value, String name, FloatBuffer defVal) throws IOE
523521
value.get(array);
524522
value.position(position);
525523

526-
writePrimitiveArrayHelper(array, name, value.position());
524+
writePrimitiveArrayHelper(array, name);
527525
}
528526

529527
@Override

jme3-plugins/src/xml/java/com/jme3/export/xml/XMLExporter.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ public class XMLExporter implements JmeExporter {
6262
public static final String ELEMENT_VALUE = "Value";
6363
public static final String ATTRIBUTE_SIZE = "size";
6464
public static final String ATTRIBUTE_DATA = "data";
65-
public static final String ATTRIBUTE_POSITION = "position"; // for buffers only
6665
public static final String ATTRIBUTE_CLASS = "class";
6766
public static final String ATTRIBUTE_REFERENCE_ID = "reference_ID";
6867
public static final String ATTRIBUTE_REFERENCE = "ref";

0 commit comments

Comments
 (0)