Click here to Skip to main content
15,885,941 members
Articles / Programming Languages / Java / Java SE

Free "tail -f" Tool for all Platforms: Tail for Windows, Tail for Linux and Tail for Mac

Rate me:
Please Sign up or sign in to vote.
2.08/5 (8 votes)
19 Jul 2006CPOL3 min read 55.9K   1.1K   24  
MakeLogic Tail is a freeware similar to " tail -f " of Linux. It is Tail for Windows, Tail for Linux and Tail for Mac
/******************************************************************************
 
Copyright (C) 2006  MakeLogic

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA


Date		: 14th April 2006
Authors		: MakeLogic

Design		: Ujjwal
Developer	: Dharma

********************************************************************************/


package com.makeLogic;

import java.awt.event.ActionEvent;

import javax.swing.AbstractAction;
import javax.swing.JDialog;

import java.awt.*;
import java.net.*;
import java.io.*;

import com.makeLogic.utils.HelpDialog;
import com.makeLogic.utils.Trace;

public class HelpDocumentAction extends AbstractAction{

	TailMDI tailMDI;
	final String helpURL = "http://www.makelogic.com/tail/TailHelp.htm";
	final String localHelpFileName = Tail.INSTALL_DIR + "TailHelp.htm";
	final String helpFileInJar = "TailHelpInJar.htm";

	public HelpDocumentAction(TailMDI tailMDI){
		super("Help");

		Trace.enter("HelpDocumentAction.HelpDocumentAction");
		
		this.tailMDI = tailMDI;

		Trace.exit("HelpDocumentAction.HelpDocumentAction");
	}

	public void actionPerformed(ActionEvent ae){

		Trace.enter("HelpDocumentAction.actionPerformed");

		/*
		HelpDialog helpDialog = new HelpDialog(Tail.tailMDI);
		helpDialog.show();
		*/

		//..1. Open the help documentation from the internet
		//..2. If help document is found on the internet, copy the file and overwrite the local file
		//..3. If internet is not accessible, open the local file
		//..4. If the local file is not found, open the jar file resource and make a local copy

		//..Check if internet accessible
		try
		{
			//..Debug
			//..System.out.println("..ML.. Getting help from internet");


			//..Embed uid in the URL
			URL url = new URL(helpURL+"?uid="+CheckForNewUpdates.uid);
			Object obj = url.getContent();
			//..System.out.println("..ML.. Content : "+obj);

			//..Internet accessible
			HyperActive.openURL(helpURL+"?uid="+CheckForNewUpdates.uid);

			//..Save the document
			FileOutputStream fos = new FileOutputStream(localHelpFileName);
			InputStream is = url.openStream();

			byte[] data = new byte[1024];
			int bytesRead = 0;
			while((bytesRead = is.read(data))!=-1)
			{
				fos.write(data,0,bytesRead);
			}

			fos.flush();
			fos.close();

			//..Debug
			//System.out.println("..ML.. New help file written");

			return;
		}
		catch(IOException ioe)
		{
			//..No Trace.exception call here

			//..Debug
			//..System.out.println("..ML.. No internet connection");
			//..Could not connect to internet
			//..Open the local file
			//..Get current classloader 

			//..Try to open the local help file
			File helpFile = new File(localHelpFileName);
			//..Check if file exists
			if(helpFile.exists())
			{

				HyperActive.openURL(localHelpFileName);

				//..Debug
				//..System.out.println("..ML.. Opened the local help file");

				return;
			}
			else
			{
				//..Debug
				//..System.out.println("..ML.. Local help file not found");

				//..Open the help file from the jar file
				ClassLoader cl = this.getClass().getClassLoader();
				Toolkit toolkit = Toolkit.getDefaultToolkit();
				String html = getHTML(cl.getResourceAsStream(helpFileInJar));

				//..Debug
				//..System.out.println("..ML.. HELP\n\n"+html+"\n\n");

				try
				{
					FileWriter fw = new FileWriter(localHelpFileName);
					fw.write(html);
					fw.flush();
					fw.close();
				}
				catch(Exception excp)
				{
					Trace.exception(excp);
					//..Debug
					//..System.out.println("..ML.. Could not create a local help file from the jar file");
				}

				//..Debug
				//..System.out.println("..ML.. Created a local help file from the jar file");

				HyperActive.openURL(localHelpFileName);

				//..Debug
				//..System.out.println("..ML.. Opened the help file created from the jar file");
			}
		}

		Trace.exit("HelpDocumentAction.actionPerformed");
	}


	//..getHTML
	public String getHTML(InputStream htmlStream)
	{
		String returnHtml = "";
		String line = "";

		try
		{
			DataInputStream dis = new DataInputStream(htmlStream);

			while(true)
			{
				line = dis.readLine();

				if(line != null)
				{
					returnHtml += line;
				}
				else
				{
					break;
				}
			}

			return returnHtml;
		}
		catch(Exception ex)
		{
			//..No Trace.exception call here
			return "";
		}
	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Web Developer
India India
Founder of MakeLogic - A Mobile Solutions and XML Web Services Company. B-Tech engineer from India's reputed IITs.

Designed and Authored products like MicroGraphs, MakeLogic VersionManager and MakeLogic Device Broker. Pls see http://www.makelogic.com

MakeLogic is a strategic business partner of Microsoft, Sun, IBM, HP and Citrix.

Contact : madanuuk@makelogic.com OR +91 - 40 - 55322433

Comments and Discussions