1baa3858d3f5d128a5c8466b700098109edcad5f2repo syncpackage SevenZip;
2baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
3baa3858d3f5d128a5c8466b700098109edcad5f2repo syncpublic class LzmaAlone
4baa3858d3f5d128a5c8466b700098109edcad5f2repo sync{
5baa3858d3f5d128a5c8466b700098109edcad5f2repo sync	static public class CommandLine
6baa3858d3f5d128a5c8466b700098109edcad5f2repo sync	{
7baa3858d3f5d128a5c8466b700098109edcad5f2repo sync		public static final int kEncode = 0;
8baa3858d3f5d128a5c8466b700098109edcad5f2repo sync		public static final int kDecode = 1;
9baa3858d3f5d128a5c8466b700098109edcad5f2repo sync		public static final int kBenchmak = 2;
10baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
11baa3858d3f5d128a5c8466b700098109edcad5f2repo sync		public int Command = -1;
12baa3858d3f5d128a5c8466b700098109edcad5f2repo sync		public int NumBenchmarkPasses = 10;
13baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
14baa3858d3f5d128a5c8466b700098109edcad5f2repo sync		public int DictionarySize = 1 << 23;
15baa3858d3f5d128a5c8466b700098109edcad5f2repo sync		public boolean DictionarySizeIsDefined = false;
16baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
17baa3858d3f5d128a5c8466b700098109edcad5f2repo sync		public int Lc = 3;
18baa3858d3f5d128a5c8466b700098109edcad5f2repo sync		public int Lp = 0;
19baa3858d3f5d128a5c8466b700098109edcad5f2repo sync		public int Pb = 2;
20baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
21baa3858d3f5d128a5c8466b700098109edcad5f2repo sync		public int Fb = 128;
22baa3858d3f5d128a5c8466b700098109edcad5f2repo sync		public boolean FbIsDefined = false;
23baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
24baa3858d3f5d128a5c8466b700098109edcad5f2repo sync		public boolean Eos = false;
25baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
26baa3858d3f5d128a5c8466b700098109edcad5f2repo sync		public int Algorithm = 2;
27baa3858d3f5d128a5c8466b700098109edcad5f2repo sync		public int MatchFinder = 1;
28baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
29baa3858d3f5d128a5c8466b700098109edcad5f2repo sync		public String InFile;
30baa3858d3f5d128a5c8466b700098109edcad5f2repo sync		public String OutFile;
31baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
32baa3858d3f5d128a5c8466b700098109edcad5f2repo sync		boolean ParseSwitch(String s)
33baa3858d3f5d128a5c8466b700098109edcad5f2repo sync		{
34baa3858d3f5d128a5c8466b700098109edcad5f2repo sync			if (s.startsWith("d"))
35baa3858d3f5d128a5c8466b700098109edcad5f2repo sync			{
36baa3858d3f5d128a5c8466b700098109edcad5f2repo sync				DictionarySize = 1 << Integer.parseInt(s.substring(1));
37baa3858d3f5d128a5c8466b700098109edcad5f2repo sync				DictionarySizeIsDefined = true;
38baa3858d3f5d128a5c8466b700098109edcad5f2repo sync			}
39baa3858d3f5d128a5c8466b700098109edcad5f2repo sync			else if (s.startsWith("fb"))
40baa3858d3f5d128a5c8466b700098109edcad5f2repo sync			{
41baa3858d3f5d128a5c8466b700098109edcad5f2repo sync				Fb = Integer.parseInt(s.substring(2));
42baa3858d3f5d128a5c8466b700098109edcad5f2repo sync				FbIsDefined = true;
43baa3858d3f5d128a5c8466b700098109edcad5f2repo sync			}
44baa3858d3f5d128a5c8466b700098109edcad5f2repo sync			else if (s.startsWith("a"))
45baa3858d3f5d128a5c8466b700098109edcad5f2repo sync				Algorithm = Integer.parseInt(s.substring(1));
46baa3858d3f5d128a5c8466b700098109edcad5f2repo sync			else if (s.startsWith("lc"))
47baa3858d3f5d128a5c8466b700098109edcad5f2repo sync				Lc = Integer.parseInt(s.substring(2));
48baa3858d3f5d128a5c8466b700098109edcad5f2repo sync			else if (s.startsWith("lp"))
49baa3858d3f5d128a5c8466b700098109edcad5f2repo sync				Lp = Integer.parseInt(s.substring(2));
50baa3858d3f5d128a5c8466b700098109edcad5f2repo sync			else if (s.startsWith("pb"))
51baa3858d3f5d128a5c8466b700098109edcad5f2repo sync				Pb = Integer.parseInt(s.substring(2));
52baa3858d3f5d128a5c8466b700098109edcad5f2repo sync			else if (s.startsWith("eos"))
53baa3858d3f5d128a5c8466b700098109edcad5f2repo sync				Eos = true;
54baa3858d3f5d128a5c8466b700098109edcad5f2repo sync			else if (s.startsWith("mf"))
55baa3858d3f5d128a5c8466b700098109edcad5f2repo sync			{
56baa3858d3f5d128a5c8466b700098109edcad5f2repo sync				String mfs = s.substring(2);
57baa3858d3f5d128a5c8466b700098109edcad5f2repo sync				if (mfs.equals("bt2"))
58baa3858d3f5d128a5c8466b700098109edcad5f2repo sync					MatchFinder = 0;
59baa3858d3f5d128a5c8466b700098109edcad5f2repo sync				else if (mfs.equals("bt4"))
60baa3858d3f5d128a5c8466b700098109edcad5f2repo sync					MatchFinder = 1;
61baa3858d3f5d128a5c8466b700098109edcad5f2repo sync				else if (mfs.equals("bt4b"))
62baa3858d3f5d128a5c8466b700098109edcad5f2repo sync					MatchFinder = 2;
63baa3858d3f5d128a5c8466b700098109edcad5f2repo sync				else
64baa3858d3f5d128a5c8466b700098109edcad5f2repo sync					return false;
65baa3858d3f5d128a5c8466b700098109edcad5f2repo sync			}
66baa3858d3f5d128a5c8466b700098109edcad5f2repo sync			else
67baa3858d3f5d128a5c8466b700098109edcad5f2repo sync				return false;
68baa3858d3f5d128a5c8466b700098109edcad5f2repo sync			return true;
69baa3858d3f5d128a5c8466b700098109edcad5f2repo sync		}
70baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
71baa3858d3f5d128a5c8466b700098109edcad5f2repo sync		public boolean Parse(String[] args) throws Exception
72baa3858d3f5d128a5c8466b700098109edcad5f2repo sync		{
73baa3858d3f5d128a5c8466b700098109edcad5f2repo sync			int pos = 0;
74baa3858d3f5d128a5c8466b700098109edcad5f2repo sync			boolean switchMode = true;
75baa3858d3f5d128a5c8466b700098109edcad5f2repo sync			for (int i = 0; i < args.length; i++)
76baa3858d3f5d128a5c8466b700098109edcad5f2repo sync			{
77baa3858d3f5d128a5c8466b700098109edcad5f2repo sync				String s = args[i];
78baa3858d3f5d128a5c8466b700098109edcad5f2repo sync				if (s.length() == 0)
79baa3858d3f5d128a5c8466b700098109edcad5f2repo sync					return false;
80baa3858d3f5d128a5c8466b700098109edcad5f2repo sync				if (switchMode)
81baa3858d3f5d128a5c8466b700098109edcad5f2repo sync				{
82baa3858d3f5d128a5c8466b700098109edcad5f2repo sync					if (s.compareTo("--") == 0)
83baa3858d3f5d128a5c8466b700098109edcad5f2repo sync					{
84baa3858d3f5d128a5c8466b700098109edcad5f2repo sync						switchMode = false;
85baa3858d3f5d128a5c8466b700098109edcad5f2repo sync						continue;
86baa3858d3f5d128a5c8466b700098109edcad5f2repo sync					}
87baa3858d3f5d128a5c8466b700098109edcad5f2repo sync					if (s.charAt(0) == '-')
88baa3858d3f5d128a5c8466b700098109edcad5f2repo sync					{
89baa3858d3f5d128a5c8466b700098109edcad5f2repo sync						String sw = s.substring(1).toLowerCase();
90baa3858d3f5d128a5c8466b700098109edcad5f2repo sync						if (sw.length() == 0)
91baa3858d3f5d128a5c8466b700098109edcad5f2repo sync							return false;
92baa3858d3f5d128a5c8466b700098109edcad5f2repo sync						try
93baa3858d3f5d128a5c8466b700098109edcad5f2repo sync						{
94baa3858d3f5d128a5c8466b700098109edcad5f2repo sync							if (!ParseSwitch(sw))
95baa3858d3f5d128a5c8466b700098109edcad5f2repo sync								return false;
96baa3858d3f5d128a5c8466b700098109edcad5f2repo sync						}
97baa3858d3f5d128a5c8466b700098109edcad5f2repo sync						catch (NumberFormatException e)
98baa3858d3f5d128a5c8466b700098109edcad5f2repo sync						{
99baa3858d3f5d128a5c8466b700098109edcad5f2repo sync							return false;
100baa3858d3f5d128a5c8466b700098109edcad5f2repo sync						}
101baa3858d3f5d128a5c8466b700098109edcad5f2repo sync						continue;
102baa3858d3f5d128a5c8466b700098109edcad5f2repo sync					}
103baa3858d3f5d128a5c8466b700098109edcad5f2repo sync				}
104baa3858d3f5d128a5c8466b700098109edcad5f2repo sync				if (pos == 0)
105baa3858d3f5d128a5c8466b700098109edcad5f2repo sync				{
106baa3858d3f5d128a5c8466b700098109edcad5f2repo sync					if (s.equalsIgnoreCase("e"))
107baa3858d3f5d128a5c8466b700098109edcad5f2repo sync						Command = kEncode;
108baa3858d3f5d128a5c8466b700098109edcad5f2repo sync					else if (s.equalsIgnoreCase("d"))
109baa3858d3f5d128a5c8466b700098109edcad5f2repo sync						Command = kDecode;
110baa3858d3f5d128a5c8466b700098109edcad5f2repo sync					else if (s.equalsIgnoreCase("b"))
111baa3858d3f5d128a5c8466b700098109edcad5f2repo sync						Command = kBenchmak;
112baa3858d3f5d128a5c8466b700098109edcad5f2repo sync					else
113baa3858d3f5d128a5c8466b700098109edcad5f2repo sync						return false;
114baa3858d3f5d128a5c8466b700098109edcad5f2repo sync				}
115baa3858d3f5d128a5c8466b700098109edcad5f2repo sync				else if(pos == 1)
116baa3858d3f5d128a5c8466b700098109edcad5f2repo sync				{
117baa3858d3f5d128a5c8466b700098109edcad5f2repo sync					if (Command == kBenchmak)
118baa3858d3f5d128a5c8466b700098109edcad5f2repo sync					{
119baa3858d3f5d128a5c8466b700098109edcad5f2repo sync						try
120baa3858d3f5d128a5c8466b700098109edcad5f2repo sync						{
121baa3858d3f5d128a5c8466b700098109edcad5f2repo sync							NumBenchmarkPasses = Integer.parseInt(s);
122baa3858d3f5d128a5c8466b700098109edcad5f2repo sync							if (NumBenchmarkPasses < 1)
123baa3858d3f5d128a5c8466b700098109edcad5f2repo sync								return false;
124baa3858d3f5d128a5c8466b700098109edcad5f2repo sync						}
125baa3858d3f5d128a5c8466b700098109edcad5f2repo sync						catch (NumberFormatException e)
126baa3858d3f5d128a5c8466b700098109edcad5f2repo sync						{
127baa3858d3f5d128a5c8466b700098109edcad5f2repo sync							return false;
128baa3858d3f5d128a5c8466b700098109edcad5f2repo sync						}
129baa3858d3f5d128a5c8466b700098109edcad5f2repo sync					}
130baa3858d3f5d128a5c8466b700098109edcad5f2repo sync					else
131baa3858d3f5d128a5c8466b700098109edcad5f2repo sync						InFile = s;
132baa3858d3f5d128a5c8466b700098109edcad5f2repo sync				}
133baa3858d3f5d128a5c8466b700098109edcad5f2repo sync				else if(pos == 2)
134baa3858d3f5d128a5c8466b700098109edcad5f2repo sync					OutFile = s;
135baa3858d3f5d128a5c8466b700098109edcad5f2repo sync				else
136baa3858d3f5d128a5c8466b700098109edcad5f2repo sync					return false;
137baa3858d3f5d128a5c8466b700098109edcad5f2repo sync				pos++;
138baa3858d3f5d128a5c8466b700098109edcad5f2repo sync				continue;
139baa3858d3f5d128a5c8466b700098109edcad5f2repo sync			}
140baa3858d3f5d128a5c8466b700098109edcad5f2repo sync			return true;
141baa3858d3f5d128a5c8466b700098109edcad5f2repo sync		}
142baa3858d3f5d128a5c8466b700098109edcad5f2repo sync	}
143baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
144baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
145baa3858d3f5d128a5c8466b700098109edcad5f2repo sync	static void PrintHelp()
146baa3858d3f5d128a5c8466b700098109edcad5f2repo sync	{
147baa3858d3f5d128a5c8466b700098109edcad5f2repo sync		System.out.println(
148baa3858d3f5d128a5c8466b700098109edcad5f2repo sync				"\nUsage:  LZMA <e|d> [<switches>...] inputFile outputFile\n" +
149baa3858d3f5d128a5c8466b700098109edcad5f2repo sync				"  e: encode file\n" +
150baa3858d3f5d128a5c8466b700098109edcad5f2repo sync				"  d: decode file\n" +
151baa3858d3f5d128a5c8466b700098109edcad5f2repo sync				"  b: Benchmark\n" +
152baa3858d3f5d128a5c8466b700098109edcad5f2repo sync				"<Switches>\n" +
153baa3858d3f5d128a5c8466b700098109edcad5f2repo sync				// "  -a{N}:  set compression mode - [0, 1], default: 1 (max)\n" +
154baa3858d3f5d128a5c8466b700098109edcad5f2repo sync				"  -d{N}:  set dictionary - [0,28], default: 23 (8MB)\n" +
155baa3858d3f5d128a5c8466b700098109edcad5f2repo sync				"  -fb{N}: set number of fast bytes - [5, 273], default: 128\n" +
156baa3858d3f5d128a5c8466b700098109edcad5f2repo sync				"  -lc{N}: set number of literal context bits - [0, 8], default: 3\n" +
157baa3858d3f5d128a5c8466b700098109edcad5f2repo sync				"  -lp{N}: set number of literal pos bits - [0, 4], default: 0\n" +
158baa3858d3f5d128a5c8466b700098109edcad5f2repo sync				"  -pb{N}: set number of pos bits - [0, 4], default: 2\n" +
159baa3858d3f5d128a5c8466b700098109edcad5f2repo sync				"  -mf{MF_ID}: set Match Finder: [bt2, bt4], default: bt4\n" +
160baa3858d3f5d128a5c8466b700098109edcad5f2repo sync				"  -eos:   write End Of Stream marker\n"
161baa3858d3f5d128a5c8466b700098109edcad5f2repo sync				);
162baa3858d3f5d128a5c8466b700098109edcad5f2repo sync	}
163baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
164baa3858d3f5d128a5c8466b700098109edcad5f2repo sync	public static void main(String[] args) throws Exception
165baa3858d3f5d128a5c8466b700098109edcad5f2repo sync	{
166baa3858d3f5d128a5c8466b700098109edcad5f2repo sync		System.out.println("\nLZMA (Java) 4.61  2008-11-23\n");
167baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
168baa3858d3f5d128a5c8466b700098109edcad5f2repo sync		if (args.length < 1)
169baa3858d3f5d128a5c8466b700098109edcad5f2repo sync		{
170baa3858d3f5d128a5c8466b700098109edcad5f2repo sync			PrintHelp();
171baa3858d3f5d128a5c8466b700098109edcad5f2repo sync			return;
172baa3858d3f5d128a5c8466b700098109edcad5f2repo sync		}
173baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
174baa3858d3f5d128a5c8466b700098109edcad5f2repo sync		CommandLine params = new CommandLine();
175baa3858d3f5d128a5c8466b700098109edcad5f2repo sync		if (!params.Parse(args))
176baa3858d3f5d128a5c8466b700098109edcad5f2repo sync		{
177baa3858d3f5d128a5c8466b700098109edcad5f2repo sync			System.out.println("\nIncorrect command");
178baa3858d3f5d128a5c8466b700098109edcad5f2repo sync			return;
179baa3858d3f5d128a5c8466b700098109edcad5f2repo sync		}
180baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
181baa3858d3f5d128a5c8466b700098109edcad5f2repo sync		if (params.Command == CommandLine.kBenchmak)
182baa3858d3f5d128a5c8466b700098109edcad5f2repo sync		{
183baa3858d3f5d128a5c8466b700098109edcad5f2repo sync			int dictionary = (1 << 21);
184baa3858d3f5d128a5c8466b700098109edcad5f2repo sync			if (params.DictionarySizeIsDefined)
185baa3858d3f5d128a5c8466b700098109edcad5f2repo sync				dictionary = params.DictionarySize;
186baa3858d3f5d128a5c8466b700098109edcad5f2repo sync			if (params.MatchFinder > 1)
187baa3858d3f5d128a5c8466b700098109edcad5f2repo sync				throw new Exception("Unsupported match finder");
188baa3858d3f5d128a5c8466b700098109edcad5f2repo sync			SevenZip.LzmaBench.LzmaBenchmark(params.NumBenchmarkPasses, dictionary);
189baa3858d3f5d128a5c8466b700098109edcad5f2repo sync		}
190baa3858d3f5d128a5c8466b700098109edcad5f2repo sync		else if (params.Command == CommandLine.kEncode || params.Command == CommandLine.kDecode)
191baa3858d3f5d128a5c8466b700098109edcad5f2repo sync		{
192baa3858d3f5d128a5c8466b700098109edcad5f2repo sync			java.io.File inFile = new java.io.File(params.InFile);
193baa3858d3f5d128a5c8466b700098109edcad5f2repo sync			java.io.File outFile = new java.io.File(params.OutFile);
194baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
195baa3858d3f5d128a5c8466b700098109edcad5f2repo sync			java.io.BufferedInputStream inStream  = new java.io.BufferedInputStream(new java.io.FileInputStream(inFile));
196baa3858d3f5d128a5c8466b700098109edcad5f2repo sync			java.io.BufferedOutputStream outStream = new java.io.BufferedOutputStream(new java.io.FileOutputStream(outFile));
197baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
198baa3858d3f5d128a5c8466b700098109edcad5f2repo sync			boolean eos = false;
199baa3858d3f5d128a5c8466b700098109edcad5f2repo sync			if (params.Eos)
200baa3858d3f5d128a5c8466b700098109edcad5f2repo sync				eos = true;
201baa3858d3f5d128a5c8466b700098109edcad5f2repo sync			if (params.Command == CommandLine.kEncode)
202baa3858d3f5d128a5c8466b700098109edcad5f2repo sync			{
203baa3858d3f5d128a5c8466b700098109edcad5f2repo sync				SevenZip.Compression.LZMA.Encoder encoder = new SevenZip.Compression.LZMA.Encoder();
204baa3858d3f5d128a5c8466b700098109edcad5f2repo sync				if (!encoder.SetAlgorithm(params.Algorithm))
205baa3858d3f5d128a5c8466b700098109edcad5f2repo sync					throw new Exception("Incorrect compression mode");
206baa3858d3f5d128a5c8466b700098109edcad5f2repo sync				if (!encoder.SetDictionarySize(params.DictionarySize))
207baa3858d3f5d128a5c8466b700098109edcad5f2repo sync					throw new Exception("Incorrect dictionary size");
208baa3858d3f5d128a5c8466b700098109edcad5f2repo sync				if (!encoder.SetNumFastBytes(params.Fb))
209baa3858d3f5d128a5c8466b700098109edcad5f2repo sync					throw new Exception("Incorrect -fb value");
210baa3858d3f5d128a5c8466b700098109edcad5f2repo sync				if (!encoder.SetMatchFinder(params.MatchFinder))
211baa3858d3f5d128a5c8466b700098109edcad5f2repo sync					throw new Exception("Incorrect -mf value");
212baa3858d3f5d128a5c8466b700098109edcad5f2repo sync				if (!encoder.SetLcLpPb(params.Lc, params.Lp, params.Pb))
213baa3858d3f5d128a5c8466b700098109edcad5f2repo sync					throw new Exception("Incorrect -lc or -lp or -pb value");
214baa3858d3f5d128a5c8466b700098109edcad5f2repo sync				encoder.SetEndMarkerMode(eos);
215baa3858d3f5d128a5c8466b700098109edcad5f2repo sync				encoder.WriteCoderProperties(outStream);
216baa3858d3f5d128a5c8466b700098109edcad5f2repo sync				long fileSize;
217baa3858d3f5d128a5c8466b700098109edcad5f2repo sync				if (eos)
218baa3858d3f5d128a5c8466b700098109edcad5f2repo sync					fileSize = -1;
219baa3858d3f5d128a5c8466b700098109edcad5f2repo sync				else
220baa3858d3f5d128a5c8466b700098109edcad5f2repo sync					fileSize = inFile.length();
221baa3858d3f5d128a5c8466b700098109edcad5f2repo sync				for (int i = 0; i < 8; i++)
222baa3858d3f5d128a5c8466b700098109edcad5f2repo sync					outStream.write((int)(fileSize >>> (8 * i)) & 0xFF);
223baa3858d3f5d128a5c8466b700098109edcad5f2repo sync				encoder.Code(inStream, outStream, -1, -1, null);
224baa3858d3f5d128a5c8466b700098109edcad5f2repo sync			}
225baa3858d3f5d128a5c8466b700098109edcad5f2repo sync			else
226baa3858d3f5d128a5c8466b700098109edcad5f2repo sync			{
227baa3858d3f5d128a5c8466b700098109edcad5f2repo sync				int propertiesSize = 5;
228baa3858d3f5d128a5c8466b700098109edcad5f2repo sync				byte[] properties = new byte[propertiesSize];
229baa3858d3f5d128a5c8466b700098109edcad5f2repo sync				if (inStream.read(properties, 0, propertiesSize) != propertiesSize)
230baa3858d3f5d128a5c8466b700098109edcad5f2repo sync					throw new Exception("input .lzma file is too short");
231baa3858d3f5d128a5c8466b700098109edcad5f2repo sync				SevenZip.Compression.LZMA.Decoder decoder = new SevenZip.Compression.LZMA.Decoder();
232baa3858d3f5d128a5c8466b700098109edcad5f2repo sync				if (!decoder.SetDecoderProperties(properties))
233baa3858d3f5d128a5c8466b700098109edcad5f2repo sync					throw new Exception("Incorrect stream properties");
234baa3858d3f5d128a5c8466b700098109edcad5f2repo sync				long outSize = 0;
235baa3858d3f5d128a5c8466b700098109edcad5f2repo sync				for (int i = 0; i < 8; i++)
236baa3858d3f5d128a5c8466b700098109edcad5f2repo sync				{
237baa3858d3f5d128a5c8466b700098109edcad5f2repo sync					int v = inStream.read();
238baa3858d3f5d128a5c8466b700098109edcad5f2repo sync					if (v < 0)
239baa3858d3f5d128a5c8466b700098109edcad5f2repo sync						throw new Exception("Can't read stream size");
240baa3858d3f5d128a5c8466b700098109edcad5f2repo sync					outSize |= ((long)v) << (8 * i);
241baa3858d3f5d128a5c8466b700098109edcad5f2repo sync				}
242baa3858d3f5d128a5c8466b700098109edcad5f2repo sync				if (!decoder.Code(inStream, outStream, outSize))
243baa3858d3f5d128a5c8466b700098109edcad5f2repo sync					throw new Exception("Error in data stream");
244baa3858d3f5d128a5c8466b700098109edcad5f2repo sync			}
245baa3858d3f5d128a5c8466b700098109edcad5f2repo sync			outStream.flush();
246baa3858d3f5d128a5c8466b700098109edcad5f2repo sync			outStream.close();
247baa3858d3f5d128a5c8466b700098109edcad5f2repo sync			inStream.close();
248baa3858d3f5d128a5c8466b700098109edcad5f2repo sync		}
249baa3858d3f5d128a5c8466b700098109edcad5f2repo sync		else
250baa3858d3f5d128a5c8466b700098109edcad5f2repo sync			throw new Exception("Incorrect command");
251baa3858d3f5d128a5c8466b700098109edcad5f2repo sync		return;
252baa3858d3f5d128a5c8466b700098109edcad5f2repo sync	}
253baa3858d3f5d128a5c8466b700098109edcad5f2repo sync}
254