March 3, 2008
The Google Web Toolkit software and sample code developed by Google is licensed under the Apache License, v. 2.0. Other software included in this distribution is provided under other licenses, as listed in the Included Software and Licenses section at the bottom of this page. Source code for software included in this distribution is available from the Google Web Toolkit project or as otherwise indicated at the bottom of this page.
Please note that the executable version of the Google Web Toolkit distributed by Google will communicate with Google's servers to check for available updates. If updates are available, you will receive the option to install them.
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
"License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files.
"Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions:
5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability.
The following third party software is distributed with Google Web Toolkit and is provided under other licenses and/or has source available from other locations. Where "gwt-dev.jar" is listed, substitute in the name of the jar corresponding to your platform, e.g. "gwt-dev-linux.jar".
| Package | License | Source Code Availability |
|---|---|---|
| Apache Tomcat | Apache License v. 2.0 (above) | tomcat.apache.org; modifications are at org/apache/tomcat/ within gwt-dev.jar |
| Apache Tapestry | Apache License v. 2.0 (above) | tapestry.apache.org |
| ASM 3.1 | (custom) | com/google/gwt/dev/asm/ within gwt-dev.jar |
| Eclipse Java Development Tools (JDT) | Eclipse Public License v. 1.0 | eclipse.org |
| Eclipse Standard Widget Toolkit (SWT) | Eclipse Public License v. 1.0 | Linux, Windows, and Mac; modifications are at org/eclipse/swt/ within gwt-dev.jar |
| Jetty 6.1.11 | Apache License v. 2.0 (above) | mortbay.org/jetty |
| Mozilla Rhino | Mozilla Public License v. 1.1 | com/google/gwt/dev/js/rhino/ within gwt-dev.jar |
| Mozilla 1.7.12 (Linux only) | Mozilla Public License v. 1.1 | mozilla.org |
| Protobuf | New BSD License | code.google.com/p/protobuf; binary modifications consist of package-rebasing. The rebased classes are rooted at com/google/gwt/dev/protobuf/ within gwt-dev.jar |
| Google Web Toolkit |
| Version 2.8.3 (Git revision 0d0b5d352) |
Release notes can be found on the GWT project hosting website.
================================================ FILE: gwt/gwt-2.8.3/webAppCreator ================================================ #!/bin/sh HOMEDIR=`dirname $0`; java -cp $HOMEDIR/gwt-user.jar:$HOMEDIR/gwt-dev.jar com.google.gwt.user.tools.WebAppCreator "$@"; ================================================ FILE: gwt/gwt-2.8.3/webAppCreator.cmd ================================================ @java -cp "%~dp0\gwt-user.jar;%~dp0\gwt-dev.jar" com.google.gwt.user.tools.WebAppCreator %* ================================================ FILE: lib/nabu-v0.9-jar-with-dependencies.jar ================================================ [File too large to display: 46.8 MB] ================================================ FILE: lib-build/gwt-user.jar ================================================ [File too large to display: 16.9 MB] ================================================ FILE: reproducible-test.sh ================================================ #!/bin/bash ant dist hash1=`sha256sum Peergos.jar` ant dist hash2=`sha256sum Peergos.jar` if [[ $hash1 == $hash2 ]]; then exit 0 else exit -1 fi ================================================ FILE: scripts/ensure-compile.sh ================================================ #!/bin/bash ## ## To set this as the pre-commit hook do: ## ## ln -s $(git rev-parse --show-toplevel)/scripts/ensure-compile.sh $(git rev-parse --show-toplevel)/.git/hooks/pre-commit ## echo "********************************" echo " Checking if project compiles.." echo "********************************" if ! ant compile; then echo "Project failed to compile" exit 1 fi ================================================ FILE: src/peergos/Peergos.gwt.xml ================================================* This class is used to encode and decode data in Base64 format as described in RFC 1521. * *
* Project home page: www.source-code.biz/base64coder/java
* The default pushback buffer size one byte, but this can be overridden
* by the creator of the stream.
*
*
* @author Aaron M. Renn (arenn@urbanophile.com)
* @author Warren Levy (warrenl@cygnus.com)
*/
public class PushbackInputStream extends FilterInputStream
{
/**
* This is the default buffer size
*/
private static final int DEFAULT_BUFFER_SIZE = 1;
/**
* This is the buffer that is used to store the pushed back data
*/
protected byte[] buf;
/**
* This is the position in the buffer from which the next byte will be
* read. Bytes are stored in reverse order in the buffer, starting from
*
* This method will return the number of bytes available from the
* pushback buffer plus the number of bytes available from the
* underlying stream.
*
* @return The number of bytes that can be read before blocking could occur
*
* @exception IOException If an error occurs
*/
public int available() throws IOException
{
try
{
return (buf.length - pos) + super.available();
}
catch (NullPointerException npe)
{
throw new IOException ("Stream closed");
}
}
/**
* This method closes the stream and releases any associated resources.
*
* @exception IOException If an error occurs.
*/
public synchronized void close() throws IOException
{
buf = null;
super.close();
}
/**
* This method returns
* This method will block until the byte can be read.
*
* @return The byte read or -1 if end of stream
*
* @exception IOException If an error occurs
*/
public synchronized int read() throws IOException
{
if (pos < buf.length)
return ((int) buf[pos++]) & 0xFF;
return super.read();
}
/**
* This method read bytes from a stream and stores them into a
* caller supplied buffer. It starts storing the data at index
*
* This method will block until some data can be read.
*
* This method first reads bytes from the pushback buffer in order to
* satisfy the read request. If the pushback buffer cannot provide all
* of the bytes requested, the remaining bytes are read from the
* underlying stream.
*
* @param b The array into which the bytes read should be stored
* @param off The offset into the array to start storing bytes
* @param len The requested number of bytes to read
*
* @return The actual number of bytes read, or -1 if end of stream.
*
* @exception IOException If an error occurs.
*/
public synchronized int read(byte[] b, int off, int len) throws IOException
{
int numBytes = Math.min(buf.length - pos, len);
if (numBytes > 0)
{
System.arraycopy (buf, pos, b, off, numBytes);
pos += numBytes;
len -= numBytes;
off += numBytes;
}
if (len > 0)
{
len = super.read(b, off, len);
if (len == -1) //EOF
return numBytes > 0 ? numBytes : -1;
numBytes += len;
}
return numBytes;
}
/**
* This method pushes a single byte of data into the pushback buffer.
* The byte pushed back is the one that will be returned as the first byte
* of the next read.
*
* If the pushback buffer is full, this method throws an exception.
*
* The argument to this method is an
* If the pushback buffer cannot hold all of the requested bytes, an
* exception is thrown.
*
* @param b The byte array to be pushed back
*
* @exception IOException If the pushback buffer is full
*/
public synchronized void unread(byte[] b) throws IOException
{
unread(b, 0, b.length);
}
/**
* This method pushed back bytes from the passed in array into the
* pushback buffer. The bytes from
* If the pushback buffer cannot hold all of the requested bytes, an
* exception is thrown.
*
* @param b The byte array to be pushed back
* @param off The index into the array where the bytes to be push start
* @param len The number of bytes to be pushed.
*
* @exception IOException If the pushback buffer is full
*/
public synchronized void unread(byte[] b, int off, int len)
throws IOException
{
if (pos < len)
throw new IOException("Insufficient space in pushback buffer");
// Note the order that these bytes are being added is the opposite
// of what would be done if they were added to the buffer one at a time.
// See the Java Class Libraries book p. 1390.
System.arraycopy(b, off, buf, pos - len, len);
// Don't put this into the arraycopy above, an exception might be thrown
// and in that case we don't want to modify pos.
pos -= len;
}
/**
* This method skips the specified number of bytes in the stream. It
* returns the actual number of bytes skipped, which may be less than the
* requested amount.
*
* This method first discards bytes from the buffer, then calls the
*
* This abstract class does not provide a fully working implementation, so it needs to be subclassed, and at least the
* {@link #write(char[], int, int)}, {@link #close()} and {@link #flush()} methods needs to be overridden. Overriding some of the
* non-abstract methods is also often advised, since it might result in higher efficiency.
*
* Many specialized readers for purposes like reading from a file already exist in this package.
*
* @see Reader */
public abstract class Writer implements Appendable, Closeable, Flushable {
static final String TOKEN_NULL = "null"; //$NON-NLS-1$
/*** The object used to synchronize access to the writer. */
protected Object lock;
/*** Constructs a new {@code Writer} with {@code this} as the object used to synchronize critical sections. */
protected Writer () {
super();
lock = this;
}
/*** Constructs a new {@code Writer} with {@code lock} used to synchronize critical sections.
*
* @param lock the {@code Object} used to synchronize critical sections.
* @throws NullPointerException if {@code lock} is {@code null}. */
protected Writer (Object lock) {
if (lock == null) {
throw new NullPointerException();
}
this.lock = lock;
}
/*** Closes this writer. Implementations of this method should free any resources associated with the writer.
*
* @throws IOException if an error occurs while closing this writer. */
public abstract void close () throws IOException;
/*** Flushes this writer. Implementations of this method should ensure that all buffered characters are written to the target.
*
* @throws IOException if an error occurs while flushing this writer. */
public abstract void flush () throws IOException;
/*** Writes the entire character buffer {@code buf} to the target.
*
* @param buf the non-null array containing characters to write.
* @throws IOException if this writer is closed or another I/O error occurs. */
public void write (char buf[]) throws IOException {
write(buf, 0, buf.length);
}
/*** Writes {@code count} characters starting at {@code offset} in {@code buf} to the target.
*
* @param buf the non-null character array to write.
* @param offset the index of the first character in {@code buf} to write.
* @param count the maximum number of characters to write.
* @throws IndexOutOfBoundsException if {@code offset < 0} or {@code count < 0}, or if {@code offset + count} is greater than
* the size of {@code buf}.
* @throws IOException if this writer is closed or another I/O error occurs. */
public abstract void write (char buf[], int offset, int count) throws IOException;
/*** Writes one character to the target. Only the two least significant bytes of the integer {@code oneChar} are written.
*
* @param oneChar the character to write to the target.
* @throws IOException if this writer is closed or another I/O error occurs. */
public void write (int oneChar) throws IOException {
synchronized (lock) {
char oneCharArray[] = new char[1];
oneCharArray[0] = (char)oneChar;
write(oneCharArray);
}
}
/*** Writes the characters from the specified string to the target.
*
* @param str the non-null string containing the characters to write.
* @throws IOException if this writer is closed or another I/O error occurs. */
public void write (String str) throws IOException {
write(str, 0, str.length());
}
/*** Writes {@code count} characters from {@code str} starting at {@code offset} to the target.
*
* @param str the non-null string containing the characters to write.
* @param offset the index of the first character in {@code str} to write.
* @param count the number of characters from {@code str} to write.
* @throws IOException if this writer is closed or another I/O error occurs.
* @throws IndexOutOfBoundsException if {@code offset < 0} or {@code count < 0}, or if {@code offset + count} is greater than
* the length of {@code str}. */
public void write (String str, int offset, int count) throws IOException {
if (count < 0) { // other cases tested by getChars()
throw new StringIndexOutOfBoundsException();
}
char buf[] = new char[count];
str.getChars(offset, offset + count, buf, 0);
synchronized (lock) {
write(buf, 0, buf.length);
}
}
/*** Appends the character {@code c} to the target. This method works the same way as {@link #write(int)}.
*
* @param c the character to append to the target stream.
* @return this writer.
* @throws IOException if this writer is closed or another I/O error occurs. */
public Writer append (char c) throws IOException {
write(c);
return this;
}
/*** Appends the character sequence {@code csq} to the target. This method works the same way as
* {@code Writer.write(csq.toString())}. If {@code csq} is {@code null}, then the string "null" is written to the target
* stream.
*
* @param csq the character sequence appended to the target.
* @return this writer.
* @throws IOException if this writer is closed or another I/O error occurs. */
public Writer append (CharSequence csq) throws IOException {
if (null == csq) {
write(TOKEN_NULL);
} else {
write(csq.toString());
}
return this;
}
/*** Appends a subsequence of the character sequence {@code csq} to the target. This method works the same way as
* {@code Writer.writer(csq.subsequence(start, end).toString())}. If {@code csq} is {@code null}, then the specified
* subsequence of the string "null" will be written to the target.
*
* @param csq the character sequence appended to the target.
* @param start the index of the first char in the character sequence appended to the target.
* @param end the index of the character following the last character of the subsequence appended to the target.
* @return this writer.
* @throws IOException if this writer is closed or another I/O error occurs.
* @throws IndexOutOfBoundsException if {@code start > end}, {@code start < 0}, {@code end < 0} or either {@code start} or
* {@code end} are greater or equal than the length of {@code csq}. */
public Writer append (CharSequence csq, int start, int end) throws IOException {
if (null == csq) {
write(TOKEN_NULL.substring(start, end));
} else {
write(csq.subSequence(start, end).toString());
}
return this;
}
/*** Returns true if this writer has encountered and suppressed an error. Used by PrintWriters as an alternative to checked
* exceptions. */
boolean checkError () {
return false;
}
}
================================================
FILE: src/peergos/gwt/emu/java/lang/AutoCloseable.java
================================================
package java.lang;
public interface AutoCloseable {
void close() throws Exception;
}
================================================
FILE: src/peergos/gwt/emu/java/lang/ClassLoader.java
================================================
package java.lang;
import java.io.InputStream;
import java.net.URL;
public class ClassLoader {
public static ClassLoader getSystemClassLoader() {
return null;
}
public InputStream getResourceAsStream(String name) {
return null;
}
public URL getResource(String name) {
return null;
}
}
================================================
FILE: src/peergos/gwt/emu/java/lang/ClassNotFoundException.java
================================================
/*
* @(#)ClassNotFoundException.java 1.20 04/02/19
*
* Copyright 2004 Sun Microsystems, Inc. All rights reserved.
* SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
*/
package java.lang;
/** Thrown when an application tries to load in a class through its string name using:
*
* but no definition for the class with the specified name could be found.
*
*
* As of release 1.4, this exception has been retrofitted to conform to the general purpose exception-chaining mechanism. The
* "optional exception that was raised while loading the class" that may be provided at construction time and accessed via the
* {@link #getException()} method is now known as the cause, and may be accessed via the {@link Throwable#getCause()}
* method, as well as the aforementioned "legacy method."
*
* @author unascribed
* @version 1.20, 02/19/04
* @see java.lang.Class#forName(java.lang.String)
* @see java.lang.ClassLoader#findSystemClass(java.lang.String)
* @see java.lang.ClassLoader#loadClass(java.lang.String, boolean)
* @since JDK1.0 */
public class ClassNotFoundException extends Exception {
/** use serialVersionUID from JDK 1.1.X for interoperability */
private static final long serialVersionUID = 9176873029745254542L;
/** This field holds the exception ex if the ClassNotFoundException(String s, Throwable ex) constructor was used to instantiate
* the object
* @serial
* @since 1.2 */
private Throwable ex;
/** Constructs a
* This method predates the general-purpose exception chaining facility. The {@link Throwable#getCause()} method is now the
* preferred means of obtaining this information.
*
* @return the
* All characters except letters ('a'..'z', 'A'..'Z') and numbers ('0'..'9')
* and characters '.', '-', '*', '_' are converted into their hexadecimal
* value prepended by '%'. For example: '#' -> %23. In addition, spaces are
* substituted by '+'
*
* @param s
* the string to be encoded.
* @return the encoded string.
* @deprecated use {@link #encode(String, String)} instead.
*/
@Deprecated
public static String encode(String s) {
// Guess a bit bigger for encoded form
StringBuilder buf = new StringBuilder(s.length() + 16);
for (int i = 0; i < s.length(); i++) {
char ch = s.charAt(i);
if ((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z')
|| (ch >= '0' && ch <= '9') || ".-*_".indexOf(ch) > -1) {
buf.append(ch);
} else if (ch == ' ') {
buf.append('+');
} else {
byte[] bytes = new String(new char[] { ch }).getBytes();
for (int j = 0; j < bytes.length; j++) {
buf.append('%');
buf.append(digits.charAt((bytes[j] & 0xf0) >> 4));
buf.append(digits.charAt(bytes[j] & 0xf));
}
}
}
return buf.toString();
}
/**
* Encodes the given string {@code s} in a x-www-form-urlencoded string
* using the specified encoding scheme {@code enc}.
*
* All characters except letters ('a'..'z', 'A'..'Z') and numbers ('0'..'9')
* and characters '.', '-', '*', '_' are converted into their hexadecimal
* value prepended by '%'. For example: '#' -> %23. In addition, spaces are
* substituted by '+'
*
* @param s
* the string to be encoded.
* @param enc
* the encoding scheme to be used.
* @return the encoded string.
* @throws UnsupportedEncodingException
* if the specified encoding scheme is invalid.
*/
public static String encode(String s, String enc) throws UnsupportedEncodingException {
if (s == null || enc == null) {
throw new NullPointerException();
}
// check for UnsupportedEncodingException
"".getBytes(enc);
// Guess a bit bigger for encoded form
StringBuilder buf = new StringBuilder(s.length() + 16);
int start = -1;
for (int i = 0; i < s.length(); i++) {
char ch = s.charAt(i);
if ((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z')
|| (ch >= '0' && ch <= '9') || " .-*_".indexOf(ch) > -1) {
if (start >= 0) {
convert(s.substring(start, i), buf, enc);
start = -1;
}
if (ch != ' ') {
buf.append(ch);
} else {
buf.append('+');
}
} else {
if (start < 0) {
start = i;
}
}
}
if (start >= 0) {
convert(s.substring(start, s.length()), buf, enc);
}
return buf.toString();
}
private static void convert(String s, StringBuilder buf, String enc)
throws UnsupportedEncodingException {
byte[] bytes = s.getBytes(enc);
for (int j = 0; j < bytes.length; j++) {
buf.append('%');
buf.append(digits.charAt((bytes[j] & 0xf0) >> 4));
buf.append(digits.charAt(bytes[j] & 0xf));
}
}
}
================================================
FILE: src/peergos/gwt/emu/java/net/UnknownHostException.java
================================================
package java.net;
import java.io.IOException;
public class UnknownHostException extends IOException{
public UnknownHostException() {
}
public UnknownHostException(String msg) {
super(msg);
}
}
================================================
FILE: src/peergos/gwt/emu/java/nio/Buffer.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 java.nio;
/** A buffer is a list of elements of a specific primitive type.
*
* A buffer can be described by the following properties:
*
* Buffers are not thread-safe. If concurrent access to a buffer instance is required, then the callers are responsible to take
* care of the synchronization issues.
*
* While the content of this buffer is not changed, the following internal changes take place: the current position is reset
* back to the start of the buffer, the value of the buffer limit is made equal to the capacity and mark is cleared.
*
* The limit is set to the current position, then the position is set to zero, and the mark is cleared.
*
* The content of this buffer is not changed.
*
* If the current position in the buffer is in excess of
* If the mark is set and it is greater than the new position, then it is cleared.
*
* The position is set to zero, and the mark is cleared. The content of this buffer is not changed.
*
* A char buffer can be created in either one of the following ways:
*
* Calling this method has the same effect as {@code put(src, 0, src.length)}.
*
* The specification for Adler32 may be found in RFC 1950.
* (ZLIB Compressed Data Format Specification version 3.3)
*
*
* From that document:
*
* "ADLER32 (Adler-32 checksum)
* This contains a checksum value of the uncompressed data
* (excluding any dictionary data) computed according to Adler-32
* algorithm. This algorithm is a 32-bit extension and improvement
* of the Fletcher algorithm, used in the ITU-T X.224 / ISO 8073
* standard.
*
* Adler-32 is composed of two sums accumulated per byte: s1 is
* the sum of all bytes, s2 is the sum of all s1 values. Both sums
* are done modulo 65521. s1 is initialized to 1, s2 to zero. The
* Adler-32 checksum is stored as s2*65536 + s1 in most-
* significant-byte first (network) order."
*
* "8.2. The Adler-32 algorithm
*
* The Adler-32 algorithm is much faster than the CRC32 algorithm yet
* still provides an extremely low probability of undetected errors.
*
* The modulo on unsigned long accumulators can be delayed for 5552
* bytes, so the modulo operation time is negligible. If the bytes
* are a, b, c, the second sum is 3a + 2b + c + 3, and so is position
* and order sensitive, unlike the first sum, which is just a
* checksum. That 65521 is prime is important to avoid a possible
* large class of two-byte errors that leave the check unchanged.
* (The Fletcher checksum uses 255, which is not prime and which also
* makes the Fletcher check insensitive to single byte changes 0 <->
* 255.)
*
* The sum s1 is initialized to 1 instead of zero to make the length
* of the sequence part of s2, so that the length does not have to be
* checked separately. (Any sequence of zeroes has a Fletcher
* checksum of zero.)"
*
* @author John Leuner, Per Bothner
* @since JDK 1.1
*
* @see InflaterInputStream
* @see DeflaterOutputStream
*/
public class Adler32 implements Checksum
{
/** largest prime smaller than 65536 */
private static final int BASE = 65521;
private int checksum; //we do all in int.
//Note that java doesn't have unsigned integers,
//so we have to be careful with what arithmetic
//we do. We return the checksum as a long to
//avoid sign confusion.
/**
* Creates a new instance of the
* Author: Christian d'Heureuse, Inventec Informatik AG, Zurich, Switzerland
* Multi-licensed: EPL / LGPL / GPL / AL / BSD.
*
* @author Christian d'Heureuse
* @author vaxquis
*/
package com.badlogic.gdx.utils;
public class Base64Coder {
public static class CharMap {
protected final char[] encodingMap = new char[64];
protected final byte[] decodingMap = new byte[128];
public CharMap (char char63, char char64) {
int i = 0;
for (char c = 'A'; c <= 'Z'; c++) {
encodingMap[i++] = c;
}
for (char c = 'a'; c <= 'z'; c++) {
encodingMap[i++] = c;
}
for (char c = '0'; c <= '9'; c++) {
encodingMap[i++] = c;
}
encodingMap[i++] = char63;
encodingMap[i++] = char64;
for (i = 0; i < decodingMap.length; i++) {
decodingMap[i] = -1;
}
for (i = 0; i < 64; i++) {
decodingMap[encodingMap[i]] = (byte)i;
}
}
public byte[] getDecodingMap () {
return decodingMap;
}
public char[] getEncodingMap () {
return encodingMap;
}
}
// The line separator string of the operating system.
private static final String systemLineSeparator = "\n";
public static final CharMap regularMap = new CharMap('+', '/'), urlsafeMap = new CharMap('-', '_');
/** Encodes a string into Base64 format. No blanks or line breaks are inserted.
* @param s A String to be encoded.
* @return A String containing the Base64 encoded data. */
public static String encodeString (String s) {
return encodeString(s, false);
}
public static String encodeString (String s, boolean useUrlsafeEncoding) {
return new String(encode(s.getBytes(), useUrlsafeEncoding ? urlsafeMap.encodingMap : regularMap.encodingMap));
}
/** Encodes a byte array into Base 64 format and breaks the output into lines of 76 characters. This method is compatible with
* sun.misc.BASE64Encoder.encodeBuffer(byte[]).
* @param in An array containing the data bytes to be encoded.
* @return A String containing the Base64 encoded data, broken into lines. */
public static String encodeLines (byte[] in) {
return encodeLines(in, 0, in.length, 76, systemLineSeparator, regularMap.encodingMap);
}
public static String encodeLines (byte[] in, int iOff, int iLen, int lineLen, String lineSeparator, CharMap charMap) {
return encodeLines(in, iOff, iLen, lineLen, lineSeparator, charMap.encodingMap);
}
/** Encodes a byte array into Base 64 format and breaks the output into lines.
* @param in An array containing the data bytes to be encoded.
* @param iOff Offset of the first byte in in to be processed.
* @param iLen Number of bytes to be processed in in, starting at iOff.
* @param lineLen Line length for the output data. Should be a multiple of 4.
* @param lineSeparator The line separator to be used to separate the output lines.
* @param charMap char map to use
* @return A String containing the Base64 encoded data, broken into lines. */
public static String encodeLines (byte[] in, int iOff, int iLen, int lineLen, String lineSeparator, char[] charMap) {
int blockLen = (lineLen * 3) / 4;
if (blockLen <= 0) {
throw new IllegalArgumentException();
}
int lines = (iLen + blockLen - 1) / blockLen;
int bufLen = ((iLen + 2) / 3) * 4 + lines * lineSeparator.length();
StringBuilder buf = new StringBuilder(bufLen);
int ip = 0;
while (ip < iLen) {
int l = Math.min(iLen - ip, blockLen);
buf.append(encode(in, iOff + ip, l, charMap));
buf.append(lineSeparator);
ip += l;
}
return buf.toString();
}
/** Encodes a byte array into Base64 format. No blanks or line breaks are inserted in the output.
* @param in An array containing the data bytes to be encoded.
* @return A character array containing the Base64 encoded data. */
public static char[] encode (byte[] in) {
return encode(in, regularMap.encodingMap);
}
public static char[] encode (byte[] in, CharMap charMap) {
return encode(in, 0, in.length, charMap);
}
public static char[] encode (byte[] in, char[] charMap) {
return encode(in, 0, in.length, charMap);
}
/** Encodes a byte array into Base64 format. No blanks or line breaks are inserted in the output.
* @param in An array containing the data bytes to be encoded.
* @param iLen Number of bytes to process in in.
* @return A character array containing the Base64 encoded data. */
public static char[] encode (byte[] in, int iLen) {
return encode(in, 0, iLen, regularMap.encodingMap);
}
public static char[] encode (byte[] in, int iOff, int iLen, CharMap charMap) {
return encode(in, iOff, iLen, charMap.encodingMap);
}
/** Encodes a byte array into Base64 format. No blanks or line breaks are inserted in the output.
* @param in An array containing the data bytes to be encoded.
* @param iOff Offset of the first byte in in to be processed.
* @param iLen Number of bytes to process in in, starting at iOff.
* @param charMap char map to use
* @return A character array containing the Base64 encoded data. */
public static char[] encode (byte[] in, int iOff, int iLen, char[] charMap) {
int oDataLen = (iLen * 4 + 2) / 3; // output length without padding
int oLen = ((iLen + 2) / 3) * 4; // output length including padding
char[] out = new char[oLen];
int ip = iOff;
int iEnd = iOff + iLen;
int op = 0;
while (ip < iEnd) {
int i0 = in[ip++] & 0xff;
int i1 = ip < iEnd ? in[ip++] & 0xff : 0;
int i2 = ip < iEnd ? in[ip++] & 0xff : 0;
int o0 = i0 >>> 2;
int o1 = ((i0 & 3) << 4) | (i1 >>> 4);
int o2 = ((i1 & 0xf) << 2) | (i2 >>> 6);
int o3 = i2 & 0x3F;
out[op++] = charMap[o0];
out[op++] = charMap[o1];
out[op] = op < oDataLen ? charMap[o2] : '=';
op++;
out[op] = op < oDataLen ? charMap[o3] : '=';
op++;
}
return out;
}
/** Decodes a string from Base64 format. No blanks or line breaks are allowed within the Base64 encoded input data.
* @param s A Base64 String to be decoded.
* @return A String containing the decoded data.
* @throws IllegalArgumentException If the input is not valid Base64 encoded data. */
public static String decodeString (String s) {
return decodeString(s, false);
}
public static String decodeString (String s, boolean useUrlSafeEncoding) {
return new String(decode(s.toCharArray(), useUrlSafeEncoding ? urlsafeMap.decodingMap : regularMap.decodingMap));
}
public static byte[] decodeLines (String s) {
return decodeLines(s, regularMap.decodingMap);
}
public static byte[] decodeLines (String s, CharMap inverseCharMap) {
return decodeLines(s, inverseCharMap.decodingMap);
}
/** Decodes a byte array from Base64 format and ignores line separators, tabs and blanks. CR, LF, Tab and Space characters are
* ignored in the input data. This method is compatible with sun.misc.BASE64Decoder.decodeBuffer(String).
* @param s A Base64 String to be decoded.
* @param inverseCharMap
* @return An array containing the decoded data bytes.
* @throws IllegalArgumentException If the input is not valid Base64 encoded data. */
public static byte[] decodeLines (String s, byte[] inverseCharMap) {
char[] buf = new char[s.length()];
int p = 0;
for (int ip = 0; ip < s.length(); ip++) {
char c = s.charAt(ip);
if (c != ' ' && c != '\r' && c != '\n' && c != '\t') {
buf[p++] = c;
}
}
return decode(buf, 0, p, inverseCharMap);
}
/** Decodes a byte array from Base64 format. No blanks or line breaks are allowed within the Base64 encoded input data.
* @param s A Base64 String to be decoded.
* @return An array containing the decoded data bytes.
* @throws IllegalArgumentException If the input is not valid Base64 encoded data. */
public static byte[] decode (String s) {
return decode(s.toCharArray());
}
/** Decodes a byte array from Base64 format. No blanks or line breaks are allowed within the Base64 encoded input data.
* @param s A Base64 String to be decoded.
* @param inverseCharMap
* @return An array containing the decoded data bytes.
* @throws IllegalArgumentException If the input is not valid Base64 encoded data. */
public static byte[] decode (String s, CharMap inverseCharMap) {
return decode(s.toCharArray(), inverseCharMap);
}
public static byte[] decode (char[] in, byte[] inverseCharMap) {
return decode(in, 0, in.length, inverseCharMap);
}
public static byte[] decode (char[] in, CharMap inverseCharMap) {
return decode(in, 0, in.length, inverseCharMap);
}
/** Decodes a byte array from Base64 format. No blanks or line breaks are allowed within the Base64 encoded input data.
* @param in A character array containing the Base64 encoded data.
* @return An array containing the decoded data bytes.
* @throws IllegalArgumentException If the input is not valid Base64 encoded data. */
public static byte[] decode (char[] in) {
return decode(in, 0, in.length, regularMap.decodingMap);
}
public static byte[] decode (char[] in, int iOff, int iLen, CharMap inverseCharMap) {
return decode(in, iOff, iLen, inverseCharMap.decodingMap);
}
/** Decodes a byte array from Base64 format. No blanks or line breaks are allowed within the Base64 encoded input data.
* @param in A character array containing the Base64 encoded data.
* @param iOff Offset of the first character in in to be processed.
* @param iLen Number of characters to process in in, starting at iOff.
* @param inverseCharMap charMap to use
* @return An array containing the decoded data bytes.
* @throws IllegalArgumentException If the input is not valid Base64 encoded data. */
public static byte[] decode (char[] in, int iOff, int iLen, byte[] inverseCharMap) {
if (iLen % 4 != 0) {
throw new IllegalArgumentException("Length of Base64 encoded input string is not a multiple of 4.");
}
while (iLen > 0 && in[iOff + iLen - 1] == '=') {
iLen--;
}
int oLen = (iLen * 3) / 4;
byte[] out = new byte[oLen];
int ip = iOff;
int iEnd = iOff + iLen;
int op = 0;
while (ip < iEnd) {
int i0 = in[ip++];
int i1 = in[ip++];
int i2 = ip < iEnd ? in[ip++] : 'A';
int i3 = ip < iEnd ? in[ip++] : 'A';
if (i0 > 127 || i1 > 127 || i2 > 127 || i3 > 127) {
throw new IllegalArgumentException("Illegal character in Base64 encoded data.");
}
int b0 = inverseCharMap[i0];
int b1 = inverseCharMap[i1];
int b2 = inverseCharMap[i2];
int b3 = inverseCharMap[i3];
if (b0 < 0 || b1 < 0 || b2 < 0 || b3 < 0) {
throw new IllegalArgumentException("Illegal character in Base64 encoded data.");
}
int o0 = (b0 << 2) | (b1 >>> 4);
int o1 = ((b1 & 0xf) << 4) | (b2 >>> 2);
int o2 = ((b2 & 3) << 6) | b3;
out[op++] = (byte)o0;
if (op < oLen) {
out[op++] = (byte)o1;
}
if (op < oLen) {
out[op++] = (byte)o2;
}
}
return out;
}
// Dummy constructor.
private Base64Coder () {
}
}
================================================
FILE: src/peergos/gwt/emu/com/badlogic/gdx/utils/Utf8Decoder.java
================================================
/*******************************************************************************
* Copyright 2015 See AUTHORS file.
*
* 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.
******************************************************************************/
/*******************************************************************************
* Copyright (c) 2008-2009 Bjoern Hoehrmann FilterInputStream provides the ability to
* unread data from a stream. It maintains an internal buffer of unread
* data that is supplied to the next read operation. This is conceptually
* similar to mark/reset functionality, except that in this case the
* position to reset the stream to does not need to be known in advance.
* buf[buf.length - 1] to buf[0]. Thus when
* pos is 0 the buffer is full and buf.length when
* it is empty
*/
protected int pos;
/**
* This method initializes a PushbackInputStream to
* read from the specified subordinate InputStream
* with a default pushback buffer size of 1.
*
* @param in The subordinate stream to read from
*/
public PushbackInputStream(InputStream in)
{
this(in, DEFAULT_BUFFER_SIZE);
}
/**
* This method initializes a PushbackInputStream to
* read from the specified subordinate InputStream with
* the specified buffer size
*
* @param in The subordinate InputStream to read from
* @param size The pushback buffer size to use
*/
public PushbackInputStream(InputStream in, int size)
{
super(in);
if (size < 0)
throw new IllegalArgumentException();
buf = new byte[size];
pos = buf.length;
}
/**
* This method returns the number of bytes that can be read from this
* stream before a read can block. A return of 0 indicates that blocking
* might (or might not) occur on the very next read attempt.
* false to indicate that it does
* not support mark/reset functionality.
*
* @return This method returns false to indicate that
* this class does not support mark/reset functionality
*/
public boolean markSupported()
{
return false;
}
/**
* This method always throws an IOException in this class because
* mark/reset functionality is not supported.
*
* @exception IOException Always thrown for this class
*/
public void reset() throws IOException
{
throw new IOException("Mark not supported in this class");
}
/**
* This method reads an unsigned byte from the input stream and returns it
* as an int in the range of 0-255. This method also will return -1 if
* the end of the stream has been reached. The byte returned will be read
* from the pushback buffer, unless the buffer is empty, in which case
* the byte will be read from the underlying stream.
* offset into the buffer and attempts to read
* len bytes. This method can return before reading the
* number of bytes requested. The actual number of bytes read is
* returned as an int. A -1 is returned to indicate the end of the
* stream.
* int. Only the low
* eight bits of this value are pushed back.
*
* @param b The byte to be pushed back, passed as an int
*
* @exception IOException If the pushback buffer is full.
*/
public synchronized void unread(int b) throws IOException
{
if (pos <= 0)
throw new IOException("Insufficient space in pushback buffer");
buf[--pos] = (byte) b;
}
/**
* This method pushes all of the bytes in the passed byte array into
* the pushback bfer. These bytes are pushed in reverse order so that
* the next byte read from the stream after this operation will be
* b[0] followed by b[1], etc.
* b[offset] to
* b[offset + len] are pushed in reverse order so that
* the next byte read from the stream after this operation will be
* b[offset] followed by b[offset + 1],
* etc.
* skip method on the underlying InputStream to
* skip additional bytes if necessary.
*
* @param n The requested number of bytes to skip
*
* @return The actual number of bytes skipped.
*
* @exception IOException If an error occurs
*
* @since 1.2
*/
public synchronized long skip(long n) throws IOException
{
final long origN = n;
if (n > 0L)
{
int numread = (int) Math.min((long) (buf.length - pos), n);
pos += numread;
n -= numread;
if (n > 0)
n -= super.skip(n);
}
return origN - n;
}
}
================================================
FILE: src/peergos/gwt/emu/java/io/RandomAccessFile.java
================================================
/*
* Copyright 2010 Google Inc.
*
* 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 java.io;
/** Saves binary data to the local storage; currently using hex encoding. The string is prefixed with "hex:"
* @author haustein */
public class RandomAccessFile implements Closeable/* implements DataOutput, DataInput, Closeable */{
public RandomAccessFile (File file, String mode) throws FileNotFoundException {
throw new Error("Not implemented");
}
@Override
public void close() throws IOException {
}
public long length () throws IOException {
return -1;
}
public int read () throws IOException {
return -1;
}
public int read (byte b[]) throws IOException {
return -1;
}
public int read (byte b[], int offset, int len) throws IOException {
return -1;
}
public void seek (long pos) throws IOException {
}
public void setLength (long newLength) throws IOException {
}
public void write (byte b[]) throws IOException {
}
}
================================================
FILE: src/peergos/gwt/emu/java/io/Reader.java
================================================
/*
* Copyright 2018 Google Inc.
*
* 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 java.io;
/**
* Reads a stream of characters.
*/
public abstract class Reader {
/**
* The maximum buffer size to incrementally read in {@link #skip}.
*/
private static final int MAX_SKIP_BUFFER_SIZE = 1024;
/**
* Closes the reader, and releases any associated resources.
*/
public abstract void close() throws IOException;
/**
* Marks the present position in the stream. Until {@code readAheadLimit} more
* characters have been read, the current point in the stream will be stored
* as the mark. Calls to {@link #reset} will reposition the point in the
* stream to the mark.
*
* @throws IOException If the stream does not support mark().
*/
public void mark(int readAheadLimit) throws IOException {
throw new IOException("Not supported");
}
/**
* Returns whether {@link #mark} is implemented.
*/
public boolean markSupported() {
return false;
}
/**
* Reads a single character, or -1 if we are at the end of the stream.
*/
public int read() throws IOException {
char chr[] = new char[1];
return (read(chr) == -1) ? -1 : chr[0];
}
/**
* Attempts to fill {@code buf} with characters up to the size of the array.
*/
public int read(char[] buf) throws IOException {
return read(buf, 0, buf.length);
}
/**
* Attempts to fill {@code buf} with up to {@code len} characters. Characters
* will be stored in {@code buf} starting at index {@code off}.
*/
public abstract int read(char[] buf, int off, int len) throws IOException;
/**
* Returns whether the stream is ready for reading characters.
*/
public boolean ready() throws IOException {
return false;
}
/**
* Attempts to reset the stream to the previous mark.
*/
public void reset() throws IOException {
throw new IOException("Not supported");
}
/**
* Skips {@code n} characters, returning the number of characters that were actually skipped.
*/
public long skip(long n) throws IOException {
long remaining = n;
int bufferSize = Math.min((int) n, MAX_SKIP_BUFFER_SIZE);
char[] skipBuffer = new char[bufferSize];
while (remaining > 0) {
long numRead = read(skipBuffer, 0, (int) remaining);
if (numRead < 0) {
break;
}
remaining -= numRead;
}
return n - remaining;
}
}
================================================
FILE: src/peergos/gwt/emu/java/io/UTFDataFormatException.java
================================================
/*
* Copyright 2010 Google Inc.
*
* 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 java.io;
public class UTFDataFormatException extends IOException {
public UTFDataFormatException (String msg) {
super(msg);
}
public UTFDataFormatException () {
super();
}
}
================================================
FILE: src/peergos/gwt/emu/java/io/UnsupportedEncodingException.java
================================================
/*
* Copyright 2010 Google Inc.
*
* 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 java.io;
public class UnsupportedEncodingException extends IOException {
public UnsupportedEncodingException () {
super();
}
public UnsupportedEncodingException (String s) {
super(s);
}
}
================================================
FILE: src/peergos/gwt/emu/java/io/Writer.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 java.io;
/*** The base class for all writers. A writer is a means of writing data to a target in a character-wise manner. Most output streams
* expect the {@link #flush()} method to be called before closing the stream, to ensure all data is actually written out.
*
*
* forName method in class Class.
* findSystemClass method in class ClassLoader .
* loadClass method in class ClassLoader.
* ClassNotFoundException with no detail message. */
public ClassNotFoundException () {
super((Throwable)null); // Disallow initCause
}
/** Constructs a ClassNotFoundException with the specified detail message.
*
* @param s the detail message. */
public ClassNotFoundException (String s) {
super(s, null); // Disallow initCause
}
/** Constructs a ClassNotFoundException with the specified detail message and optional exception that was raised
* while loading the class.
*
* @param s the detail message
* @param ex the exception that was raised while loading the class
* @since 1.2 */
public ClassNotFoundException (String s, Throwable ex) {
super(s, null); // Disallow initCause
this.ex = ex;
}
/** Returns the exception that was raised if an error occurred while attempting to load the class. Otherwise, returns
* null.
*
* Exception that was raised while loading a class
* @since 1.2 */
public Throwable getException () {
return ex;
}
/** Returns the cause of this exception (the exception that was raised if an error occurred while attempting to load the class;
* otherwise null).
*
* @return the cause of this exception.
* @since 1.4 */
public Throwable getCause () {
return ex;
}
}
================================================
FILE: src/peergos/gwt/emu/java/lang/Exception.java
================================================
/*
* Copyright 2007 Google Inc.
*
* 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 java.lang;
/**
* See the
* official Java API doc for details.
*/
public class Exception extends Throwable {
public Exception() {
}
public Exception(String message) {
super(message);
}
public Exception(String message, Throwable cause) {
super(message, cause);
}
public Exception(Throwable cause) {
super(cause);
}
protected Exception(String message, Throwable cause, boolean enableSuppression,
boolean writableStackTrace) {
super(message, cause, enableSuppression, writableStackTrace);
}
Exception(Object backingJsObject) {
super(backingJsObject);
}
}
================================================
FILE: src/peergos/gwt/emu/java/lang/InternalError.java
================================================
/*
* Copyright (c) 1994, 2008, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package java.lang;
/**
* Thrown to indicate some unexpected internal error has occurred in
* the Java Virtual Machine.
*
* @author unascribed
* @since JDK1.0
*/
public class InternalError extends Error {
private static final long serialVersionUID = -9062593416125562365L;
/**
* Constructs an InternalError with no detail message.
*/
public InternalError() {
super();
}
/**
* Constructs an InternalError with the specified
* detail message.
*
* @param s the detail message.
*/
public InternalError(String s) {
super(s);
}
}
================================================
FILE: src/peergos/gwt/emu/java/lang/InterruptedException.java
================================================
/* Copyright (c) 2008, Avian Contributors
Permission to use, copy, modify, and/or distribute this software
for any purpose with or without fee is hereby granted, provided
that the above copyright notice and this permission notice appear
in all copies.
There is NO WARRANTY for this software. See license.txt for
details. */
package java.lang;
public class InterruptedException extends Exception {
public InterruptedException (String message, Throwable cause) {
super(message, cause);
}
public InterruptedException (String message) {
this(message, null);
}
public InterruptedException (Throwable cause) {
this(null, cause);
}
public InterruptedException () {
this(null, null);
}
}
================================================
FILE: src/peergos/gwt/emu/java/lang/OutOfMemoryError.java
================================================
package java.lang;
public class OutOfMemoryError extends Error {
public OutOfMemoryError() {}
public OutOfMemoryError(String msg) {
super(msg);
}
}
================================================
FILE: src/peergos/gwt/emu/java/lang/Readable.java
================================================
/*******************************************************************************
* Copyright 2011 See AUTHORS file.
*
* 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 java.lang;
import java.io.IOException;
import java.nio.CharBuffer;
public interface Readable {
int read (CharBuffer cb) throws IOException;
}
================================================
FILE: src/peergos/gwt/emu/java/lang/Runnable.java
================================================
package java.lang;
import jsinterop.annotations.*;
@FunctionalInterface
public interface Runnable {
@JsMethod
void run();
}
================================================
FILE: src/peergos/gwt/emu/java/lang/RuntimeException.java
================================================
/*
* Copyright 2007 Google Inc.
*
* 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 java.lang;
/**
* See the
* official Java API doc for details.
*/
public class RuntimeException extends Exception {
public RuntimeException() {
}
public RuntimeException(String message) {
super(message);
}
public RuntimeException(String message, Throwable cause) {
super(message, cause);
}
public RuntimeException(Throwable cause) {
super(cause);
}
protected RuntimeException(String message, Throwable cause, boolean enableSuppression,
boolean writableStackTrace) {
super(message, cause, enableSuppression, writableStackTrace);
}
RuntimeException(Object backingJsObject) {
super(backingJsObject);
}
}
================================================
FILE: src/peergos/gwt/emu/java/lang/SecurityException.java
================================================
/* Copyright (c) 2008, Avian Contributors
Permission to use, copy, modify, and/or distribute this software
for any purpose with or without fee is hereby granted, provided
that the above copyright notice and this permission notice appear
in all copies.
There is NO WARRANTY for this software. See license.txt for
details. */
package java.lang;
public class SecurityException extends RuntimeException {
public SecurityException (String message, Throwable cause) {
super(message, cause);
}
public SecurityException (String message) {
this(message, null);
}
public SecurityException (Throwable cause) {
this(null, cause);
}
public SecurityException () {
this(null, null);
}
}
================================================
FILE: src/peergos/gwt/emu/java/lang/Thread.java
================================================
/*******************************************************************************
* Copyright 2011 See AUTHORS file.
*
* 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 java.lang;
import com.google.gwt.core.client.GWT;
public class Thread {
public Thread() {
}
public Thread(Runnable runnable) {
}
public static Thread currentThread() {
return null;
}
public synchronized void start() {
}
public ClassLoader getContextClassLoader() {
return null;
}
public static void sleep (long millis) throws InterruptedException {
// noop emu
}
public static void setDefaultUncaughtExceptionHandler(final Thread.UncaughtExceptionHandler javaHandler) {
GWT.setUncaughtExceptionHandler(new GWT.UncaughtExceptionHandler() {
@Override
public void onUncaughtException (Throwable e) {
final Thread th = new Thread() {
@Override
public String toString() {
return "The only thread";
}
};
javaHandler.uncaughtException(th, e);
}
});
}
public static interface UncaughtExceptionHandler {
void uncaughtException(Thread t, Throwable e);
}
}
================================================
FILE: src/peergos/gwt/emu/java/net/ConnectException.java
================================================
package java.net;
import jsinterop.annotations.*;
public class ConnectException extends SocketException {
public ConnectException() {
this("");
}
@JsConstructor
public ConnectException(String msg) {
super(msg);
}
}
================================================
FILE: src/peergos/gwt/emu/java/net/HttpURLConnection.java
================================================
package java.net;
public class HttpURLConnection extends URLConnection{
public static final int HTTP_OK = 200;
public static final int HTTP_NO_CONTENT = 204;
public void setRequestMethod(String method) throws ProtocolException {
}
public void setRequestProperty(String key, String value) {
}
public void setUseCaches(boolean b) {
}
public void setDoInput(boolean b) {
}
public void setConnectTimeout(int timeout) {}
public void setReadTimeout(int timeout) {}
public int getResponseCode() {
return HTTP_OK;
}
public int getContentLength() {
return -1;
}
public void connect() {
}
public void disconnect() {
}
public String getHeaderField(String name) {
return null;
}
public String getResponseMessage() {
return null;
}
}
================================================
FILE: src/peergos/gwt/emu/java/net/Inet4Address.java
================================================
package java.net;
public class Inet4Address extends InetAddress{
}
================================================
FILE: src/peergos/gwt/emu/java/net/Inet6Address.java
================================================
package java.net;
public class Inet6Address extends InetAddress{
}
================================================
FILE: src/peergos/gwt/emu/java/net/InetAddress.java
================================================
package java.net;
public class InetAddress {
public static InetAddress getByName(String host)
throws UnknownHostException {
return null;
}
public byte[] getAddress() {
return null;
}
public static InetAddress getByAddress(byte[] addr)
throws UnknownHostException {
return null;
}
public static InetAddress getLocalHost() throws UnknownHostException {
return null;
}
}
================================================
FILE: src/peergos/gwt/emu/java/net/MalformedURLException.java
================================================
package java.net;
import java.io.IOException;
public class MalformedURLException extends IOException {
public MalformedURLException() {
}
public MalformedURLException(String msg) {
super(msg);
}
}
================================================
FILE: src/peergos/gwt/emu/java/net/ProtocolException.java
================================================
package java.net;
import java.io.IOException;
public class ProtocolException extends IOException{
public ProtocolException() {
}
public ProtocolException(String msg) {
super(msg);
}
}
================================================
FILE: src/peergos/gwt/emu/java/net/Proxy.java
================================================
package java.net;
public class Proxy {
public enum Type {DIRECT, HTTP, SOCKS}
public Proxy(Type type, SocketAddress addr) {}
}
================================================
FILE: src/peergos/gwt/emu/java/net/SocketAddress.java
================================================
package java.net;
public class SocketAddress {
}
================================================
FILE: src/peergos/gwt/emu/java/net/SocketException.java
================================================
package java.net;
import java.io.IOException;
public class SocketException extends IOException{
public SocketException() {
}
public SocketException(String msg) {
super(msg);
}
}
================================================
FILE: src/peergos/gwt/emu/java/net/SocketTimeoutException.java
================================================
package java.net;
import java.io.*;
public class SocketTimeoutException extends IOException {
}
================================================
FILE: src/peergos/gwt/emu/java/net/URL.java
================================================
package java.net;
import java.io.InputStream;
public class URL {
public URL(String protocol, String host, int port, String file) throws MalformedURLException
{
}
public URL(String url) throws MalformedURLException
{
}
public URL(URL context, String spec) throws MalformedURLException {
}
public URLConnection openConnection() throws java.io.IOException {
return null;
}
public URLConnection openConnection(Proxy proxy) throws java.io.IOException {
return null;
}
public final InputStream openStream() throws java.io.IOException {
return null;
}
public String getPath() {
return null;
}
}
================================================
FILE: src/peergos/gwt/emu/java/net/URLConnection.java
================================================
package java.net;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Collections;
import java.util.List;
import java.util.Map;
public class URLConnection {
public InputStream getInputStream() throws IOException {
return null;
}
public OutputStream getOutputStream() throws IOException {
return null;
}
public InputStream getErrorStream() throws IOException {
return null;
}
public Map
*
* limit - 1. Accessing elements out of the scope will cause an exception. Limit may not be negative and not greater
* than capacity.ReadOnlyBufferException, while changing the position, limit and mark of a read-only buffer is OK.UNSET_MARK means the mark has not been set. */
final static int UNSET_MARK = -1;
/** The capacity of this buffer, which never change. */
final int capacity;
/** limit - 1 is the last element that can be read or written. Limit must be no less than zero and no greater than
* capacity. */
int limit;
/** Mark is where position will be set when reset() is called. Mark is not set by default. Mark is always no less
* than zero and no greater than position. */
int mark = UNSET_MARK;
/** The current position of this buffer. Position is always no less than zero and no greater than limit. */
int position = 0;
/** Construct a buffer with the specified capacity.
*
* @param capacity the capacity of this buffer. */
Buffer (int capacity) {
super();
if (capacity < 0) {
throw new IllegalArgumentException();
}
this.capacity = this.limit = capacity;
}
/** Returns the capacity of this buffer.
*
* @return the number of elements that are contained in this buffer.
* @since Android 1.0 */
public final int capacity () {
return capacity;
}
/** Clears this buffer.
* newLimit then, on returning from this call, it will have
* been adjusted to be equivalent to newLimit. If the mark is set and is greater than the new limit, then it is
* cleared.
* newLimit is invalid.
* @since Android 1.0 */
public final Buffer limit (int newLimit) {
if (newLimit < 0 || newLimit > capacity) {
throw new IllegalArgumentException();
}
limit = newLimit;
if (position > newLimit) {
position = newLimit;
}
if ((mark != UNSET_MARK) && (mark > newLimit)) {
mark = UNSET_MARK;
}
return this;
}
/** Marks the current position, so that the position may return to this point later by calling reset().
*
* @return this buffer.
* @since Android 1.0 */
public final Buffer mark () {
mark = position;
return this;
}
/** Returns the position of this buffer.
*
* @return the value of this buffer's current position.
* @since Android 1.0 */
public final int position () {
return position;
}
/** Sets the position of this buffer.
* newPosition is invalid.
* @since Android 1.0 */
public final Buffer position (int newPosition) {
if (newPosition < 0 || newPosition > limit) {
throw new IllegalArgumentException();
}
position = newPosition;
if ((mark != UNSET_MARK) && (mark > position)) {
mark = UNSET_MARK;
}
return this;
}
/** Returns the number of remaining elements in this buffer, that is {@code limit - position}.
*
* @return the number of remaining elements in this buffer.
* @since Android 1.0 */
public final int remaining () {
return limit - position;
}
/** Resets the position of this buffer to the mark.
*
* @return this buffer.
* @exception InvalidMarkException if the mark is not set.
* @since Android 1.0 */
public final Buffer reset () {
if (mark == UNSET_MARK) {
throw new InvalidMarkException();
}
position = mark;
return this;
}
/** Rewinds this buffer.
* BufferOverflowException is thrown when elements are written to a buffer but there is not enough remaining space
* in the buffer.
*
* @since Android 1.0 */
public class BufferOverflowException extends RuntimeException {
private static final long serialVersionUID = -5484897634319144535L;
/** Constructs a BufferOverflowException.
*
* @since Android 1.0 */
public BufferOverflowException () {
super();
}
}
================================================
FILE: src/peergos/gwt/emu/java/nio/CharBuffer.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 java.nio;
/** A buffer of chars.
*
*
*
* @since Android 1.0 */
public abstract class CharBuffer extends Buffer implements ComparableAdler32 class.
* The checksum starts off with a value of 1.
*/
public Adler32 ()
{
reset();
}
/**
* Resets the Adler32 checksum to the initial value.
*/
public void reset ()
{
checksum = 1; //Initialize to 1
}
/**
* Updates the checksum with the byte b.
*
* @param bval the data value to add. The high byte of the int is ignored.
*/
public void update (int bval)
{
//We could make a length 1 byte array and call update again, but I
//would rather not have that overhead
int s1 = checksum & 0xffff;
int s2 = checksum >>> 16;
s1 = (s1 + (bval & 0xFF)) % BASE;
s2 = (s1 + s2) % BASE;
checksum = (s2 << 16) + s1;
}
/**
* Updates the checksum with the bytes taken from the array.
*
* @param buffer an array of bytes
*/
public void update (byte[] buffer)
{
update(buffer, 0, buffer.length);
}
/**
* Updates the checksum with the bytes taken from the array.
*
* @param buf an array of bytes
* @param off the start of the data used for this update
* @param len the number of bytes to use for this update
*/
public void update (byte[] buf, int off, int len)
{
//(By Per Bothner)
int s1 = checksum & 0xffff;
int s2 = checksum >>> 16;
while (len > 0)
{
// We can defer the modulo operation:
// s1 maximally grows from 65521 to 65521 + 255 * 3800
// s2 maximally grows by 3800 * median(s1) = 2090079800 < 2^31
int n = 3800;
if (n > len)
n = len;
len -= n;
while (--n >= 0)
{
s1 = s1 + (buf[off++] & 0xFF);
s2 = s2 + s1;
}
s1 %= BASE;
s2 %= BASE;
}
/*Old implementation, borrowed from somewhere:
int n;
while (len-- > 0) {
s1 = (s1 + (bs[offset++] & 0xff)) % BASE;
s2 = (s2 + s1) % BASE;
}*/
checksum = (s2 << 16) | s1;
}
/**
* Returns the Adler32 data checksum computed so far.
*/
public long getValue()
{
return (long) checksum & 0xffffffffL;
}
}
================================================
FILE: src/peergos/gwt/emu/java/util/zip/CRC32.java
================================================
/* CRC32.java - Computes CRC32 data checksum of a data stream
Copyright (C) 1999. 2000, 2001 Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA.
Linking this library statically or dynamically with other modules is
making a combined work based on this library. Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.
As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module. An independent module is a module which is not derived from
or based on this library. If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
package java.util.zip;
/*
* Written using on-line Java Platform 1.2 API Specification, as well
* as "The Java Class Libraries", 2nd edition (Addison-Wesley, 1998).
* The actual CRC32 algorithm is taken from RFC 1952.
* Status: Believed complete and correct.
*/
/**
* Computes CRC32 data checksum of a data stream.
* The actual CRC32 algorithm is described in RFC 1952
* (GZIP file format specification version 4.3).
* Can be used to get the CRC32 over a stream if used with checked input/output
* streams.
*
* @see InflaterInputStream
* @see DeflaterOutputStream
*
* @author Per Bothner
* @date April 1, 1999.
*/
public class CRC32 implements Checksum
{
/** The crc data checksum so far. */
private int crc = 0;
/** The fast CRC table. Computed once when the CRC32 class is loaded. */
private static int[] crc_table = make_crc_table();
/** Make the table for a fast CRC. */
private static int[] make_crc_table ()
{
int[] crc_table = new int[256];
for (int n = 0; n < 256; n++)
{
int c = n;
for (int k = 8; --k >= 0; )
{
if ((c & 1) != 0)
c = 0xedb88320 ^ (c >>> 1);
else
c = c >>> 1;
}
crc_table[n] = c;
}
return crc_table;
}
/**
* Returns the CRC32 data checksum computed so far.
*/
public long getValue ()
{
return (long) crc & 0xffffffffL;
}
/**
* Resets the CRC32 data checksum as if no update was ever called.
*/
public void reset () { crc = 0; }
/**
* Updates the checksum with the int bval.
*
* @param bval (the byte is taken as the lower 8 bits of bval)
*/
public void update (int bval)
{
int c = ~crc;
c = crc_table[(c ^ bval) & 0xff] ^ (c >>> 8);
crc = ~c;
}
/**
* Adds the byte array to the data checksum.
*
* @param buf the buffer which contains the data
* @param off the offset in the buffer where the data starts
* @param len the length of the data
*/
public void update (byte[] buf, int off, int len)
{
int c = ~crc;
while (--len >= 0)
c = crc_table[(c ^ buf[off++]) & 0xff] ^ (c >>> 8);
crc = ~c;
}
/**
* Adds the complete byte array to the data checksum.
*/
public void update (byte[] buf) { update(buf, 0, buf.length); }
}
================================================
FILE: src/peergos/gwt/emu/java/util/zip/Checksum.java
================================================
/* Checksum.java - Interface to compute a data checksum
Copyright (C) 1999, 2000, 2001 Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA.
Linking this library statically or dynamically with other modules is
making a combined work based on this library. Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.
As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module. An independent module is a module which is not derived from
or based on this library. If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
package java.util.zip;
/*
* Written using on-line Java Platform 1.2 API Specification, as well
* as "The Java Class Libraries", 2nd edition (Addison-Wesley, 1998).
* St Believed complete and correct.
*/
/**
* Interface to compute a data checksum used by checked input/output streams.
* A data checksum can be updated by one byte or with a byte array. After each
* update the value of the current checksum can be returned by calling
* getValue. The complete checksum object can also be reset
* so it can be used again with new data.
*
* @see CheckedInputStream
* @see CheckedOutputStream
*
* @author Per Bothner
* @author Jochen Hoenicke
*/
public interface Checksum
{
/**
* Returns the data checksum computed so far.
*/
long getValue();
/**
* Resets the data checksum as if no update was ever called.
*/
void reset();
/**
* Adds one byte to the data checksum.
*
* @param bval the data value to add. The high byte of the int is ignored.
*/
void update (int bval);
/**
* Adds the byte array to the data checksum.
*
* @param buf the buffer which contains the data
* @param off the offset in the buffer where the data starts
* @param len the length of the data
*/
void update (byte[] buf, int off, int len);
}
================================================
FILE: src/peergos/gwt/emu/java/util/zip/Deflater.java
================================================
/* Deflater.java - Compress a data stream
Copyright (C) 1999, 2000, 2001, 2004, 2005 Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA.
Linking this library statically or dynamically with other modules is
making a combined work based on this library. Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.
As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module. An independent module is a module which is not derived from
or based on this library. If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
package java.util.zip;
/**
* This is the Deflater class. The deflater class compresses input
* with the deflate algorithm described in RFC 1951. It has several
* compression levels and three different strategies described below.
*
* This class is not thread safe. This is inherent in the API, due
* to the split of deflate and setInput.
*
* @author Jochen Hoenicke
* @author Tom Tromey
*/
public class Deflater
{
/**
* The best and slowest compression level. This tries to find very
* long and distant string repetitions.
*/
public static final int BEST_COMPRESSION = 9;
/**
* The worst but fastest compression level.
*/
public static final int BEST_SPEED = 1;
/**
* The default compression level.
*/
public static final int DEFAULT_COMPRESSION = -1;
/**
* This level won't compress at all but output uncompressed blocks.
*/
public static final int NO_COMPRESSION = 0;
/**
* The default strategy.
*/
public static final int DEFAULT_STRATEGY = 0;
/**
* This strategy will only allow longer string repetitions. It is
* useful for random data with a small character set.
*/
public static final int FILTERED = 1;
/**
* This strategy will not look for string repetitions at all. It
* only encodes with Huffman trees (which means, that more common
* characters get a smaller encoding.
*/
public static final int HUFFMAN_ONLY = 2;
/**
* The compression method. This is the only method supported so far.
* There is no need to use this constant at all.
*/
public static final int DEFLATED = 8;
/*
* The Deflater can do the following state transitions:
*
* (1) -> INIT_STATE ----> INIT_FINISHING_STATE ---.
* / | (2) (5) |
* / v (5) |
* (3)| SETDICT_STATE ---> SETDICT_FINISHING_STATE |(3)
* \ | (3) | ,-------'
* | | | (3) /
* v v (5) v v
* (1) -> BUSY_STATE ----> FINISHING_STATE
* | (6)
* v
* FINISHED_STATE
* \_____________________________________/
* | (7)
* v
* CLOSED_STATE
*
* (1) If we should produce a header we start in INIT_STATE, otherwise
* we start in BUSY_STATE.
* (2) A dictionary may be set only when we are in INIT_STATE, then
* we change the state as indicated.
* (3) Whether a dictionary is set or not, on the first call of deflate
* we change to BUSY_STATE.
* (4) -- intentionally left blank -- :)
* (5) FINISHING_STATE is entered, when flush() is called to indicate that
* there is no more INPUT. There are also states indicating, that
* the header wasn't written yet.
* (6) FINISHED_STATE is entered, when everything has been flushed to the
* internal pending output buffer.
* (7) At any time (7)
*
*/
private static final int IS_SETDICT = 0x01;
private static final int IS_FLUSHING = 0x04;
private static final int IS_FINISHING = 0x08;
private static final int INIT_STATE = 0x00;
private static final int SETDICT_STATE = 0x01;
private static final int INIT_FINISHING_STATE = 0x08;
private static final int SETDICT_FINISHING_STATE = 0x09;
private static final int BUSY_STATE = 0x10;
private static final int FLUSHING_STATE = 0x14;
private static final int FINISHING_STATE = 0x1c;
private static final int FINISHED_STATE = 0x1e;
private static final int CLOSED_STATE = 0x7f;
/** Compression level. */
private int level;
/** should we include a header. */
private boolean noHeader;
/** The current state. */
private int state;
/** The total bytes of output written. */
private long totalOut;
/** The pending output. */
private DeflaterPending pending;
/** The deflater engine. */
private DeflaterEngine engine;
/**
* Creates a new deflater with default compression level.
*/
public Deflater()
{
this(DEFAULT_COMPRESSION, false);
}
/**
* Creates a new deflater with given compression level.
* @param lvl the compression level, a value between NO_COMPRESSION
* and BEST_COMPRESSION, or DEFAULT_COMPRESSION.
* @exception IllegalArgumentException if lvl is out of range.
*/
public Deflater(int lvl)
{
this(lvl, false);
}
/**
* Creates a new deflater with given compression level.
* @param lvl the compression level, a value between NO_COMPRESSION
* and BEST_COMPRESSION.
* @param nowrap true, iff we should suppress the deflate header at the
* beginning and the adler checksum at the end of the output. This is
* useful for the GZIP format.
* @exception IllegalArgumentException if lvl is out of range.
*/
public Deflater(int lvl, boolean nowrap)
{
if (lvl == DEFAULT_COMPRESSION)
lvl = 6;
else if (lvl < NO_COMPRESSION || lvl > BEST_COMPRESSION)
throw new IllegalArgumentException();
pending = new DeflaterPending();
engine = new DeflaterEngine(pending);
this.noHeader = nowrap;
setStrategy(DEFAULT_STRATEGY);
setLevel(lvl);
reset();
}
/**
* Resets the deflater. The deflater acts afterwards as if it was
* just created with the same compression level and strategy as it
* had before.
*/
public void reset()
{
state = (noHeader ? BUSY_STATE : INIT_STATE);
totalOut = 0;
pending.reset();
engine.reset();
}
/**
* Frees all objects allocated by the compressor. There's no
* reason to call this, since you can just rely on garbage
* collection. Exists only for compatibility against Sun's JDK,
* where the compressor allocates native memory.
* If you call any method (even reset) afterwards the behaviour is
* undefined.
*/
public void end()
{
engine = null;
pending = null;
state = CLOSED_STATE;
}
/**
* Gets the current adler checksum of the data that was processed so
* far.
*/
public int getAdler()
{
return engine.getAdler();
}
/**
* Gets the number of input bytes processed so far.
*/
@Deprecated
public int getTotalIn()
{
return (int) engine.getTotalIn();
}
/**
* Gets the number of input bytes processed so far.
* @since 1.5
*/
public long getBytesRead()
{
return engine.getTotalIn();
}
/**
* Gets the number of output bytes so far.
*/
@Deprecated
public int getTotalOut()
{
return (int) totalOut;
}
/**
* Gets the number of output bytes so far.
* @since 1.5
*/
public long getBytesWritten()
{
return totalOut;
}
/**
* Finalizes this object.
*/
protected void finalize()
{
/* Exists solely for compatibility. We don't have any native state. */
}
/**
* Flushes the current input block. Further calls to deflate() will
* produce enough output to inflate everything in the current input
* block. This is not part of Sun's JDK so I have made it package
* private. It is used by DeflaterOutputStream to implement
* flush().
*/
void flush() {
state |= IS_FLUSHING;
}
/**
* Finishes the deflater with the current input block. It is an error
* to give more input after this method was called. This method must
* be called to force all bytes to be flushed.
*/
public void finish() {
state |= IS_FLUSHING | IS_FINISHING;
}
/**
* Returns true iff the stream was finished and no more output bytes
* are available.
*/
public boolean finished()
{
return state == FINISHED_STATE && pending.isFlushed();
}
/**
* Returns true, if the input buffer is empty.
* You should then call setInput().
*
* NOTE: This method can also return true when the stream
* was finished.
*/
public boolean needsInput()
{
return engine.needsInput();
}
/**
* Sets the data which should be compressed next. This should be only
* called when needsInput indicates that more input is needed.
* If you call setInput when needsInput() returns false, the
* previous input that is still pending will be thrown away.
* The given byte array should not be changed, before needsInput() returns
* true again.
* This call is equivalent to setInput(input, 0, input.length).
* @param input the buffer containing the input data.
* @exception IllegalStateException if the buffer was finished() or ended().
*/
public void setInput(byte[] input)
{
setInput(input, 0, input.length);
}
/**
* Sets the data which should be compressed next. This should be
* only called when needsInput indicates that more input is needed.
* The given byte array should not be changed, before needsInput() returns
* true again.
* @param input the buffer containing the input data.
* @param off the start of the data.
* @param len the length of the data.
* @exception IllegalStateException if the buffer was finished() or ended()
* or if previous input is still pending.
*/
public void setInput(byte[] input, int off, int len)
{
if ((state & IS_FINISHING) != 0)
throw new IllegalStateException("finish()/end() already called");
engine.setInput(input, off, len);
}
/**
* Sets the compression level. There is no guarantee of the exact
* position of the change, but if you call this when needsInput is
* true the change of compression level will occur somewhere near
* before the end of the so far given input.
* @param lvl the new compression level.
*/
public void setLevel(int lvl)
{
if (lvl == DEFAULT_COMPRESSION)
lvl = 6;
else if (lvl < NO_COMPRESSION || lvl > BEST_COMPRESSION)
throw new IllegalArgumentException();
if (level != lvl)
{
level = lvl;
engine.setLevel(lvl);
}
}
/**
* Sets the compression strategy. Strategy is one of
* DEFAULT_STRATEGY, HUFFMAN_ONLY and FILTERED. For the exact
* position where the strategy is changed, the same as for
* setLevel() applies.
* @param stgy the new compression strategy.
*/
public void setStrategy(int stgy)
{
if (stgy != DEFAULT_STRATEGY && stgy != FILTERED
&& stgy != HUFFMAN_ONLY)
throw new IllegalArgumentException();
engine.setStrategy(stgy);
}
/**
* Deflates the current input block to the given array. It returns
* the number of bytes compressed, or 0 if either
* needsInput() or finished() returns true or length is zero.
* @param output the buffer where to write the compressed data.
*/
public int deflate(byte[] output)
{
return deflate(output, 0, output.length);
}
/**
* Deflates the current input block to the given array. It returns
* the number of bytes compressed, or 0 if either
* needsInput() or finished() returns true or length is zero.
* @param output the buffer where to write the compressed data.
* @param offset the offset into the output array.
* @param length the maximum number of bytes that may be written.
* @exception IllegalStateException if end() was called.
* @exception IndexOutOfBoundsException if offset and/or length
* don't match the array length.
*/
public int deflate(byte[] output, int offset, int length)
{
int origLength = length;
if (state == CLOSED_STATE)
throw new IllegalStateException("Deflater closed");
if (state < BUSY_STATE)
{
/* output header */
int header = (DEFLATED +
((DeflaterConstants.MAX_WBITS - 8) << 4)) << 8;
int level_flags = (level - 1) >> 1;
if (level_flags < 0 || level_flags > 3)
level_flags = 3;
header |= level_flags << 6;
if ((state & IS_SETDICT) != 0)
/* Dictionary was set */
header |= DeflaterConstants.PRESET_DICT;
header += 31 - (header % 31);
pending.writeShortMSB(header);
if ((state & IS_SETDICT) != 0)
{
int chksum = engine.getAdler();
engine.resetAdler();
pending.writeShortMSB(chksum >> 16);
pending.writeShortMSB(chksum & 0xffff);
}
state = BUSY_STATE | (state & (IS_FLUSHING | IS_FINISHING));
}
for (;;)
{
int count = pending.flush(output, offset, length);
offset += count;
totalOut += count;
length -= count;
if (length == 0 || state == FINISHED_STATE)
break;
if (!engine.deflate((state & IS_FLUSHING) != 0,
(state & IS_FINISHING) != 0))
{
if (state == BUSY_STATE)
/* We need more input now */
return origLength - length;
else if (state == FLUSHING_STATE)
{
if (level != NO_COMPRESSION)
{
/* We have to supply some lookahead. 8 bit lookahead
* are needed by the zlib inflater, and we must fill
* the next byte, so that all bits are flushed.
*/
int neededbits = 8 + ((-pending.getBitCount()) & 7);
while (neededbits > 0)
{
/* write a static tree block consisting solely of
* an EOF:
*/
pending.writeBits(2, 10);
neededbits -= 10;
}
}
state = BUSY_STATE;
}
else if (state == FINISHING_STATE)
{
pending.alignToByte();
/* We have completed the stream */
if (!noHeader)
{
int adler = engine.getAdler();
pending.writeShortMSB(adler >> 16);
pending.writeShortMSB(adler & 0xffff);
}
state = FINISHED_STATE;
}
}
}
return origLength - length;
}
/**
* Sets the dictionary which should be used in the deflate process.
* This call is equivalent to setDictionary(dict, 0,
* dict.length).
* @param dict the dictionary.
* @exception IllegalStateException if setInput () or deflate ()
* were already called or another dictionary was already set.
*/
public void setDictionary(byte[] dict)
{
setDictionary(dict, 0, dict.length);
}
/**
* Sets the dictionary which should be used in the deflate process.
* The dictionary should be a byte array containing strings that are
* likely to occur in the data which should be compressed. The
* dictionary is not stored in the compressed output, only a
* checksum. To decompress the output you need to supply the same
* dictionary again.
* @param dict the dictionary.
* @param offset an offset into the dictionary.
* @param length the length of the dictionary.
* @exception IllegalStateException if setInput () or deflate () were
* already called or another dictionary was already set.
*/
public void setDictionary(byte[] dict, int offset, int length)
{
if (state != INIT_STATE)
throw new IllegalStateException();
state = SETDICT_STATE;
engine.setDictionary(dict, offset, length);
}
}
================================================
FILE: src/peergos/gwt/emu/java/util/zip/DeflaterConstants.java
================================================
/* java.util.zip.DeflaterConstants
Copyright (C) 2001 Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA.
Linking this library statically or dynamically with other modules is
making a combined work based on this library. Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.
As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module. An independent module is a module which is not derived from
or based on this library. If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
package java.util.zip;
interface DeflaterConstants
{
boolean DEBUGGING = false;
int STORED_BLOCK = 0;
int STATIC_TREES = 1;
int DYN_TREES = 2;
int PRESET_DICT = 0x20;
int DEFAULT_MEM_LEVEL = 8;
int MAX_MATCH = 258;
int MIN_MATCH = 3;
int MAX_WBITS = 15;
int WSIZE = 1 << MAX_WBITS;
int WMASK = WSIZE - 1;
int HASH_BITS = DEFAULT_MEM_LEVEL + 7;
int HASH_SIZE = 1 << HASH_BITS;
int HASH_MASK = HASH_SIZE - 1;
int HASH_SHIFT = (HASH_BITS + MIN_MATCH - 1) / MIN_MATCH;
int MIN_LOOKAHEAD = MAX_MATCH + MIN_MATCH + 1;
int MAX_DIST = WSIZE - MIN_LOOKAHEAD;
int PENDING_BUF_SIZE = 1 << (DEFAULT_MEM_LEVEL + 8);
int MAX_BLOCK_SIZE = Math.min(65535, PENDING_BUF_SIZE-5);
int DEFLATE_STORED = 0;
int DEFLATE_FAST = 1;
int DEFLATE_SLOW = 2;
int GOOD_LENGTH[] = { 0,4, 4, 4, 4, 8, 8, 8, 32, 32 };
int MAX_LAZY[] = { 0,4, 5, 6, 4,16, 16, 32, 128, 258 };
int NICE_LENGTH[] = { 0,8,16,32,16,32,128,128, 258, 258 };
int MAX_CHAIN[] = { 0,4, 8,32,16,32,128,256,1024,4096 };
int COMPR_FUNC[] = { 0,1, 1, 1, 1, 2, 2, 2, 2, 2 };
}
================================================
FILE: src/peergos/gwt/emu/java/util/zip/DeflaterEngine.java
================================================
/* DeflaterEngine.java --
Copyright (C) 2001, 2004 Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA.
Linking this library statically or dynamically with other modules is
making a combined work based on this library. Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.
As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module. An independent module is a module which is not derived from
or based on this library. If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
package java.util.zip;
class DeflaterEngine implements DeflaterConstants
{
private static final int TOO_FAR = 4096;
private int ins_h;
/**
* Hashtable, hashing three characters to an index for window, so
* that window[index]..window[index+2] have this hash code.
* Note that the array should really be unsigned short, so you need
* to and the values with 0xffff.
*/
private short[] head;
/**
* prev[index & WMASK] points to the previous index that has the
* same hash code as the string starting at index. This way
* entries with the same hash code are in a linked list.
* Note that the array should really be unsigned short, so you need
* to and the values with 0xffff.
*/
private short[] prev;
private int matchStart, matchLen;
private boolean prevAvailable;
private int blockStart;
/**
* strstart points to the current character in window.
*/
private int strstart;
/**
* lookahead is the number of characters starting at strstart in
* window that are valid.
* So window[strstart] until window[strstart+lookahead-1] are valid
* characters.
*/
private int lookahead;
/**
* This array contains the part of the uncompressed stream that
* is of relevance. The current character is indexed by strstart.
*/
private byte[] window;
private int strategy, max_chain, max_lazy, niceLength, goodLength;
/** The current compression function. */
private int comprFunc;
/** The input data for compression. */
private byte[] inputBuf;
/** The total bytes of input read. */
private int totalIn;
/** The offset into inputBuf, where input data starts. */
private int inputOff;
/** The end offset of the input data. */
private int inputEnd;
private DeflaterPending pending;
private DeflaterHuffman huffman;
/** The adler checksum */
private Adler32 adler;
/* DEFLATE ALGORITHM:
*
* The uncompressed stream is inserted into the window array. When
* the window array is full the first half is thrown away and the
* second half is copied to the beginning.
*
* The head array is a hash table. Three characters build a hash value
* and they the value points to the corresponding index in window of
* the last string with this hash. The prev array implements a
* linked list of matches with the same hash: prev[index & WMASK] points
* to the previous index with the same hash.
*
*
*/
DeflaterEngine(DeflaterPending pending) {
this.pending = pending;
huffman = new DeflaterHuffman(pending);
adler = new Adler32();
window = new byte[2*WSIZE];
head = new short[HASH_SIZE];
prev = new short[WSIZE];
/* We start at index 1, to avoid a implementation deficiency, that
* we cannot build a repeat pattern at index 0.
*/
blockStart = strstart = 1;
}
public void reset()
{
huffman.reset();
adler.reset();
blockStart = strstart = 1;
lookahead = 0;
totalIn = 0;
prevAvailable = false;
matchLen = MIN_MATCH - 1;
for (int i = 0; i < HASH_SIZE; i++)
head[i] = 0;
for (int i = 0; i < WSIZE; i++)
prev[i] = 0;
}
public final void resetAdler()
{
adler.reset();
}
public final int getAdler()
{
int chksum = (int) adler.getValue();
return chksum;
}
public final int getTotalIn()
{
return totalIn;
}
public final void setStrategy(int strat)
{
strategy = strat;
}
public void setLevel(int lvl)
{
goodLength = DeflaterConstants.GOOD_LENGTH[lvl];
max_lazy = DeflaterConstants.MAX_LAZY[lvl];
niceLength = DeflaterConstants.NICE_LENGTH[lvl];
max_chain = DeflaterConstants.MAX_CHAIN[lvl];
if (DeflaterConstants.COMPR_FUNC[lvl] != comprFunc)
{
if (DeflaterConstants.DEBUGGING)
System.err.println("Change from "+comprFunc +" to "
+ DeflaterConstants.COMPR_FUNC[lvl]);
switch (comprFunc)
{
case DEFLATE_STORED:
if (strstart > blockStart)
{
huffman.flushStoredBlock(window, blockStart,
strstart - blockStart, false);
blockStart = strstart;
}
updateHash();
break;
case DEFLATE_FAST:
if (strstart > blockStart)
{
huffman.flushBlock(window, blockStart, strstart - blockStart,
false);
blockStart = strstart;
}
break;
case DEFLATE_SLOW:
if (prevAvailable)
huffman.tallyLit(window[strstart-1] & 0xff);
if (strstart > blockStart)
{
huffman.flushBlock(window, blockStart, strstart - blockStart,
false);
blockStart = strstart;
}
prevAvailable = false;
matchLen = MIN_MATCH - 1;
break;
}
comprFunc = COMPR_FUNC[lvl];
}
}
private void updateHash() {
if (DEBUGGING)
System.err.println("updateHash: "+strstart);
ins_h = (window[strstart] << HASH_SHIFT) ^ window[strstart + 1];
}
/**
* Inserts the current string in the head hash and returns the previous
* value for this hash.
*/
private int insertString() {
short match;
int hash = ((ins_h << HASH_SHIFT) ^ window[strstart + (MIN_MATCH -1)])
& HASH_MASK;
if (DEBUGGING)
{
if (hash != (((window[strstart] << (2*HASH_SHIFT))
^ (window[strstart + 1] << HASH_SHIFT)
^ (window[strstart + 2])) & HASH_MASK))
throw new InternalError("hash inconsistent: "+hash+"/"
+window[strstart]+","
+window[strstart+1]+","
+window[strstart+2]+","+HASH_SHIFT);
}
prev[strstart & WMASK] = match = head[hash];
head[hash] = (short) strstart;
ins_h = hash;
return match & 0xffff;
}
private void slideWindow()
{
System.arraycopy(window, WSIZE, window, 0, WSIZE);
matchStart -= WSIZE;
strstart -= WSIZE;
blockStart -= WSIZE;
/* Slide the hash table (could be avoided with 32 bit values
* at the expense of memory usage).
*/
for (int i = 0; i < HASH_SIZE; i++)
{
int m = head[i] & 0xffff;
head[i] = m >= WSIZE ? (short) (m - WSIZE) : 0;
}
/* Slide the prev table.
*/
for (int i = 0; i < WSIZE; i++)
{
int m = prev[i] & 0xffff;
prev[i] = m >= WSIZE ? (short) (m - WSIZE) : 0;
}
}
/**
* Fill the window when the lookahead becomes insufficient.
* Updates strstart and lookahead.
*
* OUT assertions: strstart + lookahead <= 2*WSIZE
* lookahead >= MIN_LOOKAHEAD or inputOff == inputEnd
*/
private void fillWindow()
{
/* If the window is almost full and there is insufficient lookahead,
* move the upper half to the lower one to make room in the upper half.
*/
if (strstart >= WSIZE + MAX_DIST)
slideWindow();
/* If there is not enough lookahead, but still some input left,
* read in the input
*/
while (lookahead < DeflaterConstants.MIN_LOOKAHEAD && inputOff < inputEnd)
{
int more = 2*WSIZE - lookahead - strstart;
if (more > inputEnd - inputOff)
more = inputEnd - inputOff;
System.arraycopy(inputBuf, inputOff,
window, strstart + lookahead, more);
adler.update(inputBuf, inputOff, more);
inputOff += more;
totalIn += more;
lookahead += more;
}
if (lookahead >= MIN_MATCH)
updateHash();
}
/**
* Find the best (longest) string in the window matching the
* string starting at strstart.
*
* Preconditions:
* strstart + MAX_MATCH <= window.length.
*
*
* @param curMatch
*/
private boolean findLongestMatch(int curMatch) {
int chainLength = this.max_chain;
int niceLength = this.niceLength;
short[] prev = this.prev;
int scan = this.strstart;
int match;
int best_end = this.strstart + matchLen;
int best_len = Math.max(matchLen, MIN_MATCH - 1);
int limit = Math.max(strstart - MAX_DIST, 0);
int strend = scan + MAX_MATCH - 1;
byte scan_end1 = window[best_end - 1];
byte scan_end = window[best_end];
/* Do not waste too much time if we already have a good match: */
if (best_len >= this.goodLength)
chainLength >>= 2;
/* Do not look for matches beyond the end of the input. This is necessary
* to make deflate deterministic.
*/
if (niceLength > lookahead)
niceLength = lookahead;
if (DeflaterConstants.DEBUGGING
&& strstart > 2*WSIZE - MIN_LOOKAHEAD)
throw new InternalError("need lookahead");
do {
if (DeflaterConstants.DEBUGGING && curMatch >= strstart)
throw new InternalError("future match");
if (window[curMatch + best_len] != scan_end
|| window[curMatch + best_len - 1] != scan_end1
|| window[curMatch] != window[scan]
|| window[curMatch+1] != window[scan + 1])
continue;
match = curMatch + 2;
scan += 2;
/* We check for insufficient lookahead only every 8th comparison;
* the 256th check will be made at strstart+258.
*/
while (window[++scan] == window[++match]
&& window[++scan] == window[++match]
&& window[++scan] == window[++match]
&& window[++scan] == window[++match]
&& window[++scan] == window[++match]
&& window[++scan] == window[++match]
&& window[++scan] == window[++match]
&& window[++scan] == window[++match]
&& scan < strend);
if (scan > best_end) {
// if (DeflaterConstants.DEBUGGING && ins_h == 0)
// System.err.println("Found match: "+curMatch+"-"+(scan-strstart));
matchStart = curMatch;
best_end = scan;
best_len = scan - strstart;
if (best_len >= niceLength)
break;
scan_end1 = window[best_end-1];
scan_end = window[best_end];
}
scan = strstart;
} while ((curMatch = (prev[curMatch & WMASK] & 0xffff)) > limit
&& --chainLength != 0);
matchLen = Math.min(best_len, lookahead);
return matchLen >= MIN_MATCH;
}
void setDictionary(byte[] buffer, int offset, int length) {
if (DeflaterConstants.DEBUGGING && strstart != 1)
throw new IllegalStateException("strstart not 1");
adler.update(buffer, offset, length);
if (length < MIN_MATCH)
return;
if (length > MAX_DIST) {
offset += length - MAX_DIST;
length = MAX_DIST;
}
System.arraycopy(buffer, offset, window, strstart, length);
updateHash();
length--;
while (--length > 0)
{
insertString();
strstart++;
}
strstart += 2;
blockStart = strstart;
}
private boolean deflateStored(boolean flush, boolean finish)
{
if (!flush && lookahead == 0)
return false;
strstart += lookahead;
lookahead = 0;
int storedLen = strstart - blockStart;
if ((storedLen >= DeflaterConstants.MAX_BLOCK_SIZE)
/* Block is full */
|| (blockStart < WSIZE && storedLen >= MAX_DIST)
/* Block may move out of window */
|| flush)
{
boolean lastBlock = finish;
if (storedLen > DeflaterConstants.MAX_BLOCK_SIZE)
{
storedLen = DeflaterConstants.MAX_BLOCK_SIZE;
lastBlock = false;
}
if (DeflaterConstants.DEBUGGING)
System.err.println("storedBlock["+storedLen+","+lastBlock+"]");
huffman.flushStoredBlock(window, blockStart, storedLen, lastBlock);
blockStart += storedLen;
return !lastBlock;
}
return true;
}
private boolean deflateFast(boolean flush, boolean finish)
{
if (lookahead < MIN_LOOKAHEAD && !flush)
return false;
while (lookahead >= MIN_LOOKAHEAD || flush)
{
if (lookahead == 0)
{
/* We are flushing everything */
huffman.flushBlock(window, blockStart, strstart - blockStart,
finish);
blockStart = strstart;
return false;
}
if (strstart > 2 * WSIZE - MIN_LOOKAHEAD)
{
/* slide window, as findLongestMatch need this.
* This should only happen when flushing and the window
* is almost full.
*/
slideWindow();
}
int hashHead;
if (lookahead >= MIN_MATCH
&& (hashHead = insertString()) != 0
&& strategy != Deflater.HUFFMAN_ONLY
&& strstart - hashHead <= MAX_DIST
&& findLongestMatch(hashHead))
{
/* longestMatch sets matchStart and matchLen */
if (DeflaterConstants.DEBUGGING)
{
for (int i = 0 ; i < matchLen; i++)
{
if (window[strstart+i] != window[matchStart + i])
throw new InternalError();
}
}
boolean full = huffman.tallyDist(strstart - matchStart, matchLen);
lookahead -= matchLen;
if (matchLen <= max_lazy && lookahead >= MIN_MATCH)
{
while (--matchLen > 0)
{
strstart++;
insertString();
}
strstart++;
}
else
{
strstart += matchLen;
if (lookahead >= MIN_MATCH - 1)
updateHash();
}
matchLen = MIN_MATCH - 1;
if (!full)
continue;
}
else
{
/* No match found */
huffman.tallyLit(window[strstart] & 0xff);
strstart++;
lookahead--;
}
if (huffman.isFull())
{
boolean lastBlock = finish && lookahead == 0;
huffman.flushBlock(window, blockStart, strstart - blockStart,
lastBlock);
blockStart = strstart;
return !lastBlock;
}
}
return true;
}
private boolean deflateSlow(boolean flush, boolean finish)
{
if (lookahead < MIN_LOOKAHEAD && !flush)
return false;
while (lookahead >= MIN_LOOKAHEAD || flush)
{
if (lookahead == 0)
{
if (prevAvailable)
huffman.tallyLit(window[strstart-1] & 0xff);
prevAvailable = false;
/* We are flushing everything */
if (DeflaterConstants.DEBUGGING && !flush)
throw new InternalError("Not flushing, but no lookahead");
huffman.flushBlock(window, blockStart, strstart - blockStart,
finish);
blockStart = strstart;
return false;
}
if (strstart >= 2 * WSIZE - MIN_LOOKAHEAD)
{
/* slide window, as findLongestMatch need this.
* This should only happen when flushing and the window
* is almost full.
*/
slideWindow();
}
int prevMatch = matchStart;
int prevLen = matchLen;
if (lookahead >= MIN_MATCH)
{
int hashHead = insertString();
if (strategy != Deflater.HUFFMAN_ONLY
&& hashHead != 0 && strstart - hashHead <= MAX_DIST
&& findLongestMatch(hashHead))
{
/* longestMatch sets matchStart and matchLen */
/* Discard match if too small and too far away */
if (matchLen <= 5
&& (strategy == Deflater.FILTERED
|| (matchLen == MIN_MATCH
&& strstart - matchStart > TOO_FAR))) {
matchLen = MIN_MATCH - 1;
}
}
}
/* previous match was better */
if (prevLen >= MIN_MATCH && matchLen <= prevLen)
{
if (DeflaterConstants.DEBUGGING)
{
for (int i = 0 ; i < matchLen; i++)
{
if (window[strstart-1+i] != window[prevMatch + i])
throw new InternalError();
}
}
huffman.tallyDist(strstart - 1 - prevMatch, prevLen);
prevLen -= 2;
do
{
strstart++;
lookahead--;
if (lookahead >= MIN_MATCH)
insertString();
}
while (--prevLen > 0);
strstart ++;
lookahead--;
prevAvailable = false;
matchLen = MIN_MATCH - 1;
}
else
{
if (prevAvailable)
huffman.tallyLit(window[strstart-1] & 0xff);
prevAvailable = true;
strstart++;
lookahead--;
}
if (huffman.isFull())
{
int len = strstart - blockStart;
if (prevAvailable)
len--;
boolean lastBlock = (finish && lookahead == 0 && !prevAvailable);
huffman.flushBlock(window, blockStart, len, lastBlock);
blockStart += len;
return !lastBlock;
}
}
return true;
}
public boolean deflate(boolean flush, boolean finish)
{
boolean progress;
do
{
fillWindow();
boolean canFlush = flush && inputOff == inputEnd;
if (DeflaterConstants.DEBUGGING)
System.err.println("window: ["+blockStart+","+strstart+","
+lookahead+"], "+comprFunc+","+canFlush);
switch (comprFunc)
{
case DEFLATE_STORED:
progress = deflateStored(canFlush, finish);
break;
case DEFLATE_FAST:
progress = deflateFast(canFlush, finish);
break;
case DEFLATE_SLOW:
progress = deflateSlow(canFlush, finish);
break;
default:
throw new InternalError();
}
}
while (pending.isFlushed() /* repeat while we have no pending output */
&& progress); /* and progress was made */
return progress;
}
public void setInput(byte[] buf, int off, int len)
{
if (inputOff < inputEnd)
throw new IllegalStateException
("Old input was not completely processed");
int end = off + len;
/* We want to throw an ArrayIndexOutOfBoundsException early. The
* check is very tricky: it also handles integer wrap around.
*/
if (0 > off || off > end || end > buf.length)
throw new ArrayIndexOutOfBoundsException();
inputBuf = buf;
inputOff = off;
inputEnd = end;
}
public final boolean needsInput()
{
return inputEnd == inputOff;
}
}
================================================
FILE: src/peergos/gwt/emu/java/util/zip/DeflaterHuffman.java
================================================
/* DeflaterHuffman.java --
Copyright (C) 2001, 2004, 2005 Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA.
Linking this library statically or dynamically with other modules is
making a combined work based on this library. Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.
As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module. An independent module is a module which is not derived from
or based on this library. If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
package java.util.zip;
/**
* This is the DeflaterHuffman class.
*
* This class is not thread safe. This is inherent in the API, due
* to the split of deflate and setInput.
*
* @author Jochen Hoenicke
* @date Jan 6, 2000
*/
class DeflaterHuffman
{
private static final int BUFSIZE = 1 << (DeflaterConstants.DEFAULT_MEM_LEVEL + 6);
private static final int LITERAL_NUM = 286;
private static final int DIST_NUM = 30;
private static final int BITLEN_NUM = 19;
private static final int REP_3_6 = 16;
private static final int REP_3_10 = 17;
private static final int REP_11_138 = 18;
private static final int EOF_SYMBOL = 256;
private static final int[] BL_ORDER =
{ 16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15 };
private static final String bit4Reverse =
"\000\010\004\014\002\012\006\016\001\011\005\015\003\013\007\017";
class Tree {
short[] freqs;
short[] codes;
byte[] length;
int[] bl_counts;
int minNumCodes, numCodes;
int maxLength;
Tree(int elems, int minCodes, int maxLength) {
this.minNumCodes = minCodes;
this.maxLength = maxLength;
freqs = new short[elems];
bl_counts = new int[maxLength];
}
void reset() {
for (int i = 0; i < freqs.length; i++)
freqs[i] = 0;
codes = null;
length = null;
}
final void writeSymbol(int code)
{
if (DeflaterConstants.DEBUGGING)
{
freqs[code]--;
// System.err.print("writeSymbol("+freqs.length+","+code+"): ");
}
pending.writeBits(codes[code] & 0xffff, length[code]);
}
final void checkEmpty()
{
boolean empty = true;
for (int i = 0; i < freqs.length; i++)
if (freqs[i] != 0)
{
System.err.println("freqs["+i+"] == "+freqs[i]);
empty = false;
}
if (!empty)
throw new InternalError();
System.err.println("checkEmpty suceeded!");
}
void setStaticCodes(short[] stCodes, byte[] stLength)
{
codes = stCodes;
length = stLength;
}
public void buildCodes() {
int[] nextCode = new int[maxLength];
int code = 0;
codes = new short[freqs.length];
if (DeflaterConstants.DEBUGGING)
System.err.println("buildCodes: "+freqs.length);
for (int bits = 0; bits < maxLength; bits++)
{
nextCode[bits] = code;
code += bl_counts[bits] << (15 - bits);
if (DeflaterConstants.DEBUGGING)
System.err.println("bits: "+(bits+1)+" count: "+bl_counts[bits]
+" nextCode: "+Integer.toHexString(code));
}
if (DeflaterConstants.DEBUGGING && code != 65536)
throw new RuntimeException("Inconsistent bl_counts!");
for (int i=0; i < numCodes; i++)
{
int bits = length[i];
if (bits > 0)
{
if (DeflaterConstants.DEBUGGING)
System.err.println("codes["+i+"] = rev("
+Integer.toHexString(nextCode[bits-1])+"),"
+bits);
codes[i] = bitReverse(nextCode[bits-1]);
nextCode[bits-1] += 1 << (16 - bits);
}
}
}
private void buildLength(int childs[])
{
this.length = new byte [freqs.length];
int numNodes = childs.length / 2;
int numLeafs = (numNodes + 1) / 2;
int overflow = 0;
for (int i = 0; i < maxLength; i++)
bl_counts[i] = 0;
/* First calculate optimal bit lengths */
int lengths[] = new int[numNodes];
lengths[numNodes-1] = 0;
for (int i = numNodes - 1; i >= 0; i--)
{
if (childs[2*i+1] != -1)
{
int bitLength = lengths[i] + 1;
if (bitLength > maxLength)
{
bitLength = maxLength;
overflow++;
}
lengths[childs[2*i]] = lengths[childs[2*i+1]] = bitLength;
}
else
{
/* A leaf node */
int bitLength = lengths[i];
bl_counts[bitLength - 1]++;
this.length[childs[2*i]] = (byte) lengths[i];
}
}
if (DeflaterConstants.DEBUGGING)
{
System.err.println("Tree "+freqs.length+" lengths:");
for (int i=0; i < numLeafs; i++)
System.err.println("Node "+childs[2*i]+" freq: "+freqs[childs[2*i]]
+ " len: "+length[childs[2*i]]);
}
if (overflow == 0)
return;
int incrBitLen = maxLength - 1;
do
{
/* Find the first bit length which could increase: */
while (bl_counts[--incrBitLen] == 0)
;
/* Move this node one down and remove a corresponding
* amount of overflow nodes.
*/
do
{
bl_counts[incrBitLen]--;
bl_counts[++incrBitLen]++;
overflow -= 1 << (maxLength - 1 - incrBitLen);
}
while (overflow > 0 && incrBitLen < maxLength - 1);
}
while (overflow > 0);
/* We may have overshot above. Move some nodes from maxLength to
* maxLength-1 in that case.
*/
bl_counts[maxLength-1] += overflow;
bl_counts[maxLength-2] -= overflow;
/* Now recompute all bit lengths, scanning in increasing
* frequency. It is simpler to reconstruct all lengths instead of
* fixing only the wrong ones. This idea is taken from 'ar'
* written by Haruhiko Okumura.
*
* The nodes were inserted with decreasing frequency into the childs
* array.
*/
int nodePtr = 2 * numLeafs;
for (int bits = maxLength; bits != 0; bits--)
{
int n = bl_counts[bits-1];
while (n > 0)
{
int childPtr = 2*childs[nodePtr++];
if (childs[childPtr + 1] == -1)
{
/* We found another leaf */
length[childs[childPtr]] = (byte) bits;
n--;
}
}
}
if (DeflaterConstants.DEBUGGING)
{
System.err.println("*** After overflow elimination. ***");
for (int i=0; i < numLeafs; i++)
System.err.println("Node "+childs[2*i]+" freq: "+freqs[childs[2*i]]
+ " len: "+length[childs[2*i]]);
}
}
void buildTree()
{
int numSymbols = freqs.length;
/* heap is a priority queue, sorted by frequency, least frequent
* nodes first. The heap is a binary tree, with the property, that
* the parent node is smaller than both child nodes. This assures
* that the smallest node is the first parent.
*
* The binary tree is encoded in an array: 0 is root node and
* the nodes 2*n+1, 2*n+2 are the child nodes of node n.
*/
int[] heap = new int[numSymbols];
int heapLen = 0;
int maxCode = 0;
for (int n = 0; n < numSymbols; n++)
{
int freq = freqs[n];
if (freq != 0)
{
/* Insert n into heap */
int pos = heapLen++;
int ppos;
while (pos > 0 &&
freqs[heap[ppos = (pos - 1) / 2]] > freq) {
heap[pos] = heap[ppos];
pos = ppos;
}
heap[pos] = n;
maxCode = n;
}
}
/* We could encode a single literal with 0 bits but then we
* don't see the literals. Therefore we force at least two
* literals to avoid this case. We don't care about order in
* this case, both literals get a 1 bit code.
*/
while (heapLen < 2)
{
int node = maxCode < 2 ? ++maxCode : 0;
heap[heapLen++] = node;
}
numCodes = Math.max(maxCode + 1, minNumCodes);
int numLeafs = heapLen;
int[] childs = new int[4*heapLen - 2];
int[] values = new int[2*heapLen - 1];
int numNodes = numLeafs;
for (int i = 0; i < heapLen; i++)
{
int node = heap[i];
childs[2*i] = node;
childs[2*i+1] = -1;
values[i] = freqs[node] << 8;
heap[i] = i;
}
/* Construct the Huffman tree by repeatedly combining the least two
* frequent nodes.
*/
do
{
int first = heap[0];
int last = heap[--heapLen];
/* Propagate the hole to the leafs of the heap */
int ppos = 0;
int path = 1;
while (path < heapLen)
{
if (path + 1 < heapLen
&& values[heap[path]] > values[heap[path+1]])
path++;
heap[ppos] = heap[path];
ppos = path;
path = path * 2 + 1;
}
/* Now propagate the last element down along path. Normally
* it shouldn't go too deep.
*/
int lastVal = values[last];
while ((path = ppos) > 0
&& values[heap[ppos = (path - 1)/2]] > lastVal)
heap[path] = heap[ppos];
heap[path] = last;
int second = heap[0];
/* Create a new node father of first and second */
last = numNodes++;
childs[2*last] = first;
childs[2*last+1] = second;
int mindepth = Math.min(values[first] & 0xff, values[second] & 0xff);
values[last] = lastVal = values[first] + values[second] - mindepth + 1;
/* Again, propagate the hole to the leafs */
ppos = 0;
path = 1;
while (path < heapLen)
{
if (path + 1 < heapLen
&& values[heap[path]] > values[heap[path+1]])
path++;
heap[ppos] = heap[path];
ppos = path;
path = ppos * 2 + 1;
}
/* Now propagate the new element down along path */
while ((path = ppos) > 0
&& values[heap[ppos = (path - 1)/2]] > lastVal)
heap[path] = heap[ppos];
heap[path] = last;
}
while (heapLen > 1);
if (heap[0] != childs.length / 2 - 1)
throw new RuntimeException("Weird!");
buildLength(childs);
}
int getEncodedLength()
{
int len = 0;
for (int i = 0; i < freqs.length; i++)
len += freqs[i] * length[i];
return len;
}
void calcBLFreq(Tree blTree) {
int max_count; /* max repeat count */
int min_count; /* min repeat count */
int count; /* repeat count of the current code */
int curlen = -1; /* length of current code */
int i = 0;
while (i < numCodes)
{
count = 1;
int nextlen = length[i];
if (nextlen == 0)
{
max_count = 138;
min_count = 3;
}
else
{
max_count = 6;
min_count = 3;
if (curlen != nextlen)
{
blTree.freqs[nextlen]++;
count = 0;
}
}
curlen = nextlen;
i++;
while (i < numCodes && curlen == length[i])
{
i++;
if (++count >= max_count)
break;
}
if (count < min_count)
blTree.freqs[curlen] += count;
else if (curlen != 0)
blTree.freqs[REP_3_6]++;
else if (count <= 10)
blTree.freqs[REP_3_10]++;
else
blTree.freqs[REP_11_138]++;
}
}
void writeTree(Tree blTree)
{
int max_count; /* max repeat count */
int min_count; /* min repeat count */
int count; /* repeat count of the current code */
int curlen = -1; /* length of current code */
int i = 0;
while (i < numCodes)
{
count = 1;
int nextlen = length[i];
if (nextlen == 0)
{
max_count = 138;
min_count = 3;
}
else
{
max_count = 6;
min_count = 3;
if (curlen != nextlen)
{
blTree.writeSymbol(nextlen);
count = 0;
}
}
curlen = nextlen;
i++;
while (i < numCodes && curlen == length[i])
{
i++;
if (++count >= max_count)
break;
}
if (count < min_count)
{
while (count-- > 0)
blTree.writeSymbol(curlen);
}
else if (curlen != 0)
{
blTree.writeSymbol(REP_3_6);
pending.writeBits(count - 3, 2);
}
else if (count <= 10)
{
blTree.writeSymbol(REP_3_10);
pending.writeBits(count - 3, 3);
}
else
{
blTree.writeSymbol(REP_11_138);
pending.writeBits(count - 11, 7);
}
}
}
}
DeflaterPending pending;
private Tree literalTree, distTree, blTree;
private short d_buf[];
private byte l_buf[];
private int last_lit;
private int extra_bits;
private static short staticLCodes[];
private static byte staticLLength[];
private static short staticDCodes[];
private static byte staticDLength[];
/**
* Reverse the bits of a 16 bit value.
*/
static short bitReverse(int value) {
return (short) (bit4Reverse.charAt(value & 0xf) << 12
| bit4Reverse.charAt((value >> 4) & 0xf) << 8
| bit4Reverse.charAt((value >> 8) & 0xf) << 4
| bit4Reverse.charAt(value >> 12));
}
static {
/* See RFC 1951 3.2.6 */
/* Literal codes */
staticLCodes = new short[LITERAL_NUM];
staticLLength = new byte[LITERAL_NUM];
int i = 0;
while (i < 144) {
staticLCodes[i] = bitReverse((0x030 + i) << 8);
staticLLength[i++] = 8;
}
while (i < 256) {
staticLCodes[i] = bitReverse((0x190 - 144 + i) << 7);
staticLLength[i++] = 9;
}
while (i < 280) {
staticLCodes[i] = bitReverse((0x000 - 256 + i) << 9);
staticLLength[i++] = 7;
}
while (i < LITERAL_NUM) {
staticLCodes[i] = bitReverse((0x0c0 - 280 + i) << 8);
staticLLength[i++] = 8;
}
/* Distant codes */
staticDCodes = new short[DIST_NUM];
staticDLength = new byte[DIST_NUM];
for (i = 0; i < DIST_NUM; i++) {
staticDCodes[i] = bitReverse(i << 11);
staticDLength[i] = 5;
}
}
public DeflaterHuffman(DeflaterPending pending)
{
this.pending = pending;
literalTree = new Tree(LITERAL_NUM, 257, 15);
distTree = new Tree(DIST_NUM, 1, 15);
blTree = new Tree(BITLEN_NUM, 4, 7);
d_buf = new short[BUFSIZE];
l_buf = new byte [BUFSIZE];
}
public final void reset() {
last_lit = 0;
extra_bits = 0;
literalTree.reset();
distTree.reset();
blTree.reset();
}
private int l_code(int len) {
if (len == 255)
return 285;
int code = 257;
while (len >= 8)
{
code += 4;
len >>= 1;
}
return code + len;
}
private int d_code(int distance) {
int code = 0;
while (distance >= 4)
{
code += 2;
distance >>= 1;
}
return code + distance;
}
public void sendAllTrees(int blTreeCodes) {
blTree.buildCodes();
literalTree.buildCodes();
distTree.buildCodes();
pending.writeBits(literalTree.numCodes - 257, 5);
pending.writeBits(distTree.numCodes - 1, 5);
pending.writeBits(blTreeCodes - 4, 4);
for (int rank = 0; rank < blTreeCodes; rank++)
pending.writeBits(blTree.length[BL_ORDER[rank]], 3);
literalTree.writeTree(blTree);
distTree.writeTree(blTree);
if (DeflaterConstants.DEBUGGING)
blTree.checkEmpty();
}
public void compressBlock() {
for (int i = 0; i < last_lit; i++)
{
int litlen = l_buf[i] & 0xff;
int dist = d_buf[i];
if (dist-- != 0)
{
if (DeflaterConstants.DEBUGGING)
System.err.print("["+(dist+1)+","+(litlen+3)+"]: ");
int lc = l_code(litlen);
literalTree.writeSymbol(lc);
int bits = (lc - 261) / 4;
if (bits > 0 && bits <= 5)
pending.writeBits(litlen & ((1 << bits) - 1), bits);
int dc = d_code(dist);
distTree.writeSymbol(dc);
bits = dc / 2 - 1;
if (bits > 0)
pending.writeBits(dist & ((1 << bits) - 1), bits);
}
else
{
if (DeflaterConstants.DEBUGGING)
{
if (litlen > 32 && litlen < 127)
System.err.print("("+(char)litlen+"): ");
else
System.err.print("{"+litlen+"}: ");
}
literalTree.writeSymbol(litlen);
}
}
if (DeflaterConstants.DEBUGGING)
System.err.print("EOF: ");
literalTree.writeSymbol(EOF_SYMBOL);
if (DeflaterConstants.DEBUGGING)
{
literalTree.checkEmpty();
distTree.checkEmpty();
}
}
public void flushStoredBlock(byte[] stored,
int stored_offset, int stored_len,
boolean lastBlock) {
if (DeflaterConstants.DEBUGGING)
System.err.println("Flushing stored block "+ stored_len);
pending.writeBits((DeflaterConstants.STORED_BLOCK << 1)
+ (lastBlock ? 1 : 0), 3);
pending.alignToByte();
pending.writeShort(stored_len);
pending.writeShort(~stored_len);
pending.writeBlock(stored, stored_offset, stored_len);
reset();
}
public void flushBlock(byte[] stored, int stored_offset, int stored_len,
boolean lastBlock) {
literalTree.freqs[EOF_SYMBOL]++;
/* Build trees */
literalTree.buildTree();
distTree.buildTree();
/* Calculate bitlen frequency */
literalTree.calcBLFreq(blTree);
distTree.calcBLFreq(blTree);
/* Build bitlen tree */
blTree.buildTree();
int blTreeCodes = 4;
for (int i = 18; i > blTreeCodes; i--)
{
if (blTree.length[BL_ORDER[i]] > 0)
blTreeCodes = i+1;
}
int opt_len = 14 + blTreeCodes * 3 + blTree.getEncodedLength()
+ literalTree.getEncodedLength() + distTree.getEncodedLength()
+ extra_bits;
int static_len = extra_bits;
for (int i = 0; i < LITERAL_NUM; i++)
static_len += literalTree.freqs[i] * staticLLength[i];
for (int i = 0; i < DIST_NUM; i++)
static_len += distTree.freqs[i] * staticDLength[i];
if (opt_len >= static_len)
{
/* Force static trees */
opt_len = static_len;
}
if (stored_offset >= 0 && stored_len+4 < opt_len >> 3)
{
/* Store Block */
if (DeflaterConstants.DEBUGGING)
System.err.println("Storing, since " + stored_len + " < " + opt_len
+ " <= " + static_len);
flushStoredBlock(stored, stored_offset, stored_len, lastBlock);
}
else if (opt_len == static_len)
{
/* Encode with static tree */
pending.writeBits((DeflaterConstants.STATIC_TREES << 1)
+ (lastBlock ? 1 : 0), 3);
literalTree.setStaticCodes(staticLCodes, staticLLength);
distTree.setStaticCodes(staticDCodes, staticDLength);
compressBlock();
reset();
}
else
{
/* Encode with dynamic tree */
pending.writeBits((DeflaterConstants.DYN_TREES << 1)
+ (lastBlock ? 1 : 0), 3);
sendAllTrees(blTreeCodes);
compressBlock();
reset();
}
}
public final boolean isFull()
{
return last_lit == BUFSIZE;
}
public final boolean tallyLit(int lit)
{
if (DeflaterConstants.DEBUGGING)
{
if (lit > 32 && lit < 127)
System.err.println("("+(char)lit+")");
else
System.err.println("{"+lit+"}");
}
d_buf[last_lit] = 0;
l_buf[last_lit++] = (byte) lit;
literalTree.freqs[lit]++;
return last_lit == BUFSIZE;
}
public final boolean tallyDist(int dist, int len)
{
if (DeflaterConstants.DEBUGGING)
System.err.println("["+dist+","+len+"]");
d_buf[last_lit] = (short) dist;
l_buf[last_lit++] = (byte) (len - 3);
int lc = l_code(len-3);
literalTree.freqs[lc]++;
if (lc >= 265 && lc < 285)
extra_bits += (lc - 261) / 4;
int dc = d_code(dist-1);
distTree.freqs[dc]++;
if (dc >= 4)
extra_bits += dc / 2 - 1;
return last_lit == BUFSIZE;
}
}
================================================
FILE: src/peergos/gwt/emu/java/util/zip/DeflaterOutputStream.java
================================================
/* DeflaterOutputStream.java - Output filter for compressing.
Copyright (C) 1999, 2000, 2001, 2004, 2005 Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA.
Linking this library statically or dynamically with other modules is
making a combined work based on this library. Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.
As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module. An independent module is a module which is not derived from
or based on this library. If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
package java.util.zip;
import java.io.FilterOutputStream;
import java.io.IOException;
import java.io.OutputStream;
/* Written using on-line Java Platform 1.2 API Specification
* and JCL book.
* Believed complete and correct.
*/
/**
* This is a special FilterOutputStream deflating the bytes that are
* written through it. It uses the Deflater for deflating.
*
* A special thing to be noted is that flush() doesn't flush
* everything in Sun's JDK, but it does so in jazzlib. This is because
* Sun's Deflater doesn't have a way to flush() everything, without
* finishing the stream.
*
* @author Tom Tromey, Jochen Hoenicke
* @date Jan 11, 2001
*/
public class DeflaterOutputStream extends FilterOutputStream
{
/**
* This buffer is used temporarily to retrieve the bytes from the
* deflater and write them to the underlying output stream.
*/
protected byte[] buf;
/**
* The deflater which is used to deflate the stream.
*/
protected Deflater def;
/**
* Deflates everything in the def's input buffers. This will call
* def.deflate() until all bytes from the input buffers
* are processed.
*/
protected void deflate() throws IOException
{
while (! def.needsInput())
{
int len = def.deflate(buf, 0, buf.length);
// System.err.println("DOS deflated " + len + " out of " + buf.length);
if (len <= 0)
break;
out.write(buf, 0, len);
}
if (! def.needsInput())
throw new InternalError("Can't deflate all input?");
}
/**
* Creates a new DeflaterOutputStream with a default Deflater and
* default buffer size.
* @param out the output stream where deflated output should be written.
*/
public DeflaterOutputStream(OutputStream out)
{
this(out, new Deflater(), 4096);
}
/**
* Creates a new DeflaterOutputStream with the given Deflater and
* default buffer size.
* @param out the output stream where deflated output should be written.
* @param defl the underlying deflater.
*/
public DeflaterOutputStream(OutputStream out, Deflater defl)
{
this(out, defl, 4096);
}
/**
* Creates a new DeflaterOutputStream with the given Deflater and
* buffer size.
* @param out the output stream where deflated output should be written.
* @param defl the underlying deflater.
* @param bufsize the buffer size.
* @exception IllegalArgumentException if bufsize isn't positive.
*/
public DeflaterOutputStream(OutputStream out, Deflater defl, int bufsize)
{
super(out);
if (bufsize <= 0)
throw new IllegalArgumentException("bufsize <= 0");
buf = new byte[bufsize];
def = defl;
}
/**
* Flushes the stream by calling flush() on the deflater and then
* on the underlying stream. This ensures that all bytes are
* flushed. This function doesn't work in Sun's JDK, but only in
* jazzlib.
*/
public void flush() throws IOException
{
def.flush();
deflate();
out.flush();
}
/**
* Finishes the stream by calling finish() on the deflater. This
* was the only way to ensure that all bytes are flushed in Sun's
* JDK.
*/
public void finish() throws IOException
{
def.finish();
while (! def.finished())
{
int len = def.deflate(buf, 0, buf.length);
if (len <= 0)
break;
out.write(buf, 0, len);
}
if (! def.finished())
throw new InternalError("Can't deflate all input?");
out.flush();
}
/**
* Calls finish() and closes the stream.
*/
public void close() throws IOException
{
finish();
out.close();
}
/**
* Writes a single byte to the compressed output stream.
* @param bval the byte value.
*/
public void write(int bval) throws IOException
{
byte[] b = new byte[1];
b[0] = (byte) bval;
write(b, 0, 1);
}
/**
* Writes a len bytes from an array to the compressed stream.
* @param buf the byte array.
* @param off the offset into the byte array where to start.
* @param len the number of bytes to write.
*/
public void write(byte[] buf, int off, int len) throws IOException
{
def.setInput(buf, off, len);
deflate();
}
}
================================================
FILE: src/peergos/gwt/emu/java/util/zip/DeflaterPending.java
================================================
/* java.util.zip.DeflaterPending
Copyright (C) 2001 Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA.
Linking this library statically or dynamically with other modules is
making a combined work based on this library. Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.
As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module. An independent module is a module which is not derived from
or based on this library. If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
package java.util.zip;
/**
* This class stores the pending output of the Deflater.
*
* @author Jochen Hoenicke
* @date Jan 5, 2000
*/
class DeflaterPending extends PendingBuffer
{
public DeflaterPending()
{
super(DeflaterConstants.PENDING_BUF_SIZE);
}
}
================================================
FILE: src/peergos/gwt/emu/java/util/zip/GZIPInputStream.java
================================================
/*******************************************************************************
* Copyright 2011 See AUTHORS file.
*
* 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 java.util.zip;
import java.io.IOException;
import java.io.InputStream;
/** Dummy emulation. Throws a GdxRuntimeException on first read.
* @author hneuer */
public class GZIPInputStream extends InflaterInputStream {
public GZIPInputStream (InputStream in, int size) {
super(in);
}
public GZIPInputStream(InputStream in) throws IOException {
super(in);
}
}
================================================
FILE: src/peergos/gwt/emu/java/util/zip/InflaterInputStream.java
================================================
/*******************************************************************************
* Copyright 2011 See AUTHORS file.
*
* 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 java.util.zip;
import java.io.IOException;
import java.io.InputStream;
/** Dummy emulation. Throws a GdxRuntimeException on first read.
* @author hneuer */
public class InflaterInputStream extends InputStream {
private InputStream in;
public InflaterInputStream (InputStream in) {
this.in = in;
}
@Override
public int read () throws IOException {
throw new IOException("InflaterInputStream not supported in GWT");
}
@Override
public void close () throws IOException {
super.close();
//StreamUtils.closeQuietly(in);
}
}
================================================
FILE: src/peergos/gwt/emu/java/util/zip/PendingBuffer.java
================================================
/* java.util.zip.PendingBuffer
Copyright (C) 2001 Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA.
Linking this library statically or dynamically with other modules is
making a combined work based on this library. Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.
As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module. An independent module is a module which is not derived from
or based on this library. If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
package java.util.zip;
/**
* This class is general purpose class for writing data to a buffer.
*
* It allows you to write bits as well as bytes
*
* Based on DeflaterPending.java
*
* @author Jochen Hoenicke
* @date Jan 5, 2000
*/
class PendingBuffer
{
protected byte[] buf;
int start;
int end;
int bits;
int bitCount;
public PendingBuffer()
{
this( 4096 );
}
public PendingBuffer(int bufsize)
{
buf = new byte[bufsize];
}
public final void reset() {
start = end = bitCount = 0;
}
public final void writeByte(int b)
{
if (DeflaterConstants.DEBUGGING && start != 0)
throw new IllegalStateException();
buf[end++] = (byte) b;
}
public final void writeShort(int s)
{
if (DeflaterConstants.DEBUGGING && start != 0)
throw new IllegalStateException();
buf[end++] = (byte) s;
buf[end++] = (byte) (s >> 8);
}
public final void writeInt(int s)
{
if (DeflaterConstants.DEBUGGING && start != 0)
throw new IllegalStateException();
buf[end++] = (byte) s;
buf[end++] = (byte) (s >> 8);
buf[end++] = (byte) (s >> 16);
buf[end++] = (byte) (s >> 24);
}
public final void writeBlock(byte[] block, int offset, int len)
{
if (DeflaterConstants.DEBUGGING && start != 0)
throw new IllegalStateException();
System.arraycopy(block, offset, buf, end, len);
end += len;
}
public final int getBitCount() {
return bitCount;
}
public final void alignToByte() {
if (DeflaterConstants.DEBUGGING && start != 0)
throw new IllegalStateException();
if (bitCount > 0)
{
buf[end++] = (byte) bits;
if (bitCount > 8)
buf[end++] = (byte) (bits >>> 8);
}
bits = 0;
bitCount = 0;
}
public final void writeBits(int b, int count)
{
if (DeflaterConstants.DEBUGGING && start != 0)
throw new IllegalStateException();
if (DeflaterConstants.DEBUGGING)
System.err.println("writeBits("+Integer.toHexString(b)+","+count+")");
bits |= b << bitCount;
bitCount += count;
if (bitCount >= 16) {
buf[end++] = (byte) bits;
buf[end++] = (byte) (bits >>> 8);
bits >>>= 16;
bitCount -= 16;
}
}
public final void writeShortMSB(int s) {
if (DeflaterConstants.DEBUGGING && start != 0)
throw new IllegalStateException();
buf[end++] = (byte) (s >> 8);
buf[end++] = (byte) s;
}
public final boolean isFlushed() {
return end == 0;
}
/**
* Flushes the pending buffer into the given output array. If the
* output array is to small, only a partial flush is done.
*
* @param output the output array;
* @param offset the offset into output array;
* @param length the maximum number of bytes to store;
* @exception IndexOutOfBoundsException if offset or length are
* invalid.
*/
public final int flush(byte[] output, int offset, int length) {
if (bitCount >= 8)
{
buf[end++] = (byte) bits;
bits >>>= 8;
bitCount -= 8;
}
if (length > end - start)
{
length = end - start;
System.arraycopy(buf, start, output, offset, length);
start = 0;
end = 0;
}
else
{
System.arraycopy(buf, start, output, offset, length);
start += length;
}
return length;
}
/**
* Flushes the pending buffer and returns that data in a new array
*
* @return the output stream
*/
public final byte[] toByteArray()
{
byte[] ret = new byte[ end - start ];
System.arraycopy(buf, start, ret, 0, ret.length);
start = 0;
end = 0;
return ret;
}
}
================================================
FILE: src/peergos/gwt/emu/javafx/application/Platform.java
================================================
package javafx.application;
public final class Platform {
public static void runLater(Runnable runnable) {};
}
================================================
FILE: src/peergos/gwt/emu/javafx/embed/swing/JFXPanel.java
================================================
package javafx.embed.swing;
public final class JFXPanel {
public JFXPanel(){
}
}
================================================
FILE: src/peergos/gwt/emu/javafx/embed/swing/SwingFXUtils.java
================================================
package javafx.embed.swing;
import java.awt.image.BufferedImage;
import javafx.scene.image.Image;
public final class SwingFXUtils {
public static BufferedImage fromFXImage(Image img, BufferedImage bimg) {
return null;
}
}
================================================
FILE: src/peergos/gwt/emu/javafx/scene/SnapshotParameters.java
================================================
package javafx.scene;
public final class SnapshotParameters {
}
================================================
FILE: src/peergos/gwt/emu/javafx/scene/image/Image.java
================================================
package javafx.scene.image;
public class Image{
public Image() {
}
}
================================================
FILE: src/peergos/gwt/emu/javafx/scene/image/WritableImage.java
================================================
package javafx.scene.image;
public final class WritableImage extends Image {
public WritableImage(int width, int height) {
super();
}
}
================================================
FILE: src/peergos/gwt/emu/javafx/scene/media/Media.java
================================================
package javafx.scene.media;
import javafx.util.Duration;
public final class Media {
public Media(String source){
}
public final Duration getDuration() {
return null;
}
}
================================================
FILE: src/peergos/gwt/emu/javafx/scene/media/MediaPlayer.java
================================================
package javafx.scene.media;
import javafx.util.Duration;
public final class MediaPlayer{
public MediaPlayer(Media media){
}
public void seek(Duration seekTime) {
}
}
================================================
FILE: src/peergos/gwt/emu/javafx/scene/media/MediaView.java
================================================
package javafx.scene.media;
import javafx.scene.image.WritableImage;
import javafx.scene.SnapshotParameters;
public final class MediaView{
public MediaView() {
}
public void setFitWidth(int width){
}
public void setFitHeight(int height) {
}
public void setMediaPlayer(MediaPlayer mediaPlayer){
}
public void setPreserveRatio(boolean preserverRatio) {
}
public WritableImage snapshot(SnapshotParameters params, WritableImage image){
return null;
}
}
================================================
FILE: src/peergos/gwt/emu/javafx/util/Duration.java
================================================
package javafx.util;
public final class Duration {
public static Duration seconds(double s) {
return null;
}
public boolean isUnknown() {
return false;
}
public double toSeconds() {
return 0;
}
}
================================================
FILE: src/peergos/gwt/emu/javax/crypto/Mac.java
================================================
package javax.crypto;
import javax.crypto.spec.SecretKeySpec;
public class Mac {
public static Mac getInstance(String algo)
{
return null;
}
public void init(SecretKeySpec spec)
{
}
public int getMacLength()
{
return -1;
}
public void update(byte[] b)
{
}
public void doFinal(byte[] a, int i)
{
}
}
================================================
FILE: src/peergos/gwt/emu/javax/crypto/spec/SecretKeySpec.java
================================================
package javax.crypto.spec;
public class SecretKeySpec {
private final byte[] key;
private final String algorithm;
public SecretKeySpec(byte[] key, String algorithm)
{
this.key = key;
this.algorithm = algorithm;
}
public byte[] getEncoded() {
return this.key;
}
}
================================================
FILE: src/peergos/gwt/emu/javax/imageio/ImageIO.java
================================================
package javax.imageio;
import java.awt.image.BufferedImage;
import java.awt.image.RenderedImage;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.IOException;
/*
* Dummy implementation - does nothing
* */
public class ImageIO {
public static BufferedImage read(InputStream input) throws IOException {
return null;
}
public static boolean write(RenderedImage im,
String formatName,
OutputStream output) throws IOException {
return false;
}
}
================================================
FILE: src/peergos/server/AggregatedMetrics.java
================================================
package peergos.server;
import io.prometheus.client.Counter;
import io.prometheus.client.Histogram;
import io.prometheus.client.exporter.HTTPServer;
import peergos.server.util.*;
import java.io.IOException;
import java.util.*;
/**
* A wrapper around the prometheus metrics and HTTP exporter.
*/
public class AggregatedMetrics {
private static Counter build(String name, String help) {
return Counter.build()
.name(name).help(help).register();
}
public static final Counter FOLLOW_REQUEST_COUNTER = build("send_follow_request_total","Total follow requests.");
public static final Counter GET_FOLLOW_REQUEST_COUNTER = build("get_follow_request_counter", "Total get follow request calls.");
public static final Counter REMOVE_FOLLOW_REQUEST_COUNTER = build("remove_follow_request_counter", "Total remove follow request calls.");
public static final Counter PUBLIC_FILE_COUNTER = build("public_file_counter", "Total public files.");
public static final Counter STORAGE_ID = build("storage_id", "Total id calls.");
public static final Counter STORAGE_IDS = build("storage_ids", "Total ids calls.");
public static final Counter STORAGE_BLOCK_PUT = build("storage_block_put", "Total DHT block puts.");
public static final Counter STORAGE_BLOCK_PUT_BULK = build("storage_block_put_bulk", "Total bulk block puts.");
public static final Counter STORAGE_BLOCK_GET = build("storage_block_get", "Total DHT block gets.");
public static final Counter STORAGE_BLOCK_STAT = build("storage_block_stat", "Total DHT block stats.");
public static final Counter STORAGE_BLOCK_REFS = build("storage_block_refs", "Total DHT block refs.");
public static final Counter STORAGE_TRANSACTION_START = build("storage_transaction_start", "Total DHT transaction starts.");
public static final Counter STORAGE_TRANSACTION_CLOSE = build("storage_transaction_close", "Total DHT transaction closes.");
public static final Counter STORAGE_CHAMP_GET = build("storage_champ_get", "Total champ gets");
public static final Counter STORAGE_LINK_GET = build("storage_link_get", "Total link gets");
public static final Counter STORAGE_LINK_COUNTS = build("storage_link_counts", "Total link counts");
public static final Counter STORAGE_IPNS_GET = build("storage_ipns_get", "Total ipns gets");
public static final Histogram STORAGE_CHAMP_GET_DURATION = Histogram.build()
.labelNames("duration")
.name("champ_get_duration")
.help("Time to respond to a champ.get call")
.exponentialBuckets(0.01, 2, 16)
.register();
public static final Histogram STORAGE_LINK_GET_DURATION = Histogram.build()
.labelNames("duration")
.name("link_get_duration")
.help("Time to respond to a link.get call")
.exponentialBuckets(0.01, 2, 16)
.register();
public static final Counter MUTABLE_POINTERS_SET = build("mutable_pointers_set", "Total mutable-pointers set calls.");
public static final Counter MUTABLE_POINTERS_GET = build("mutable_pointers_get", "Total mutable-pointers get calls.");
public static final Counter LOGIN_SET = build("login_set", "Total login set calls.");
public static final Counter LOGIN_GET = build("login_get", "Total successful login get calls.");
public static final Counter LOGIN_GET_FAILURE_PASSWORD = build("login_get_failure_password", "Total login get calls with incorrect signature.");
public static final Counter LOGIN_GET_FAILURE_EXTERNAL = build("login_get_failure_external", "Total failed login get calls for external users.");
public static final Counter LOGIN_GET_MFA = build("login_get_mfa", "Total get mfa calls.");
public static final Counter LOGIN_ADD_TOTP = build("login_add_totp", "Total add totp calls.");
public static final Counter LOGIN_ENABLE_TOTP = build("login_enable_totp", "Total enable totp calls.");
public static final Counter LOGIN_WEBAUTHN_START = build("login_webauthn_start", "Total webauthn start calls.");
public static final Counter LOGIN_WEBAUTHN_COMPLETE = build("login_webauthn_complete", "Total webauthn complete calls.");
public static final Counter LOGIN_DELETE_MFA = build("login_delete_mfa", "Total delete mfa calls.");
public static final Counter BAT_ADD = build("bat_add", "Total addBat calls.");
public static final Counter BATS_GET = build("bats_get", "Total getBats calls.");
public static final Counter GET_ALL_USERNAMES = build("core_node_get_all_usernames", "Total get-all-usernames calls.");
public static final Counter GET_USERNAME = build("core_node_get_username", "Total get-username calls.");
public static final Counter GET_PUBLIC_KEY = build("core_node_get_public_key", "Total get-public-key calls.");
public static final Counter GET_PUBLIC_KEY_CHAIN = build("core_node_get_chain", "Total get-public-key-chain calls.");
public static final Counter UPDATE_PUBLIC_KEY_CHAIN = build("core_node_update_chain", "Total getupdate-public-key-chain calls.");
public static final Counter PKI_RATE_LIMITED = build("pki_rate_limited", "Total number of pki updates rate limited.");
public static final Counter SIGNUP = build("core_node_signup", "Total signup calls.");
public static final Counter PAID_SIGNUP_START = build("core_node_signup_paid_start", "Total start paid signup calls.");
public static final Counter PAID_SIGNUP_COMPLETE = build("core_node_signup_paid_complete", "Total complete paid signup calls.");
public static final Counter PAID_SIGNUP_SUCCESS = build("core_node_signup_paid_success", "Total successful paid signup calls.");
public static final Counter MIRROR = build("core_node_mirror", "Total mirror calls.");
public static final Counter PAID_MIRROR_START = build("core_node_mirror_paid_start", "Total start paid mirror calls.");
public static final Counter PAID_MIRROR_COMPLETE = build("core_node_mirror_paid_complete", "Total complete paid mirror calls.");
public static final Counter GET_USER_SNAPSHOTS = build("core_node_get_user_snapshots", "Total get user snapshots calls.");
public static final Counter PAID_MIRROR_SUCCESS = build("core_node_mirror_paid_success", "Total successful paid mirror calls.");
public static final Counter MIGRATE_USER = build("core_node_migrate_user", "Total migrate-user calls.");
private static Set