|
Groovy example source code file (FileReaderTest.groovy)
The Groovy FileReaderTest.groovy source code
package org.codehaus.groovy.control.io
class FileReaderTest extends GroovyTestCase {
void testFileBOM() {
def file = File.createTempFile("encoding", ".groovy")
file.deleteOnExit()
def fos = new FileOutputStream(file)
// first write the byteorder mark for UTF-8
fos.write(0xEF)
fos.write(0xBB)
fos.write(0xFF)
fos.write("return 1".getBytes("US-ASCII"))
fos.flush()
fos.close()
def gcl = new GroovyClassLoader()
gcl.config.sourceEncoding = "UTF-8"
def clazz = gcl.parseClass(file)
def result = clazz.newInstance().run()
assert result == 1
}
}
Other Groovy examples (source code examples)Here is a short list of links related to this Groovy FileReaderTest.groovy source code file: |
Other websites by Alvin Alexander:
Life/living in Alaska (OneMansAlaska.com)
How I Sold My Business (HowISoldMyBusiness.com)
Copyright 1998-2011 Alvin Alexander, devdaily.com
All Rights Reserved.