All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.sommeri.sourcemap.Base64 Maven / Gradle / Ivy

Go to download

Less language is an extension of css and less4j compiles it into regular css. It adds several dynamic features into css: variables, expressions, nested rules. Less4j is a port. The original compiler was written in JavaScript and is called less.js. The less language is mostly defined in less.js documentation/issues and by what less.js actually do. Links to less.js: * home page: http://lesscss.org/ * source code & issues: https://github.com/cloudhead/less.js

There is a newer version: 1.17.2
Show newest version
/*
 * Copyright 2011 The Closure Compiler Authors.
 *
 * 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 com.github.sommeri.sourcemap;

import java.util.Arrays;

/**
 * A utility class for working with Base64 values.
 * @author [email protected] (John Lenz)
 */
public final class Base64 {

  // This is a utility class
  private Base64() {}

  /**
   *  A map used to convert integer values in the range 0-63 to their base64
   *  values.
   */
  private static final String BASE64_MAP =
      "ABCDEFGHIJKLMNOPQRSTUVWXYZ" +
      "abcdefghijklmnopqrstuvwxyz" +
      "0123456789+/";

  /**
   * A map used to convert base64 character into integer values.
   */
  private static final int[] BASE64_DECODE_MAP = new int[256];
  static {
      Arrays.fill(BASE64_DECODE_MAP, -1);
      for (int i = 0; i < BASE64_MAP.length(); i++) {
        BASE64_DECODE_MAP[BASE64_MAP.charAt(i)] = i;
      }
  }

  /**
   * @param value A value in the range of 0-63.
   * @return a base64 digit.
   */
  public static char toBase64(int value) {
    assert (value <= 63 && value >= 0) : "value out of range:" + value;
    return BASE64_MAP.charAt(value);
  }

  /**
   * @param c A base64 digit.
   * @return A value in the range of 0-63.
   */
  public static int fromBase64(char c) {
    int result = BASE64_DECODE_MAP[c];
    assert (result != -1) : "invalid char";
    return BASE64_DECODE_MAP[c];
  }

  /**
   * @param value an integer to base64 encode.
   * @return the six digit long base64 encoded value of the integer.
   */
  public static String base64EncodeInt(int value) {
    char[] c = new char[6];
    for (int i = 0; i < 5; i++) {
      c[i] = Base64.toBase64((value >> (26 - i * 6)) & 0x3f);
    }
    c[5] = Base64.toBase64((value << 4) & 0x3f);
    return new String(c);
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy