hi,

im quite new to java, and i've been trying to understand this code, but i have no clue about the red parts. does anyone have any idea of what the red parts of this code do?

import java.io.*;

public class BWTEncode
{
	public static void main(String args[])
	{
		int blockSize = 4*1024;
		String file = null;
		InputStream input = System.in; /* Default to the standard input */
		
		/* Process command line arguments */
		for(int i = 0; i < args.length; i++)
		{
			if(args[i].equals("-bs"))
			{
				if((i+1) < args.length)
				{
					blockSize = Integer.parseInt(args[i+1]);
					i++;
				}
				else
				{
					usage();
					System.exit(-1);
				}
					
			}
			else if(args[i].equals("--help"))
			{
				usage();
				System.exit(-1);
			}
			else
			{
				try
				{
					input = new FileInputStream(args[i]);
				}
				catch(IOException e)
				{
					e.printStackTrace();
					System.exit(-1);
				}
				break;				
			}			
		}
		
		/* Create Compressor */
		BWTEncoder bzc = new BWTEncoder(blockSize,System.out);
		bzc.encodeStream(input);
		
	}
	
	public static void usage()
	{
		System.err.println("Usage: java [-bs <blocksize>] <filename>");
		System.err.println("");
		System.err.println("Where <filename> is the file to encode (otherwise encode stdin) and <blocksize> is the block size in bytes.");
	}
}

thanks

The first simply "gets" another reference to STDIN, the next part reads the arguments provided to the command until it finds the option "-bs" and then reads that options parameter (i.e. the next argument). The last block creates an instance the class and calls a method from it.

This article has been dead for over six months. Start a new discussion instead.