@@ -430,20 +430,19 @@ public String readValue() throws XMLStreamException,
430430 */
431431 public String readValue (boolean keepWhiteSpace ) throws XMLStreamException ,
432432 ServiceXmlDeserializationException {
433- String errMsg = String .format ("Could not read value from %s." ,
434- XmlNodeType .getString (this .presentEvent .getEventType ()));
435433 if (this .presentEvent .isStartElement ()) {
436434 // Go to next event and check for Characters event
437435 this .read (keepWhiteSpace );
438436 if (this .presentEvent .isCharacters ()) {
439- StringBuffer elementValue = new StringBuffer ();
437+ final StringBuilder elementValue = new StringBuilder ();
440438 do {
441439 if (this .getNodeType ().nodeType == XmlNodeType .CHARACTERS ) {
442440 Characters characters = (Characters ) this .presentEvent ;
443441 if (keepWhiteSpace || (!characters .isIgnorableWhiteSpace ()
444442 && !characters .isWhiteSpace ())) {
445- if (characters .getData () != null && characters .getData ().length () != 0 ) {
446- elementValue .append (characters .getData ());
443+ final String charactersData = characters .getData ();
444+ if (charactersData != null && !charactersData .isEmpty ()) {
445+ elementValue .append (charactersData );
447446 }
448447 }
449448 }
@@ -456,26 +455,26 @@ public String readValue(boolean keepWhiteSpace) throws XMLStreamException,
456455 // this.read();
457456 return elementValue .toString ();
458457 } else {
459- errMsg = errMsg + "Could not find "
460- + XmlNodeType .getString (XmlNodeType .CHARACTERS );
461- throw new ServiceXmlDeserializationException ( errMsg );
458+ throw new ServiceXmlDeserializationException (
459+ getReadValueErrMsg ( "Could not find " + XmlNodeType .getString (XmlNodeType .CHARACTERS ))
460+ );
462461 }
463462 } else if (this .presentEvent .getEventType () == XmlNodeType .CHARACTERS
464463 && this .presentEvent .isCharacters ()) {
465464 /*
466465 * if(this.presentEvent.asCharacters().getData().equals("<")) {
467466 */
468- final String charData = this .presentEvent
469- .asCharacters ().getData ();
470- StringBuffer data = new StringBuffer (charData == null ? "" : charData );
467+ final String charData = this .presentEvent .asCharacters ().getData ();
468+ final StringBuilder data = new StringBuilder (charData == null ? "" : charData );
471469 do {
472470 this .read (keepWhiteSpace );
473471 if (this .getNodeType ().nodeType == XmlNodeType .CHARACTERS ) {
474472 Characters characters = (Characters ) this .presentEvent ;
475473 if (keepWhiteSpace || (!characters .isIgnorableWhiteSpace ()
476474 && !characters .isWhiteSpace ())) {
477- if (characters .getData () != null && characters .getData ().length () != 0 ) {
478- data .append (characters .getData ());
475+ final String charactersData = characters .getData ();
476+ if (charactersData != null && !charactersData .isEmpty ()) {
477+ data .append (charactersData );
479478 }
480479 }
481480 }
@@ -488,9 +487,9 @@ public String readValue(boolean keepWhiteSpace) throws XMLStreamException,
488487 * return elementValue; }
489488 */
490489 } else {
491- errMsg = errMsg + "Expected is "
492- + XmlNodeType .getString (XmlNodeType .START_ELEMENT );
493- throw new ServiceXmlDeserializationException ( errMsg );
490+ throw new ServiceXmlDeserializationException (
491+ getReadValueErrMsg ( "Expected is " + XmlNodeType .getString (XmlNodeType .START_ELEMENT ))
492+ );
494493 }
495494
496495 }
@@ -1122,4 +1121,15 @@ private static boolean isNullOrEmpty(String namespacePrefix) {
11221121
11231122 }
11241123
1124+ /**
1125+ * Gets the error message which happened during {@link #readValue()}.
1126+ *
1127+ * @param details details message
1128+ * @return error message with details
1129+ */
1130+ private String getReadValueErrMsg (final String details ) {
1131+ final int eventType = this .presentEvent .getEventType ();
1132+ return "Could not read value from " + XmlNodeType .getString (eventType ) + "." + details ;
1133+ }
1134+
11251135}
0 commit comments