
// Project: webCDwriter - Network CD Writing
// Author: Jörg Haeger
//	Joerg.Haeger@Uni-Bielefeld.de

import java.io.*;
import netscape.security.PrivilegeManager;

class SecFile extends java.io.File
{
	public SecFile(java.io.File parent, String child)
	{
		super(parent, child);
	}

	public SecFile(String pathname)
	{
		super(pathname);
	}

	public boolean canRead()
	{
		if (CDcreator.isNetscapeVM())
		try {
			PrivilegeManager.enablePrivilege(
				"UniversalFileRead");
		}
		catch (Exception e) {
		}
		return super.canRead();
	}

	public boolean isDirectory()
	{
		if (CDcreator.isNetscapeVM())
		try {
			PrivilegeManager.enablePrivilege(
				"UniversalFileRead");
		}
		catch (Exception e) {
		}
		return super.isDirectory();
	}

	public boolean isWAV()
	{
		if (CDcreator.isNetscapeVM())
		try {
			PrivilegeManager.enablePrivilege(
				"UniversalFileRead");
		}
		catch (Exception e) {
		}

		FileInputStream inStream;
		try
		{
			inStream = new FileInputStream(this);
			byte bs[] = new byte[44];
			int n = inStream.read(bs);
			int freq = ((bs[25] & 0xff) << 8)
				| (bs[24] & 0xff);
			return n == 44
				&& bs[8] == 'W' && bs[9] == 'A'
				&& bs[10] == 'V' && bs[11] == 'E'
				&& bs[20] == 1 && bs[21] == 0 // PCM
				&& bs[22] == 2 && bs[23] == 0 // stereo
				&& freq == 44100
				&& bs[26] == 0 && bs[27] == 0
				&& bs[34] == 16
				;
		}
		catch (java.io.IOException e)
		{
			System.out.println("can't read " + this);
			return false;
		}
	}

	public long length()
	{
		if (CDcreator.isNetscapeVM())
		try {
			PrivilegeManager.enablePrivilege(
				"UniversalFileRead");
		}
		catch (Exception e) {
		}
		return super.length();
	}

	public String[] list()
	{
		if (CDcreator.isNetscapeVM())
		try {
			PrivilegeManager.enablePrivilege(
				"UniversalFileRead");
		}
		catch (Exception e) {
		}
		return super.list();
	}
}
