annotate src/ch/ethz/ssh2/compression/CompressionFactory.java @ 362:d51bf957d955

add help files to the web documentation
author Carl Byington <carl@five-ten-sg.com>
date Mon, 04 Aug 2014 08:41:56 -0700
parents 459eb9b6b84e
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
326
97da8c5fb40a pickup compression from trilead
Carl Byington <carl@five-ten-sg.com>
parents: 307
diff changeset
1 /*
97da8c5fb40a pickup compression from trilead
Carl Byington <carl@five-ten-sg.com>
parents: 307
diff changeset
2 * ConnectBot: simple, powerful, open-source SSH client for Android
97da8c5fb40a pickup compression from trilead
Carl Byington <carl@five-ten-sg.com>
parents: 307
diff changeset
3 * Copyright 2007 Kenny Root, Jeffrey Sharkey
97da8c5fb40a pickup compression from trilead
Carl Byington <carl@five-ten-sg.com>
parents: 307
diff changeset
4 *
97da8c5fb40a pickup compression from trilead
Carl Byington <carl@five-ten-sg.com>
parents: 307
diff changeset
5 * Licensed under the Apache License, Version 2.0 (the "License");
97da8c5fb40a pickup compression from trilead
Carl Byington <carl@five-ten-sg.com>
parents: 307
diff changeset
6 * you may not use this file except in compliance with the License.
97da8c5fb40a pickup compression from trilead
Carl Byington <carl@five-ten-sg.com>
parents: 307
diff changeset
7 * You may obtain a copy of the License at
97da8c5fb40a pickup compression from trilead
Carl Byington <carl@five-ten-sg.com>
parents: 307
diff changeset
8 *
97da8c5fb40a pickup compression from trilead
Carl Byington <carl@five-ten-sg.com>
parents: 307
diff changeset
9 * http://www.apache.org/licenses/LICENSE-2.0
97da8c5fb40a pickup compression from trilead
Carl Byington <carl@five-ten-sg.com>
parents: 307
diff changeset
10 *
97da8c5fb40a pickup compression from trilead
Carl Byington <carl@five-ten-sg.com>
parents: 307
diff changeset
11 * Unless required by applicable law or agreed to in writing, software
97da8c5fb40a pickup compression from trilead
Carl Byington <carl@five-ten-sg.com>
parents: 307
diff changeset
12 * distributed under the License is distributed on an "AS IS" BASIS,
97da8c5fb40a pickup compression from trilead
Carl Byington <carl@five-ten-sg.com>
parents: 307
diff changeset
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
97da8c5fb40a pickup compression from trilead
Carl Byington <carl@five-ten-sg.com>
parents: 307
diff changeset
14 * See the License for the specific language governing permissions and
97da8c5fb40a pickup compression from trilead
Carl Byington <carl@five-ten-sg.com>
parents: 307
diff changeset
15 * limitations under the License.
97da8c5fb40a pickup compression from trilead
Carl Byington <carl@five-ten-sg.com>
parents: 307
diff changeset
16 */
97da8c5fb40a pickup compression from trilead
Carl Byington <carl@five-ten-sg.com>
parents: 307
diff changeset
17
273
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
18 package ch.ethz.ssh2.compression;
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
19
326
97da8c5fb40a pickup compression from trilead
Carl Byington <carl@five-ten-sg.com>
parents: 307
diff changeset
20 import java.util.Vector;
273
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
21
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
22 /**
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
23 * @author Kenny Root
326
97da8c5fb40a pickup compression from trilead
Carl Byington <carl@five-ten-sg.com>
parents: 307
diff changeset
24 *
273
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
25 */
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
26 public class CompressionFactory {
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
27 static class CompressorEntry {
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
28 String type;
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
29 String compressorClass;
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
30
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
31 public CompressorEntry(String type, String compressorClass) {
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
32 this.type = type;
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
33 this.compressorClass = compressorClass;
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
34 }
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
35 }
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
36
326
97da8c5fb40a pickup compression from trilead
Carl Byington <carl@five-ten-sg.com>
parents: 307
diff changeset
37 static Vector<CompressorEntry> compressors = new Vector<CompressorEntry>();
273
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
38
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
39 static {
326
97da8c5fb40a pickup compression from trilead
Carl Byington <carl@five-ten-sg.com>
parents: 307
diff changeset
40 /* Higher Priority First */
328
459eb9b6b84e pickup compression from trilead
Carl Byington <carl@five-ten-sg.com>
parents: 327
diff changeset
41 compressors.addElement(new CompressorEntry("zlib", "ch.ethz.ssh2.compression.Zlib"));
459eb9b6b84e pickup compression from trilead
Carl Byington <carl@five-ten-sg.com>
parents: 327
diff changeset
42 compressors.addElement(new CompressorEntry("zlib@openssh.com", "ch.ethz.ssh2.compression.ZlibOpenSSH"));
326
97da8c5fb40a pickup compression from trilead
Carl Byington <carl@five-ten-sg.com>
parents: 307
diff changeset
43 compressors.addElement(new CompressorEntry("none", ""));
273
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
44 }
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
45
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
46 public static String[] getDefaultCompressorList() {
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
47 String list[] = new String[compressors.size()];
307
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
48
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
49 for (int i = 0; i < compressors.size(); i++) {
326
97da8c5fb40a pickup compression from trilead
Carl Byington <carl@five-ten-sg.com>
parents: 307
diff changeset
50 CompressorEntry ce = compressors.elementAt(i);
97da8c5fb40a pickup compression from trilead
Carl Byington <carl@five-ten-sg.com>
parents: 307
diff changeset
51 list[i] = new String(ce.type);
273
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
52 }
307
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
53
273
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
54 return list;
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
55 }
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
56
326
97da8c5fb40a pickup compression from trilead
Carl Byington <carl@five-ten-sg.com>
parents: 307
diff changeset
57 public static void checkCompressorList(String[] compressorCandidates) {
97da8c5fb40a pickup compression from trilead
Carl Byington <carl@five-ten-sg.com>
parents: 307
diff changeset
58 for (int i = 0; i < compressorCandidates.length; i++)
97da8c5fb40a pickup compression from trilead
Carl Byington <carl@five-ten-sg.com>
parents: 307
diff changeset
59 getEntry(compressorCandidates[i]);
273
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
60 }
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
61
327
9a657362519c pickup compression from trilead
Carl Byington <carl@five-ten-sg.com>
parents: 326
diff changeset
62 public static Compressor createCompressor(String type) {
273
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
63 try {
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
64 CompressorEntry ce = getEntry(type);
307
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
65
326
97da8c5fb40a pickup compression from trilead
Carl Byington <carl@five-ten-sg.com>
parents: 307
diff changeset
66 if ("".equals(ce.compressorClass))
273
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
67 return null;
307
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
68
273
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
69 Class<?> cc = Class.forName(ce.compressorClass);
327
9a657362519c pickup compression from trilead
Carl Byington <carl@five-ten-sg.com>
parents: 326
diff changeset
70 Compressor cmp = (Compressor) cc.newInstance();
326
97da8c5fb40a pickup compression from trilead
Carl Byington <carl@five-ten-sg.com>
parents: 307
diff changeset
71 return cmp;
273
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
72 }
307
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
73 catch (Exception e) {
273
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
74 throw new IllegalArgumentException("Cannot instantiate " + type);
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
75 }
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
76 }
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
77
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
78 private static CompressorEntry getEntry(String type) {
326
97da8c5fb40a pickup compression from trilead
Carl Byington <carl@five-ten-sg.com>
parents: 307
diff changeset
79 for (int i = 0; i < compressors.size(); i++) {
97da8c5fb40a pickup compression from trilead
Carl Byington <carl@five-ten-sg.com>
parents: 307
diff changeset
80 CompressorEntry ce = compressors.elementAt(i);
97da8c5fb40a pickup compression from trilead
Carl Byington <carl@five-ten-sg.com>
parents: 307
diff changeset
81
97da8c5fb40a pickup compression from trilead
Carl Byington <carl@five-ten-sg.com>
parents: 307
diff changeset
82 if (ce.type.equals(type))
273
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
83 return ce;
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
84 }
307
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
85
326
97da8c5fb40a pickup compression from trilead
Carl Byington <carl@five-ten-sg.com>
parents: 307
diff changeset
86 throw new IllegalArgumentException("Unkown algorithm " + type);
273
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
87 }
326
97da8c5fb40a pickup compression from trilead
Carl Byington <carl@five-ten-sg.com>
parents: 307
diff changeset
88 }