/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 * This source file is part of SableVM.                            *
 *                                                                 *
 * See the file "LICENSE" for the copyright information and for    *
 * the terms and conditions for copying, distribution and          *
 * modification of this source file.                               *
 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

/**
 * @author Patrick Latifi
 */
import java.io.*;

class SSourceFileAttributeParser implements SParser
{
	private static SSourceFileAttributeParser instance;

	private SSourceFileAttributeParser()
	{
	}

	public static SSourceFileAttributeParser getInstance()
	{
		if (instance == null)
			instance = new SSourceFileAttributeParser();

		return instance;
	}

	public Object read(DataInputStream d) throws SClassFileException
	{
		int sourceFileIndex = SInputStream.
		    readUnsignedShort(d, SConstants.ITEM_SOURCEFILE_INDEX);

		return new SSourceFileAttribute(
			SAttributeInfoParser.getInstance().
			getAttributeNameIndex(),
			SAttributeInfoParser.getInstance().getAttributeLength(),
			sourceFileIndex);
	}

	public void write(DataOutputStream d, Object obj)
		throws SClassFileException
	{
		SSourceFileAttribute attribute = (SSourceFileAttribute) obj;
		
		SInputStream.writeShort(d, attribute.getSourceFileIndex());
	}
}
