FileDocCategorySizeDatePackage
FileComparator.javaAPI DocMyID3 for Android2020Tue Oct 07 11:15:24 BST 2008org.cmc.music.util

FileComparator

public class FileComparator extends Object
author
charles To change the template for this generated type comment go to Window>Preferences>Java>Code Generation>Code and Comments

Fields Summary
Constructors Summary
Methods Summary
public booleancompare(java.io.File a, java.io.File b)

		System.out.println("comparing: " + a.getAbsolutePath());
		System.out.println("\t" + "with: " + b.getAbsolutePath());

		// identity.
		if (a.getAbsolutePath().equals(b.getAbsolutePath()))
			return false;

		if (a.length() != b.length())
		{
			System.out.println("\t" + "lengths don't match");
			return false;
		}

		boolean result = compareContents(a, b);
		if (result)
			System.out.println("\t" + "match!");
		else
			System.out.println("\t" + "contents don't match");
		return result;

	
private booleancompareContents(java.io.File a, java.io.File b)

		InputStream ais = null;
		InputStream bis = null;

		try
		{
			ais = new FileInputStream(a);
			ais = new BufferedInputStream(ais);
			bis = new FileInputStream(b);
			bis = new BufferedInputStream(bis);

			while (true)
			{
				int abyte = ais.read();
				int bbyte = bis.read();
				if (abyte != bbyte)
					return false;
				if (abyte == -1)
					return true;
			}
		}
		catch (Exception e)
		{
			System.out.println(e.getMessage());
			e.printStackTrace();
			return false;
		}
		finally
		{
			try
			{
				if (ais != null)
					ais.close();
			}
			catch (Exception e)
			{
				System.out.println(e.getMessage());
				e.printStackTrace();
			}
			try
			{
				if (bis != null)
					bis.close();
			}
			catch (Exception e)
			{
				System.out.println(e.getMessage());
				e.printStackTrace();
			}
		}