-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add possibility to add user defined resources
- Loading branch information
Showing
9 changed files
with
149 additions
and
144 deletions.
There are no files selected for viewing
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
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
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package cloudgene.mapred.util; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
|
||
public class TextUtil { | ||
|
||
private static final Logger log = LoggerFactory.getLogger(TextUtil.class); | ||
|
||
public static String tail(File file, int lines) { | ||
java.io.RandomAccessFile fileHandler = null; | ||
try { | ||
fileHandler = new java.io.RandomAccessFile(file, "r"); | ||
long fileLength = fileHandler.length() - 1; | ||
StringBuilder sb = new StringBuilder(); | ||
int line = 0; | ||
|
||
for (long filePointer = fileLength; filePointer != -1; filePointer--) { | ||
fileHandler.seek(filePointer); | ||
int readByte = fileHandler.readByte(); | ||
|
||
if (readByte == 0xA) { | ||
line = line + 1; | ||
if (line == lines) { | ||
if (filePointer == fileLength) { | ||
continue; | ||
} | ||
break; | ||
} | ||
} else if (readByte == 0xD) { | ||
line = line + 1; | ||
if (line == lines) { | ||
if (filePointer == fileLength - 1) { | ||
continue; | ||
} | ||
break; | ||
} | ||
} | ||
sb.append((char) readByte); | ||
} | ||
|
||
String lastLine = sb.reverse().toString(); | ||
return lastLine; | ||
} catch (java.io.IOException e) { | ||
log.error("Parsing log file failed.", e); | ||
return null; | ||
} finally { | ||
if (fileHandler != null) | ||
try { | ||
fileHandler.close(); | ||
} catch (IOException e) { | ||
log.error("Parsing log file failed.", e); | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.