Categories:
Audio (13)
Biotech (29)
Bytecode (22)
Database (79)
Framework (7)
Game (7)
General (497)
Graphics (53)
I/O (32)
IDE (2)
JAR Tools (70)
JavaBeans (16)
JDBC (86)
JDK (338)
JSP (20)
Logging (90)
Mail (54)
Messaging (8)
Network (106)
PDF (82)
Report (7)
Scripting (75)
Security (67)
Server (112)
Servlet (17)
SOAP (24)
Testing (55)
Web (24)
XML (287)
Other Resources:
commons-codec-1.11.jar - Apache Commons Codec
commons-codec-1.11.jar is the JAR file for Apache Commons Codec 1.11, which
provides implementations of common encoders and decoders such as Base64, Hex, Phonetic and URLs.
JAR File Size and Download Location:
JAR name: commons-codec.jar Target JDK version: 1.8 Dependency: None File name: commons-codec-1.11.jar File size: 335,042 bytes Date modified: 10/17/2017 Download: Apache Commons Codec
✍: FYIcenter
⏎ org/apache/commons/codec/cli/Digest.java
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You 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 org.apache.commons.codec.cli; import java.io.File; import java.io.IOException; import java.nio.charset.Charset; import java.security.MessageDigest; import java.util.Arrays; import java.util.Locale; import org.apache.commons.codec.binary.Hex; import org.apache.commons.codec.digest.DigestUtils; import org.apache.commons.codec.digest.MessageDigestAlgorithms; /** * A minimal command line to run digest over files, directories or a string * * @see #main(String[]) * @since 1.11 */ public class Digest { /** * Runs the digest algorithm in {@code args[0]} on the file in {@code args[1]}. If there is no {@code args[1]}, use * standard input. * * <p> * The algorithm can also be {@code ALL} or {@code *} to output one line for each known algorithm. * </p> * * @param args * {@code args[0]} is one of {@link MessageDigestAlgorithms} name, * {@link MessageDigest} name, {@code ALL}, or {@code *}. * {@code args[1+]} is a FILE/DIRECTORY/String. * @throws IOException if an error occurs */ public static void main(final String[] args) throws IOException { new Digest(args).run(); } private final String algorithm; private final String[] args; private final String[] inputs; private Digest(final String[] args) { if (args == null) { throw new IllegalArgumentException("args"); } if (args.length == 0) { throw new IllegalArgumentException( String.format("Usage: java %s [algorithm] [FILE|DIRECTORY|string] ...", Digest.class.getName())); } this.args = args; algorithm = args[0]; if (args.length <= 1) { inputs = null; } else { inputs = new String[args.length -1]; System.arraycopy(args, 1, inputs, 0, inputs.length); } } private void println(final String prefix, final byte[] digest) { println(prefix, digest, null); } private void println(final String prefix, final byte[] digest, final String fileName) { // The standard appears to be to print // hex, space, then either space or '*' followed by filename // where '*' is used for binary files // shasum(1) has a -b option which generates " *" separator // we don't distinguish binary files at present System.out.println(prefix + Hex.encodeHexString(digest) + (fileName != null ? " " + fileName : "")); } private void run() throws IOException { if (algorithm.equalsIgnoreCase("ALL") || algorithm.equals("*")) { run(MessageDigestAlgorithms.values()); return; } final MessageDigest messageDigest = DigestUtils.getDigest(algorithm, null); if (messageDigest != null) { run("", messageDigest); } else { run("", DigestUtils.getDigest(algorithm.toUpperCase(Locale.ROOT))); } } private void run(final String[] digestAlgorithms) throws IOException { for (final String messageDigestAlgorithm : digestAlgorithms) { if (DigestUtils.isAvailable(messageDigestAlgorithm)) { run(messageDigestAlgorithm + " ", messageDigestAlgorithm); } } } private void run(final String prefix, final MessageDigest messageDigest) throws IOException { if (inputs == null) { println(prefix, DigestUtils.digest(messageDigest, System.in)); return; } for(final String source : inputs) { final File file = new File(source); if (file.isFile()) { println(prefix, DigestUtils.digest(messageDigest, file), source); } else if (file.isDirectory()) { final File[] listFiles = file.listFiles(); if (listFiles != null) { run(prefix, messageDigest, listFiles); } } else { // use the default charset for the command-line parameter final byte[] bytes = source.getBytes(Charset.defaultCharset()); println(prefix, DigestUtils.digest(messageDigest, bytes)); } } } private void run(final String prefix, final MessageDigest messageDigest, final File[] files) throws IOException { for (final File file : files) { if (file.isFile()) { println(prefix, DigestUtils.digest(messageDigest, file), file.getName()); } } } private void run(final String prefix, final String messageDigestAlgorithm) throws IOException { run(prefix, DigestUtils.getDigest(messageDigestAlgorithm)); } @Override public String toString() { return String.format("%s %s", super.toString(), Arrays.toString(args)); } }
⏎ org/apache/commons/codec/cli/Digest.java
⇒ What Is commons-codec-1.8.jar
⇐ What Is commons-codec-1.11-bin.zip
2018-10-27, 47048👍, 0💬
Popular Posts:
The Apache FontBox library is an open source Java tool to obtain low level information from font fil...
Apache Axis2 is the core engine for Web services. It is a complete re-design and re-write of the wid...
iText is an ideal library for developers looking to enhance web- and other applications with dynamic...
Apache Axis2 is the core engine for Web services. It is a complete re-design and re-write of the wid...
Jettison is a collection of Java APIs (like STaX and DOM) which read and write JSON. This allows nea...