package de.innosystec.unrar.rarfile;

import de.innosystec.unrar.io.Raw;

public class UnixOwnersHeader
extends SubBlockHeader
{
	private int ownerNameSize;
	private int groupNameSize;
	private String owner;
	private String group;

	public  UnixOwnersHeader(SubBlockHeader sb, byte[] uoHeader) {
		super(sb);
		int pos = 0;
		ownerNameSize = Raw.readShortLittleEndian(uoHeader, pos)&0xFFFF;
		pos+=2;
		groupNameSize = Raw.readShortLittleEndian(uoHeader, pos)&0xFFFF;
		pos+=2;
		if(pos+ownerNameSize<uoHeader.length){
			byte[] ownerBuffer = new byte[ownerNameSize];
			System.arraycopy(uoHeader, pos, ownerBuffer, 0, ownerNameSize);
			owner = new String(ownerBuffer);
		}
		pos+=ownerNameSize;
		if(pos+groupNameSize<uoHeader.length){
			byte[] groupBuffer = new byte[groupNameSize];
			System.arraycopy(uoHeader, pos, groupBuffer, 0, groupNameSize);
			group = new String(groupBuffer);
		}
	}
	/**
	 * @return the group
	 */
	public String getGroup() {
		return group;
	}
	/**
	 * @param group the group to set
	 */
	public void setGroup(String group) {
		this.group = group;
	}
	/**
	 * @return the groupNameSize
	 */
	public int getGroupNameSize() {
		return groupNameSize;
	}
	/**
	 * @param groupNameSize the groupNameSize to set
	 */
	public void setGroupNameSize(int groupNameSize) {
		this.groupNameSize = groupNameSize;
	}
	/**
	 * @return the owner
	 */
	public String getOwner() {
		return owner;
	}
	/**
	 * @param owner the owner to set
	 */
	public void setOwner(String owner) {
		this.owner = owner;
	}
	/**
	 * @return the ownerNameSize
	 */
	public int getOwnerNameSize() {
		return ownerNameSize;
	}
	/**
	 * @param ownerNameSize the ownerNameSize to set
	 */
	public void setOwnerNameSize(int ownerNameSize) {
		this.ownerNameSize = ownerNameSize;
	}

	public String toString(){
	    StringBuilder buf = new StringBuilder(super.toString());
		buf.append("\nownerNameSize: "+ownerNameSize);
		buf.append("\nowner: "+owner);
		buf.append("\ngroupNameSize: "+groupNameSize);
		buf.append("\ngroup: "+group);
		return buf.toString();
	}
}