I have a String which contains some formatted content with LineFeed
after each line. I want to format the content of that variable to restrict each line to have not more than 80 characters.
Can somebody help me with this in Groovy?
for testing purpose I copied the content in a file
String fileContents = new File('E://Projects//temp//license').text
println fileContents
fileContents content or Console Output
List of connectivities are:
Valid [Metadata Exchange for Microsoft Visio]
Valid [Metadata Exchange for Microstrategy]
Valid [Metadata Exchange for Microsoft SQL Server Reporting Services and Analysis Services]
Valid [Metadata Exchange for Netezza]
Valid [Metadata Exchange for Oracle]
Valid [Metadata Exchange for Oracle BI Enterprise Edition]
Valid [Metadata Exchange for Oracle Designer]
Command ran successfully
Update
This is what I am using after tim_yates answer
def es=lic.entrySet()
xml.licInfo() {
int i=0
es.each{
if(!it.key.contains("failed with error"))
{
String val=new String(it.value)
license(name:it.key,value:trimOutput(val),assignedTo:resultRows[i++])
}
}
}
def trimOutput(text)
{
text=text.tokenize( '\n' )*.toList()*.collate(90)*.collect { it.join() }.flatten().join( '\n' )
text
}
but is gives me the following exception
Exception in thread "main" groovy.lang.MissingMethodException: No signature of method: java.util.ArrayList.collate() is applicable for argument types: (java.lang.Integer) values: [90]
Possible solutions: clone(), collect(groovy.lang.Closure), collect(groovy.lang.Closure), clear(), clear(), clear()
More update (console output of println es)
[license_all =Edition: BAAC Standard
Software Version: 6.5
Distributed by: ABC
Issued on: 2012-Feb-06
Validity period: Non-Expiry
Serial number: 210502
Deployment level: Production
List of supported platforms are:
[All operating systems] is authorized for [100] logical CPUs
Number of authorized repository instances: 100
Number of authorized CAL usage count: 100
List of connectivities are:
Valid [Metadata Exchange for Microsoft SQL Server Reporting Services and Analysis Services]
Valid [Metadata Exchange for Netezza]
Valid [Metadata Exchange for Oracle]
Valid [Metadata Exchange for Oracle BI Enterprise Edition]
Valid [Metadata Exchange for Oracle Designer]
Valid [Metadata Exchange for Oracle Warehouse Builder]
Valid [Metadata Exchange for Popkin System Architect]
Valid [Metadata Exchange for SAP R/3]
Valid [Metadata Exchange for Select SE]
Valid [Metadata Exchange for Silverrun - RDM]
Valid [Metadata Exchange for SQL Server]
Valid [Metadata Exchange for Sybase ASE]
Valid [Metadata Exchange for Sybase PowerDesigner]
Valid [Metadata Exchange for Teradata]
Command ran successfully.
]