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