home | career | drupal | java | mac | mysql | perl | scala | uml | unix

Groovy example source code file (FileReaderTest.groovy)

This example Groovy source code file (FileReaderTest.groovy) is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Java - Groovy tags/keywords

fileoutputstream, fileoutputstream, filereadertest, filereadertest, groovyclassloader, groovytestcase, us-ascii, us-ascii, utf-8, utf-8

The Groovy FileReaderTest.groovy source code

package org.codehaus.groovy.control.io

class FileReaderTest extends GroovyTestCase {

    void testFileBOM() {
        def file = File.createTempFile("encoding", ".groovy")
        def fos = new FileOutputStream(file)
        // first write the byteorder mark for UTF-8
        fos.write("return 1".getBytes("US-ASCII"))
        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:

new blog posts


Copyright 1998-2014 Alvin Alexander, alvinalexander.com
All Rights Reserved.