Mercurial > 510Connectbot
diff 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 |
line wrap: on
line diff
--- a/src/ch/ethz/ssh2/compression/CompressionFactory.java Thu Jul 31 09:34:31 2014 -0700 +++ b/src/ch/ethz/ssh2/compression/CompressionFactory.java Thu Jul 31 11:15:15 2014 -0700 @@ -1,11 +1,27 @@ +/* + * ConnectBot: simple, powerful, open-source SSH client for Android + * Copyright 2007 Kenny Root, Jeffrey Sharkey + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package ch.ethz.ssh2.compression; -import java.util.ArrayList; -import java.util.List; +import java.util.Vector; /** * @author Kenny Root - * @version $Id: CompressionFactory.java 156 2014-04-29 12:02:35Z dkocher@sudo.ch $ + * */ public class CompressionFactory { static class CompressorEntry { @@ -18,41 +34,41 @@ } } - private static final List<CompressorEntry> compressors - = new ArrayList<CompressorEntry>(); + static Vector<CompressorEntry> compressors = new Vector<CompressorEntry>(); static { - // Higher priority first - compressors.add(new CompressorEntry("none", null)); + /* Higher Priority First */ + compressors.addElement(new CompressorEntry("zlib", "com.trilead.ssh2.compression.Zlib")); + compressors.addElement(new CompressorEntry("zlib@openssh.com", "com.trilead.ssh2.compression.ZlibOpenSSH")); + compressors.addElement(new CompressorEntry("none", "")); } public static String[] getDefaultCompressorList() { String list[] = new String[compressors.size()]; for (int i = 0; i < compressors.size(); i++) { - CompressorEntry ce = compressors.get(i); - list[i] = ce.type; + CompressorEntry ce = compressors.elementAt(i); + list[i] = new String(ce.type); } return list; } - public static void checkCompressorList(String[] list) { - for (final String candidate : list) { - getEntry(candidate); - } + public static void checkCompressorList(String[] compressorCandidates) { + for (int i = 0; i < compressorCandidates.length; i++) + getEntry(compressorCandidates[i]); } - public static Compressor createCompressor(String type) { + public static ICompressor createCompressor(String type) { try { CompressorEntry ce = getEntry(type); - if (null == ce.compressorClass) { + if ("".equals(ce.compressorClass)) return null; - } Class<?> cc = Class.forName(ce.compressorClass); - return (Compressor) cc.newInstance(); + ICompressor cmp = (ICompressor) cc.newInstance(); + return cmp; } catch (Exception e) { throw new IllegalArgumentException("Cannot instantiate " + type); @@ -60,12 +76,13 @@ } private static CompressorEntry getEntry(String type) { - for (CompressorEntry ce : compressors) { - if (ce.type.equals(type)) { + for (int i = 0; i < compressors.size(); i++) { + CompressorEntry ce = compressors.elementAt(i); + + if (ce.type.equals(type)) return ce; - } } - throw new IllegalArgumentException("Unknown algorithm " + type); + throw new IllegalArgumentException("Unkown algorithm " + type); } -} \ No newline at end of file +}