﻿using System;
using SharpJVM.SharpJVM.Entry;
using SharpJVM.SharpJVM.Entry.Entry;
using System.IO;
using Ionic.Zip;
namespace SharpJVM.SharpJVM.Entry.EntryManager
{
	public class ZipEntryManager:IEntryManager
	{
		public ZipFile Zip{ private set; get; }
		public ZipEntryManager(ZipFile Zip)
		{
			this.Zip = Zip;
		}
		public IEntry GetEntry(string ClassName)
		{
			string Path = ClassName + ".class";
			foreach (ZipEntry entry in Zip) {
				if (entry.FileName == Path) {
					MemoryStream stream = new MemoryStream();
					entry.Extract(stream);
					byte[] ByteArray = stream.GetBuffer();
					stream.Close();
					return new ByteArrayEntry(ByteArray, ClassName);
				}
			}
			return null;
		}
	}
}