|
80 | 80 | } else { |
81 | 81 | lastLF=false; |
82 | 82 | } |
83 | | - if ( char != -1 ) buffer.append( chr( char ) ); |
| 83 | + if ( char != -1 ) buffer.append( char ); |
84 | 84 |
|
85 | 85 | position--; |
86 | 86 |
|
|
96 | 96 |
|
97 | 97 | if( buffer.len() ) { |
98 | 98 | // Strip any CR or LF from the last (first really) line to eliminate leading line breaks in console output |
99 | | - buffer[ buffer.len() ] = listChangeDelims( buffer[ buffer.len() ], '', chr(13) & chr( 10 ) ); |
| 99 | + loop times=2 { |
| 100 | + if( buffer[ buffer.len() ] == 10 || buffer[ buffer.len() ] == 13 ) { |
| 101 | + buffer.deleteAt( buffer.len() ); |
| 102 | + } |
| 103 | + } |
100 | 104 | } |
| 105 | + buffer = createObject("java", "java.lang.String").init(buffer.reverse(), "UTF-8"); |
| 106 | + |
101 | 107 |
|
102 | 108 | // print our file to console |
103 | 109 | print |
104 | | - .text( buffer |
105 | | - .reverse() |
106 | | - .toList( "" ) |
| 110 | + .text( buffer |
107 | 111 | .listToArray( chr( 13 ) & chr( 10 ) ) |
108 | 112 | .map( function( line ) { |
109 | 113 | return ansiFormatter.cleanLine( line ); |
|
137 | 141 | threadName = 'tail#createUUID()#'; |
138 | 142 | thread action="run" name=threadName priority="HIGH" { |
139 | 143 | try{ |
| 144 | + var buffer = []; |
140 | 145 | // Only keep drawing as long as the main thread is active |
141 | 146 | while( variables.tailRun ) { |
142 | | - |
143 | | - var randomAccessFile = createObject( "java", "java.io.RandomAccessFile" ).init( file, "r" ); |
144 | | - randomAccessFile.seek( position ); |
145 | | - var line = randomAccessFile.readLine(); |
146 | | - while( !isnull( line ) ){ |
147 | | - |
| 147 | + if( isNull( randomAccessFile ) ) { |
| 148 | + var randomAccessFile = createObject( "java", "java.io.RandomAccessFile" ).init( file, "r" ); |
| 149 | + randomAccessFile.seek( position ); |
| 150 | + } |
| 151 | + |
| 152 | + // Don't convert to chars yet, just read the bytes |
| 153 | + var byte = randomAccessFile.read(); |
| 154 | + |
| 155 | + if ( byte != -1 ) buffer.append( byte ); |
| 156 | + |
| 157 | + // If we reached the end of a line or the end of the file (and there are bytes in the buffer), print it out |
| 158 | + if( byte == 13 || byte == 10 || ( byte == -1 && buffer.len() ) ) { |
| 159 | + // Convert byte array to UTF-8 encoded string |
| 160 | + var line = createObject("java", "java.lang.String").init(buffer, "UTF-8"); |
| 161 | + buffer.clear(); |
148 | 162 | line = ansiFormatter.cleanLine( line ); |
149 | 163 | print |
150 | | - .line( line ) |
| 164 | + .text( line ) |
151 | 165 | .toConsole(); |
152 | | - |
153 | | - var line = randomAccessFile.readLine(); |
154 | 166 | } |
| 167 | + |
| 168 | + // If we aren't at the end of the file, keep reading |
| 169 | + if( byte != -1) { |
| 170 | + continue; |
| 171 | + } |
| 172 | + |
| 173 | + // At the end of the file, let's close it, wait a few ms and try again |
| 174 | + |
155 | 175 | // Close the file every time so we don't keep it open and locked |
156 | 176 | position = randomAccessFile.getFilePointer(); |
157 | 177 | randomAccessFile.close(); |
| 178 | + structDelete( local, 'randomAccessFile' ); |
158 | 179 |
|
159 | 180 | // Decrease this to speed up the Tail |
160 | 181 | sleep( 300 ); |
|
0 commit comments