/** * Compares two strings based not on the strings * themselves, but on an encoding of the two * strings using the StringEncoder this Comparator * was created with. * * If an {@link EncoderException} is encountered, return <code>0</code>. * * @param o1 the object to compare * @param o2 the object to compare to * @return the Comparable.compareTo() return code or 0 if an encoding error was caught. * @see Comparable */ public int compare(Object o1, Object o2) { int compareCode = 0; try { Comparable s1 = (Comparable) ((Encoder) this.stringEncoder).encode(o1); Comparable s2 = (Comparable) ((Encoder) this.stringEncoder).encode(o2); compareCode = s1.compareTo(s2); } catch (EncoderException ee) { compareCode = 0; } return compareCode; }
/** * Tests to make sure Base64's implementation of the org.apache.commons.codec.Encoder * interface is behaving identical to commons-codec-1.3.jar. * * @throws EncoderException problem */ @Test public void testEncoder() throws EncoderException { final Encoder enc = new Base64(); for (int i = 0; i < STRINGS.length; i++) { if (STRINGS[i] != null) { final byte[] base64 = utf8(STRINGS[i]); final byte[] binary = BYTES[i]; final boolean b = Arrays.equals(base64, (byte[]) enc.encode(binary)); assertTrue("Encoder test-" + i, b); } } }
/** * Compares two strings based not on the strings * themselves, but on an encoding of the two * strings using the StringEncoder this Comparator * was created with. * * If an {@link EncoderException} is encountered, return <code>0</code>. * * @param o1 the object to compare * @param o2 the object to compare to * @return the Comparable.compareTo() return code or 0 if an encoding error was caught. * @see Comparable */ public int compare(Object o1, Object o2) { int compareCode = 0; try { Comparable s1 = (Comparable) ((Encoder) this.stringEncoder).encode(o1); Comparable s2 = (Comparable) ((Encoder) this.stringEncoder).encode(o2); compareCode = s1.compareTo(s2); } catch (EncoderException ee) { compareCode = 0; } return compareCode; }
/** * Compares two strings based not on the strings * themselves, but on an encoding of the two * strings using the StringEncoder this Comparator * was created with. * * If an {@link EncoderException} is encountered, return <code>0</code>. * * @param o1 the object to compare * @param o2 the object to compare to * @return the Comparable.compareTo() return code or 0 if an encoding error was caught. * @see Comparable */ public int compare(Object o1, Object o2) { int compareCode = 0; try { Comparable s1 = (Comparable) ((Encoder) this.stringEncoder).encode(o1); Comparable s2 = (Comparable) ((Encoder) this.stringEncoder).encode(o2); compareCode = s1.compareTo(s2); } catch (EncoderException ee) { compareCode = 0; } return compareCode; }
/** * Compares two strings based not on the strings * themselves, but on an encoding of the two * strings using the StringEncoder this Comparator * was created with. * * If an {@link EncoderException} is encountered, return <code>0</code>. * * @param o1 the object to compare * @param o2 the object to compare to * @return the Comparable.compareTo() return code or 0 if an encoding error was caught. * @see Comparable */ public int compare(Object o1, Object o2) { int compareCode = 0; try { Comparable s1 = (Comparable) ((Encoder) this.stringEncoder).encode(o1); Comparable s2 = (Comparable) ((Encoder) this.stringEncoder).encode(o2); compareCode = s1.compareTo(s2); } catch (EncoderException ee) { compareCode = 0; } return compareCode; }
/** * Compares two strings based not on the strings * themselves, but on an encoding of the two * strings using the StringEncoder this Comparator * was created with. * * If an {@link EncoderException} is encountered, return <code>0</code>. * * @param o1 the object to compare * @param o2 the object to compare to * @return the Comparable.compareTo() return code or 0 if an encoding error was caught. * @see Comparable */ public int compare(Object o1, Object o2) { int compareCode = 0; try { Comparable s1 = (Comparable) ((Encoder) this.stringEncoder).encode(o1); Comparable s2 = (Comparable) ((Encoder) this.stringEncoder).encode(o2); compareCode = s1.compareTo(s2); } catch (EncoderException ee) { compareCode = 0; } return compareCode; }
/** * Compares two strings based not on the strings * themselves, but on an encoding of the two * strings using the StringEncoder this Comparator * was created with. * * If an {@link EncoderException} is encountered, return <code>0</code>. * * @param o1 the object to compare * @param o2 the object to compare to * @return the Comparable.compareTo() return code or 0 if an encoding error was caught. * @see Comparable */ public int compare(Object o1, Object o2) { int compareCode = 0; try { Comparable s1 = (Comparable) ((Encoder) this.stringEncoder).encode(o1); Comparable s2 = (Comparable) ((Encoder) this.stringEncoder).encode(o2); compareCode = s1.compareTo(s2); } catch (EncoderException ee) { compareCode = 0; } return compareCode; }
String phonetic = null; try { String v = encoder.encode(value).toString(); if (v.length() > 0 && !value.equals(v)) phonetic = v; } catch (Exception ignored) {} // just use the direct text
String phonetic = null; try { String v = encoder.encode(value).toString(); if (v.length() > 0 && !value.equals(v)) phonetic = v; } catch (Exception ignored) {} // just use the direct text
@Test public void testInvalidAuthenticationRequest() throws Exception { MockHttpServletRequest request = new MockHttpServletRequest(); request.setRequestURI( "/feeds/unauthorized-repo" ); request.addHeader( "User-Agent", "Apache Archiva unit test" ); request.setMethod( "GET" ); Encoder encoder = new Base64(); String userPass = "unauthUser:unauthPass"; String encodedUserPass = new String( (byte[]) encoder.encode( userPass.getBytes() ) ); request.addHeader( "Authorization", "BASIC " + encodedUserPass ); MockHttpServletResponse mockHttpServletResponse = new MockHttpServletResponse(); rssFeedServlet.doGet( request, mockHttpServletResponse ); assertEquals( HttpServletResponse.SC_UNAUTHORIZED, mockHttpServletResponse.getStatus() ); }