Skip to content

Commit bdf8e5c

Browse files
committed
Add back code for 1.6 to keep binary compatibility.
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/codec/trunk@1201529 13f79535-47bb-0310-9956-ffa450edef68
1 parent 1d8ec5a commit bdf8e5c

4 files changed

Lines changed: 178 additions & 21 deletions

File tree

src/main/java/org/apache/commons/codec/binary/Base64.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,20 @@ void decode(byte[] in, int inPos, int inAvail) {
467467
}
468468
}
469469

470+
/**
471+
* Tests a given byte array to see if it contains only valid characters within the Base64 alphabet. Currently the
472+
* method treats whitespace as valid.
473+
*
474+
* @param arrayOctet
475+
* byte array to test
476+
* @return <code>true</code> if all bytes are valid characters in the Base64 alphabet or if the byte array is empty;
477+
* <code>false</code>, otherwise
478+
* @deprecated 1.5 Use {@link #isBase64(byte[])}, will be removed in 2.0.
479+
*/
480+
public static boolean isArrayByteBase64(byte[] arrayOctet) {
481+
return isBase64(arrayOctet);
482+
}
483+
470484
/**
471485
* Returns whether or not the <code>octet</code> is in the base 64 alphabet.
472486
*
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. 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+
18+
package org.apache.commons.codec.language;
19+
20+
import org.apache.commons.codec.EncoderException;
21+
import org.apache.commons.codec.StringEncoder;
22+
23+
/**
24+
* Encodes a string into a Caverphone 2.0 value. Delegate to a {@link Caverphone2} instance.
25+
*
26+
* This is an algorithm created by the Caversham Project at the University of Otago. It implements the Caverphone 2.0
27+
* algorithm:
28+
*
29+
* @author Apache Software Foundation
30+
* @version $Id: Caverphone.java 1079535 2011-03-08 20:54:37Z ggregory $
31+
* @see <a href="http://en.wikipedia.org/wiki/Caverphone">Wikipedia - Caverphone</a>
32+
* @see <a href="http://caversham.otago.ac.nz/files/working/ctp150804.pdf">Caverphone 2.0 specification</a>
33+
* @since 1.4
34+
* @deprecated 1.5 Replaced by {@link Caverphone2}, will be removed in 2.0.
35+
*/
36+
public class Caverphone implements StringEncoder {
37+
38+
/**
39+
* Delegate to a {@link Caverphone2} instance to avoid code duplication.
40+
*/
41+
final private Caverphone2 encoder = new Caverphone2();
42+
43+
/**
44+
* Creates an instance of the Caverphone encoder
45+
*/
46+
public Caverphone() {
47+
super();
48+
}
49+
50+
/**
51+
* Encodes the given String into a Caverphone value.
52+
*
53+
* @param source
54+
* String the source string
55+
* @return A caverphone code for the given String
56+
*/
57+
public String caverphone(String source) {
58+
return this.encoder.encode(source);
59+
}
60+
61+
/**
62+
* Encodes an Object using the caverphone algorithm. This method is provided in order to satisfy the requirements of
63+
* the Encoder interface, and will throw an EncoderException if the supplied object is not of type java.lang.String.
64+
*
65+
* @param pObject
66+
* Object to encode
67+
* @return An object (or type java.lang.String) containing the caverphone code which corresponds to the String
68+
* supplied.
69+
* @throws EncoderException
70+
* if the parameter supplied is not of type java.lang.String
71+
*/
72+
public Object encode(Object pObject) throws EncoderException {
73+
if (!(pObject instanceof String)) {
74+
throw new EncoderException("Parameter supplied to Caverphone encode is not of type java.lang.String");
75+
}
76+
return this.caverphone((String) pObject);
77+
}
78+
79+
/**
80+
* Encodes a String using the Caverphone algorithm.
81+
*
82+
* @param pString
83+
* String object to encode
84+
* @return The caverphone code corresponding to the String supplied
85+
*/
86+
public String encode(String pString) {
87+
return this.caverphone(pString);
88+
}
89+
90+
/**
91+
* Tests if the caverphones of two strings are identical.
92+
*
93+
* @param str1
94+
* First of two strings to compare
95+
* @param str2
96+
* Second of two strings to compare
97+
* @return <code>true</code> if the caverphones of these strings are identical, <code>false</code> otherwise.
98+
*/
99+
public boolean isCaverphoneEqual(String str1, String str2) {
100+
return this.caverphone(str1).equals(this.caverphone(str2));
101+
}
102+
103+
}

src/main/java/org/apache/commons/codec/language/Soundex.java

Lines changed: 47 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -56,29 +56,12 @@ public class Soundex implements StringEncoder {
5656
*/
5757
public static final Soundex US_ENGLISH = new Soundex();
5858

59-
6059
/**
61-
* Encodes the Strings and returns the number of characters in the two encoded Strings that are the same. This
62-
* return value ranges from 0 through 4: 0 indicates little or no similarity, and 4 indicates strong similarity or
63-
* identical values.
64-
*
65-
* @param s1
66-
* A String that will be encoded and compared.
67-
* @param s2
68-
* A String that will be encoded and compared.
69-
* @return The number of characters in the two encoded Strings that are the same from 0 to 4.
70-
*
71-
* @see SoundexUtils#difference(StringEncoder,String,String)
72-
* @see <a href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/tsqlref/ts_de-dz_8co5.asp"> MS
73-
* T-SQL DIFFERENCE </a>
60+
* The maximum length of a Soundex code - Soundex codes are only four characters by definition.
7461
*
75-
* @throws EncoderException
76-
* if an error occurs encoding one of the strings
77-
* @since 1.3
62+
* @deprecated This feature is not needed since the encoding size must be constant. Will be removed in 2.0.
7863
*/
79-
public int difference(String s1, String s2) throws EncoderException {
80-
return SoundexUtils.difference(this, s1, s2);
81-
}
64+
private int maxLength = 4;
8265

8366
/**
8467
* Every letter of the alphabet is "mapped" to a numerical value. This char array holds the values to which each
@@ -123,6 +106,29 @@ public Soundex(String mapping) {
123106
this.soundexMapping = mapping.toCharArray();
124107
}
125108

109+
/**
110+
* Encodes the Strings and returns the number of characters in the two encoded Strings that are the same. This
111+
* return value ranges from 0 through 4: 0 indicates little or no similarity, and 4 indicates strong similarity or
112+
* identical values.
113+
*
114+
* @param s1
115+
* A String that will be encoded and compared.
116+
* @param s2
117+
* A String that will be encoded and compared.
118+
* @return The number of characters in the two encoded Strings that are the same from 0 to 4.
119+
*
120+
* @see SoundexUtils#difference(StringEncoder,String,String)
121+
* @see <a href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/tsqlref/ts_de-dz_8co5.asp"> MS
122+
* T-SQL DIFFERENCE </a>
123+
*
124+
* @throws EncoderException
125+
* if an error occurs encoding one of the strings
126+
* @since 1.3
127+
*/
128+
public int difference(String s1, String s2) throws EncoderException {
129+
return SoundexUtils.difference(this, s1, s2);
130+
}
131+
126132
/**
127133
* Encodes an Object using the soundex algorithm. This method is provided in order to satisfy the requirements of
128134
* the Encoder interface, and will throw an EncoderException if the supplied object is not of type java.lang.String.
@@ -186,6 +192,16 @@ private char getMappingCode(String str, int index) {
186192
return mappedChar;
187193
}
188194

195+
/**
196+
* Returns the maxLength. Standard Soundex
197+
*
198+
* @deprecated This feature is not needed since the encoding size must be constant. Will be removed in 2.0.
199+
* @return int
200+
*/
201+
public int getMaxLength() {
202+
return this.maxLength;
203+
}
204+
189205
/**
190206
* Returns the soundex mapping.
191207
*
@@ -212,6 +228,17 @@ private char map(char ch) {
212228
return this.getSoundexMapping()[index];
213229
}
214230

231+
/**
232+
* Sets the maxLength.
233+
*
234+
* @deprecated This feature is not needed since the encoding size must be constant. Will be removed in 2.0.
235+
* @param maxLength
236+
* The maxLength to set
237+
*/
238+
public void setMaxLength(int maxLength) {
239+
this.maxLength = maxLength;
240+
}
241+
215242
/**
216243
* Retrieves the Soundex code for a given String object.
217244
*

src/main/java/org/apache/commons/codec/net/URLCodec.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,10 @@ public class URLCodec implements BinaryEncoder, BinaryDecoder, StringEncoder, St
5959

6060
/**
6161
* The default charset used for string decoding and encoding.
62+
*
63+
* TODO: This field will be final in 2.0.
6264
*/
63-
protected final String charset;
65+
protected String charset;
6466

6567
/**
6668
* Release 1.5 made this field final.
@@ -346,4 +348,15 @@ public String getDefaultCharset() {
346348
return this.charset;
347349
}
348350

351+
/**
352+
* The <code>String</code> encoding used for decoding and encoding.
353+
*
354+
* @return Returns the encoding.
355+
*
356+
* @deprecated Use {@link #getDefaultCharset()}, will be removed in 2.0.
357+
*/
358+
public String getEncoding() {
359+
return this.charset;
360+
}
361+
349362
}

0 commit comments

Comments
 (0)