I have sticky point with a list. After some work I could generate my list and make an xml result. But in my list are entries with tabulators or line breaks (the last entry)
If I execute the script, the result is the following:
[100, 0100045395, Kurzstrasse, 0502028767496, , 8050, 100, Zürich, 05.07.2010,
100, 0100045395, 0400053113, 0000356988, , TPS, ZL1, 1549820, 02.06.2010,
100, 0100045395, 0400053113, 0000356988, , TPS, ZL1, 1549820, 02.06.2010,
]
First of all I will try to remove the last line break with pop() But I allways get this message:
Caught: groovy.lang.MissingMethodException: No signature of method: Ljava.lang.String;.pop() is applicable for argument types: () values: []
Possible solutions: sum(), dump(), min(), max(), any(), sort()
at auslesenzwei.xmlGenerieren(auslesenzwei.groovy:44)
at auslesenzwei.run(auslesenzwei.groovy:37)
What I'am doing wrong?
Code:
import groovy.util.CharsetToolkit;
import java.lang.Object
//Generate pathname
//Pfadname generiert für einfacheres ändern des Speicherortes
def pathname = "C:/mySupport-eclipse/trackandtrace.txt"
//Define Error Status
//Error Status definieren für Weiterverabeitung in mySupport
int errorCode = 0
def errorMessage = ""
def linesAsList = []
def bsknr = "0100045395"
//Define new File
//Neue Datei definieren
def file = new File(pathname)
if(!file.exists())
{
errorCode = 1
errorMessage = "File not found"
out_xml = xmlGenerieren()
}
else
{
//Read Roews and look for BSK Number, split after tab
//Zeilen einlesen und nach der BSK Nummer suchen, nach dem Tabulator trennen
def lines = file.filterLine {
line -> line ==~ /.*\t${bsknr}\t.*/
}
//Split the result after tab and enter, give back as String
//Das Ergebnis aufteilen bei Tabulator und Enter und zugleich als String zurückgeben
linesAsList = lines.toString().split('\t|\r')
xmlGenerieren(linesAsList)
//println linesAsList
}
def xmlGenerieren(givenlist) {
def writer = new StringWriter()
def builder = new groovy.xml.MarkupBuilder(writer)
//givenlist.pop()
println givenlist
def listsize = givenlist.size()
//Test if is empty
//Prüfen ob ein Ergebnis gefunden wurde
if (listsize == 0)
{
builder.result()
{
entry(wert:"0")
{
paketnr("(empty)")
}
}
println writer.toString()
errorCode = 0
}
else {
//i = listsize / 8
//println i
}
}
thanks for the help
String.split()
returns an array of Strings, not a List. Use String.tokenize()
, or cast the result of split to a list like linesAsList = lines.toString().split('\\t|\\r') as List
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.