More code for your convenience

I had this log file from my server that's just been sitting there collecting errors for about 2 years. It got pretty big, upwards of 60 MB. So, I wrote this program to break it into chunks. I looked over the FreeBSD documentation to see if there's a program that just reads the last few KB or so. I was getting no output on my new "Browse By Month" code, and when I wrote this program, I was able to split the file into chunks of about 976 KB each (1,000,000 bytes).

package filebreaker;


public class FileBreaker {
public static void main(String []args){
String dir = "/usr/home/jason/Downloads/";
String filename = dir + "catalina.out";
int chunk = 1000000;

try {
BufferedInputStream fs = new BufferedInputStream( new FileInputStream(filename) );
BufferedOutputStream os = null;
int itr = 0;
byte []buf = new byte[chunk];
int status = 0;
while (status != -1){
status =, 0, chunk);
String chunkFilename = dir + "/out/catalina-" + itr + ".txt";
os = new BufferedOutputStream(new FileOutputStream(chunkFilename));
catch (Exception e){

I found out the error. I'm using Java 1.6.0 on my local machine, and have yet to install it on my server. I used a method (Calendar.getDisplayName(int, int, Locale)) that wasn't part of Java 1.5.0, which is running on my server. DOH!

I also now like putting code on my website since I have new css for handling <code /> tags. It looks like this:

code {
display: block;
overflow: auto;
width: 600px;
white-space: pre;

code br {
display: none;

:D My text formatter takes line breaks and replaces them with "<br />", and I wanted code to be preformatted so I don't have to replace tabs with spaces, and also I didn't have to check if I was inside a "code" tag and not insert <br /> for line breaks. It's just a very convenient way to handle it that might look like crap in another browser that's not FireFox. I'll add lots more code now :)

blog comments powered by Disqus