Example usage for java.lang Character MAX_RADIX

List of usage examples for java.lang Character MAX_RADIX

Introduction

In this page you can find the example usage for java.lang Character MAX_RADIX.

Prototype

int MAX_RADIX

To view the source code for java.lang Character MAX_RADIX.

Click Source Link

Document

The maximum radix available for conversion to and from strings.

Usage

From source file:org.apache.blur.mapreduce.lib.CsvBlurMapper.java

@Override
protected void map(Writable k, Text value, Context context) throws IOException, InterruptedException {
    BlurRecord record = _mutate.getRecord();
    record.clearColumns();/*from   w w w. j a  v  a  2 s .c om*/
    String str = value.toString();

    Iterable<String> split = _splitter.split(str);
    List<String> list = toList(split);

    int offset = 0;
    boolean gen = false;
    if (!_autoGenerateRowIdAsHashOfData) {
        record.setRowId(list.get(offset++));
    } else {
        _digest.reset();
        byte[] bs = value.getBytes();
        int length = value.getLength();
        _digest.update(bs, 0, length);
        record.setRowId(new BigInteger(_digest.digest()).toString(Character.MAX_RADIX));
        gen = true;
    }

    if (!_autoGenerateRecordIdAsHashOfData) {
        record.setRecordId(list.get(offset++));
    } else {
        if (gen) {
            record.setRecordId(record.getRowId());
        } else {
            _digest.reset();
            byte[] bs = value.getBytes();
            int length = value.getLength();
            _digest.update(bs, 0, length);
            record.setRecordId(new BigInteger(_digest.digest()).toString(Character.MAX_RADIX));
        }
    }
    String family;
    if (_familyNotInFile) {
        family = _familyFromPath;
    } else {
        family = list.get(offset++);
    }
    record.setFamily(family);

    List<String> columnNames = _columnNameMap.get(family);
    if (columnNames == null) {
        throw new IOException("Family [" + family + "] is missing in the definition.");
    }
    if (list.size() - offset != columnNames.size()) {

        String options = "";

        if (!_autoGenerateRowIdAsHashOfData) {
            options += "rowid,";
        }
        if (!_autoGenerateRecordIdAsHashOfData) {
            options += "recordid,";
        }
        if (!_familyNotInFile) {
            options += "family,";
        }
        String msg = "Record [" + str + "] does not match defined record [" + options
                + getColumnNames(columnNames) + "].";
        throw new IOException(msg);
    }

    for (int i = 0; i < columnNames.size(); i++) {
        String val = handleHiveNulls(list.get(i + offset));
        if (val != null) {
            record.addColumn(columnNames.get(i), val);
            _columnCounter.increment(1);
        }
    }
    _key.set(record.getRowId());
    _mutate.setMutateType(MUTATE_TYPE.REPLACE);
    context.write(_key, _mutate);
    _recordCounter.increment(1);
    context.progress();
}

From source file:org.forgerock.openam.authentication.modules.oauth2.OAuth.java

private String createAuthorizationState() {
    return new BigInteger(160, new SecureRandom()).toString(Character.MAX_RADIX);
}

From source file:org.hammurapi.TaskBase.java

protected File processArchive() {
    if (archive == null) {
        return null;
    }/*from w w  w  .  ja va2 s . c o  m*/

    String tmpDirProperty = System.getProperty("java.io.tmpdir");
    File tmpDir = tmpDirProperty == null ? new File(".") : new File(tmpDirProperty);
    SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
    String prefix = "har_" + sdf.format(new Date());
    File workDir = unpackDir == null ? new File(tmpDir, prefix) : unpackDir;

    for (int i = 0; unpackDir == null && workDir.exists(); i++) {
        workDir = new File(tmpDir, prefix + "_" + Integer.toString(i, Character.MAX_RADIX));
    }

    if (workDir.exists() || workDir.mkdir()) {
        try {
            ZipFile zipFile = new ZipFile(archive);
            Enumeration entries = zipFile.entries();
            while (entries.hasMoreElements()) {
                ZipEntry entry = (ZipEntry) entries.nextElement();
                if (!entry.getName().endsWith("/")) {
                    File outFile = new File(workDir, entry.getName().replace('/', File.separatorChar));
                    if (!outFile.getParentFile().exists() && !outFile.getParentFile().mkdirs()) {
                        throw new BuildException("Directory does not exist and cannot be created: "
                                + outFile.getParentFile().getAbsolutePath());
                    }

                    log("Archive entry " + entry.getName() + " unpacked to " + outFile.getAbsolutePath(),
                            Project.MSG_DEBUG);

                    byte[] buf = new byte[4096];
                    int l;
                    InputStream in = zipFile.getInputStream(entry);
                    FileOutputStream fos = new FileOutputStream(outFile);
                    while ((l = in.read(buf)) != -1) {
                        fos.write(buf, 0, l);
                    }
                    in.close();
                    fos.close();
                }
            }
            zipFile.close();

            File configFile = new File(workDir, "config.xml");
            if (configFile.exists() && configFile.isFile()) {
                Document configDoc = DocumentBuilderFactory.newInstance().newDocumentBuilder()
                        .parse(configFile);
                processConfig(workDir, configDoc.getDocumentElement());
            } else {
                throw new BuildException("Archive configuration file does not exist or is not a file");
            }
        } catch (ZipException e) {
            throw new BuildException(e.toString(), e);
        } catch (IOException e) {
            throw new BuildException(e.toString(), e);
        } catch (SAXException e) {
            throw new BuildException(e.toString(), e);
        } catch (ParserConfigurationException e) {
            throw new BuildException(e.toString(), e);
        } catch (FactoryConfigurationError e) {
            throw new BuildException(e.toString(), e);
        }
    } else {
        throw new BuildException("Could not create directory " + workDir.getAbsolutePath());
    }
    return unpackDir == null ? workDir : null;
}

From source file:org.callimachusproject.auth.DigestAuthenticationManager.java

private boolean isRecentDigest(Object target, Map<String, String[]> request,
        Map<String, String> authorization) {
    if (authorization == null)
        return false;
    String url = request.get("request-target")[0];
    String date = request.get("date")[0];
    String[] via = request.get("via");
    String realm = authorization.get("realm");
    String uri = authorization.get("uri");
    String username = authorization.get("username");
    if (username == null)
        throw new BadRequest("Missing username");
    ParsedURI parsed = new ParsedURI(url);
    String path = parsed.getPath();
    if (parsed.getQuery() != null) {
        path = path + "?" + parsed.getQuery();
    }//from w  ww .  j a  v  a  2s  .  c  o  m
    if (realm == null || !url.equals(uri) && !path.equals(uri)) {
        logger.info("Bad authorization on {} using {}", url, authorization);
        throw new BadRequest("Bad Authorization");
    }
    if (!realm.equals(authName))
        return false;
    try {
        long now = DateUtil.parseDate(date).getTime();
        String nonce = authorization.get("nonce");
        if (nonce == null)
            return false;
        int first = nonce.indexOf(':');
        int last = nonce.lastIndexOf(':');
        if (first < 0 || last < 0)
            return false;
        if (!hash(via).equals(nonce.substring(last + 1)))
            return false;
        String revision = nonce.substring(first + 1, last);
        if (!revision.equals(getRevisionOf(target)))
            return false;
        String time = nonce.substring(0, first);
        Long ms = Long.valueOf(time, Character.MAX_RADIX);
        long age = now - ms;
        return age < MAX_NONCE_AGE;
    } catch (NumberFormatException e) {
        logger.debug(e.toString(), e);
        return false;
    } catch (DateParseException e) {
        logger.warn(e.toString(), e);
        return false;
    }
}

From source file:org.callimachusproject.auth.DigestAuthenticationManager.java

private String hash(String... values) {
    long code = 0;
    if (values != null) {
        for (String str : values) {
            code = code * 31 + str.hashCode();
        }// w w  w.  ja  va2  s  .com
    }
    return Long.toString(code, Character.MAX_RADIX);
}

From source file:org.marketcetera.photon.internal.strategy.StrategyManager.java

private String encode(String string) {
    if (string == null)
        return null;
    try {//  www . j a  v a2 s. co m
        return new BigInteger(string.getBytes("UTF-8")).toString(Character.MAX_RADIX); //$NON-NLS-1$
    } catch (UnsupportedEncodingException e) {
        // java should have UTF-8
        throw new IllegalStateException(e);
    }
}

From source file:org.marketcetera.photon.internal.strategy.StrategyManager.java

private String decode(String string) {
    if (string == null)
        return null;
    try {/*w  w w  .  ja v a  2s. c  o  m*/
        return new String(new BigInteger(string, Character.MAX_RADIX).toByteArray(), "UTF-8"); //$NON-NLS-1$
    } catch (UnsupportedEncodingException e) {
        // java should have UTF-8
        throw new IllegalStateException(e);
    }
}

From source file:org.alfresco.web.ui.repo.component.UIActions.java

/**
 * @return a unique ID for a JSF component
 *///from ww  w.java 2 s. c o m
private static String createUniqueId() {
    try {
        return "id_" + new BigInteger(GUID.generate().getBytes("8859_1")).toString(Character.MAX_RADIX);
    } catch (UnsupportedEncodingException e) {
        throw new RuntimeException(e);
    }
}

From source file:org.apache.myfaces.ov2021.application.jsp.JspStateManagerImpl.java

@Override
public void writeState(FacesContext facesContext, SerializedView serializedView) throws IOException {
    if (log.isLoggable(Level.FINEST))
        log.finest("Entering writeState");

    UIViewRoot uiViewRoot = facesContext.getViewRoot();
    //save state in response (client)
    RenderKit renderKit = getRenderKitFactory().getRenderKit(facesContext, uiViewRoot.getRenderKitId());
    ResponseStateManager responseStateManager = renderKit.getResponseStateManager();

    if (isLegacyResponseStateManager(responseStateManager)) {
        responseStateManager.writeState(facesContext, serializedView);
    } else if (!isSavingStateInClient(facesContext)) {
        Object[] state = new Object[2];
        state[JSF_SEQUENCE_INDEX] = Integer.toString(getNextViewSequence(facesContext), Character.MAX_RADIX);
        responseStateManager.writeState(facesContext, state);
    } else {//from w  w w .  j  a  va 2 s . c om
        Object[] state = new Object[2];
        state[0] = serializedView.getStructure();
        state[1] = serializedView.getState();
        responseStateManager.writeState(facesContext, state);
    }

    if (log.isLoggable(Level.FINEST))
        log.finest("Exiting writeState");

}

From source file:org.apache.myfaces.ov2021.application.jsp.JspStateManagerImpl.java

@Override
public String getViewState(FacesContext facesContext) {
    UIViewRoot uiViewRoot = facesContext.getViewRoot();
    String viewId = uiViewRoot.getViewId();
    ViewDeclarationLanguage vdl = facesContext.getApplication().getViewHandler()
            .getViewDeclarationLanguage(facesContext, viewId);
    if (vdl != null) {
        StateManagementStrategy sms = vdl.getStateManagementStrategy(facesContext, viewId);

        if (sms != null) {
            if (log.isLoggable(Level.FINEST))
                log.finest("Calling saveView of StateManagementStrategy from getViewState: "
                        + sms.getClass().getName());

            return facesContext.getRenderKit().getResponseStateManager().getViewState(facesContext,
                    saveView(facesContext));
        }//from w  w w  .j  av  a 2 s .  c  o m
    }
    Object[] savedState = (Object[]) saveView(facesContext);

    if (!isSavingStateInClient(facesContext)) {
        Object[] state = new Object[2];
        state[JSF_SEQUENCE_INDEX] = Integer.toString(getNextViewSequence(facesContext), Character.MAX_RADIX);
        return facesContext.getRenderKit().getResponseStateManager().getViewState(facesContext, state);
    } else {
        return facesContext.getRenderKit().getResponseStateManager().getViewState(facesContext, savedState);
    }
}