Created
April 10, 2012 10:56
-
-
Save mauricio/2350438 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class PDFTronXMLFilterWriter( writer : Writer ) extends FilterWriter( writer ) { | |
val buffer = MutableList[Char]() | |
val selectedContent = "<?xml version=\"1.0\" encoding=\"utf-8\" ?>".toCharArray | |
writer.write( selectedContent ) | |
writer.write( "\n<document>\n" ) | |
override def close() { | |
this.out.write( buffer.mkString("") ) | |
this.out.write( "\n</document>" ) | |
this.out.flush() | |
this.out.close() | |
} | |
override def write(c: Int) { | |
this.buffer += c.toChar | |
if ( this.selectedContent.indexOfSlice( this.buffer ) == -1 ) { | |
this.out.write( buffer.mkString("") ) | |
this.buffer.clear() | |
} else { | |
if ( this.buffer.size == this.selectedContent.size ) { | |
this.buffer.clear() | |
} | |
} | |
} | |
override def write(buffer: Array[Char], off: Int, len: Int) { | |
( off until ( off + len) ).foreach( (index) => { this.write( buffer(index) ) } ) | |
} | |
override def write(str: String, off: Int, len: Int) { | |
this.write( str.toCharArray, off, len ) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment