예제 #1
0
 /**
  * Creates a Base64 codec used for decoding (all modes) and encoding in URL-unsafe mode.
  *
  * <p>When encoding the line length and line separator are given in the constructor, and the
  * encoding table is STANDARD_ENCODE_TABLE.
  *
  * <p>Line lengths that aren't multiples of 4 will still essentially end up being multiples of 4
  * in the encoded data.
  *
  * <p>When decoding all variants are supported.
  *
  * @param lineLength Each line of encoded data will be at most of the given length (rounded down
  *     to nearest multiple of 4). If lineLength <= 0, then the output will not be divided into
  *     lines (chunks). Ignored when decoding.
  * @param lineSeparator Each line of encoded data will end with this sequence of bytes.
  * @param urlSafe Instead of emitting '+' and '/' we emit '-' and '_' respectively. urlSafe is
  *     only applied to encode operations. Decoding seamlessly handles both modes.
  * @throws IllegalArgumentException The provided lineSeparator included some base64 characters.
  *     That's not going to work!
  * @since 1.4
  */
 public Base64(final int lineLength, final byte[] lineSeparator, final boolean urlSafe) {
   unencodedBlockSize = BYTES_PER_UNENCODED_BLOCK;
   encodedBlockSize = BYTES_PER_ENCODED_BLOCK;
   this.lineLength = lineLength;
   chunkSeparatorLength = lineSeparator == null ? 0 : lineSeparator.length;
   // TODO could be simplified if there is no requirement to reject invalid line sep when length
   // <=0
   // @see test case Base64Test.testConstructors()
   if (lineSeparator != null) {
     if (containsAlphabetOrPad(lineSeparator)) {
       final String sep = StringUtil.newStringUtf8(lineSeparator);
       throw new IllegalArgumentException(
           "lineSeparator must not contain base64 characters: [" + sep + "]");
     }
     if (lineLength > 0) { // null line-sep forces no chunking rather than throwing IAE
       encodeSize = BYTES_PER_ENCODED_BLOCK + lineSeparator.length;
       this.lineSeparator = new byte[lineSeparator.length];
       System.arraycopy(lineSeparator, 0, this.lineSeparator, 0, lineSeparator.length);
     } else {
       encodeSize = BYTES_PER_ENCODED_BLOCK;
       this.lineSeparator = null;
     }
   } else {
     encodeSize = BYTES_PER_ENCODED_BLOCK;
     this.lineSeparator = null;
   }
   decodeSize = encodeSize - 1;
   encodeTable = urlSafe ? URL_SAFE_ENCODE_TABLE : STANDARD_ENCODE_TABLE;
 }
예제 #2
0
 @Override
 public int drawLine(final Graphics render, int idx) {
   final String[] items = menu.getItems();
   int i = 0;
   for (final String item : items) {
     StringUtil.drawLine(render, idx++, i++ + ": [red]" + item);
   }
   return idx;
 }
예제 #3
0
 @Override
 public final int drawLine(final Graphics render, int idx) {
   final String camPos =
       "Camera Position (x,y,z): ("
           + client.getCamPosX()
           + ", "
           + client.getCamPosY()
           + ", "
           + client.getCamPosZ()
           + ")";
   final String camAngle =
       "Camera Angle (pitch, yaw): ("
           + client.getCameraPitch()
           + ", "
           + client.getCameraYaw()
           + ")";
   StringUtil.drawLine(render, idx++, camPos);
   StringUtil.drawLine(render, idx++, camAngle);
   return idx;
 }
예제 #4
0
        @Override
        public String format(final LogRecord record) {
          final String[] className = record.getLoggerName().split("\\.");
          final String name = className[className.length - 1];
          final int maxLen = 22;
          final String append = "...";

          return String.format(
              "[%s] %-" + maxLen + "s %s %s",
              dateFormat.format(record.getMillis()),
              name.length() > maxLen ? name.substring(0, maxLen - append.length()) + append : name,
              record.getMessage(),
              StringUtil.throwableToString(record.getThrown()));
        }
예제 #5
0
파일: DRM.java 프로젝트: Latency/UtopianBot
 public static String getServiceKey() {
   final File key = new File(Configuration.Paths.getServiceKey());
   if (key.exists() && key.canRead()) return StringUtil.newStringUtf8(IOHelper.read(key));
   return DEFAULTKEY;
 }
예제 #6
0
 /**
  * Encodes binary data using a URL-safe variation of the base64 algorithm but does not chunk the
  * output. The url-safe variation emits - and _ instead of + and / characters.
  *
  * @param binaryData binary data to encode
  * @return String containing Base64 characters
  * @since 1.4
  */
 public static String encodeBase64URLSafeString(final byte[] binaryData) {
   return StringUtil.newStringUtf8(encodeBase64(binaryData, false, true));
 }
예제 #7
0
 /**
  * Tests a given String to see if it contains only valid characters within the Base64 alphabet.
  * Currently the method treats whitespace as valid.
  *
  * @param base64 String to test
  * @return <code>true</code> if all characters in the String are valid characters in the Base64
  *     alphabet or if the String is empty; <code>false</code>, otherwise
  * @since 1.5
  */
 public static boolean isBase64(final String base64) {
   return isBase64(StringUtil.getBytesUtf8(base64));
 }
예제 #8
0
 /**
  * Tests a given String to see if it contains only valid characters within the alphabet. The
  * method treats whitespace and PAD as valid.
  *
  * @param basen String to test
  * @return <code>true</code> if all characters in the String are valid characters in the alphabet
  *     or if the String is empty; <code>false</code>, otherwise
  * @see #isInAlphabet(byte[], boolean)
  */
 public boolean isInAlphabet(final String basen) {
   return isInAlphabet(StringUtil.getBytesUtf8(basen), true);
 }
예제 #9
0
 /**
  * Encodes a byte[] containing binary data, into a String containing characters in the appropriate
  * alphabet. Uses UTF8 encoding.
  *
  * @param pArray a byte array containing binary data
  * @return String containing only character data in the appropriate alphabet.
  */
 public String encodeAsString(final byte[] pArray) {
   return StringUtil.newStringUtf8(encode(pArray));
 }
예제 #10
0
 /**
  * Decodes a String containing characters in the Base-N alphabet.
  *
  * @param pArray A String containing Base-N character data
  * @return a byte array containing binary data
  */
 public byte[] decode(final String pArray) {
   return decode(StringUtil.getBytesUtf8(pArray));
 }
예제 #11
0
 public static String getVersionFormatted() {
   return StringUtil.formatVersion(getVersion());
 }