WIP migrating to kotlin.

This commit is contained in:
Robinson 2023-08-16 19:44:03 -05:00
parent fd7583023d
commit ada5ffddd5
No known key found for this signature in database
GPG Key ID: 8E7DB78588BD6F5C
31 changed files with 1168 additions and 1663 deletions

389
LICENSE
View File

@ -6,23 +6,21 @@
Parse and extract data from Microsoft LZX compressed .cab files for Java 8+
Extra license information
- ByteUtilties - Byte manipulation and Unsigned Number Utilities
- Kotlin -
[The Apache Software License, Version 2.0]
https://github.com/JetBrains/kotlin
Copyright 2020
JetBrains s.r.o. and Kotlin Programming Language contributors
Kotlin Compiler, Test Data+Libraries, and Tools repository contain third-party code, to which different licenses may apply
See: https://github.com/JetBrains/kotlin/blob/master/license/README.md
- ByteUtils - Byte manipulation and SHA/xxHash utilities
[The Apache Software License, Version 2.0]
https://git.dorkbox.com/dorkbox/ByteUtilities
Copyright 2023
Dorkbox LLC
Extra license information
- Byte Utils (UByte, UInteger, ULong, Unsigned, UNumber, UShort) -
[The Apache Software License, Version 2.0]
https://github.com/jOOQ/jOOQ/tree/master/jOOQ/src/main/java/org/jooq/types
Copyright 2017
Data Geekery GmbH (http://www.datageekery.com)
Lukas Eder
Ed Schaller
Jens Nerche
Ivan Sokolov
- Kryo Serialization -
[BSD 3-Clause License]
https://github.com/EsotericSoftware/kryo
@ -73,7 +71,7 @@
- Objenesis -
[The Apache Software License, Version 2.0]
http://objenesis.org
https://github.com/easymock/objenesis
Objenesis Team and all contributors
- MinLog-SLF4J -
@ -81,6 +79,13 @@
https://github.com/EsotericSoftware/minlog
Nathan Sweet
- LZ4 and xxHash - LZ4 compression for Java, based on Yann Collet's work
[The Apache Software License, Version 2.0]
https://github.com/lz4/lz4
Copyright 2023
Yann Collet
Adrien Grand
- Updates - Software Update Management
[The Apache Software License, Version 2.0]
https://git.dorkbox.com/dorkbox/Updates
@ -125,23 +130,6 @@
Sean Luke
Michael Lecuyer (portions Copyright 1993
- FileUtil (code from FilenameUtils.java for normalize + dependencies) -
[The Apache Software License, Version 2.0]
https://git.dorkbox.com/dorkbox/Utilities
http://commons.apache.org/proper/commons-io/
Copyright 2013
The Apache Software Foundation
Kevin A. Burton
Scott Sanders
Daniel Rall
Christoph.Reck
Peter Donald
Jeff Turner
Matthew Hawthorne
Martin Cooper
Jeremias Maerki
Stephen Colebourne
- FastThreadLocal -
[BSD 3-Clause License]
https://git.dorkbox.com/dorkbox/Utilities
@ -151,21 +139,6 @@
Lightweight Java Game Library Project
Riven
- Base64Fast -
[BSD 3-Clause License]
https://git.dorkbox.com/dorkbox/Utilities
http://migbase64.sourceforge.net/
Copyright 2004
Mikael Grev, MiG InfoCom AB. (base64@miginfocom.com)
- BCrypt -
[BSD 2-Clause "Simplified" or "FreeBSD" license]
https://git.dorkbox.com/dorkbox/Utilities
http://www.mindrot.org/projects/jBCrypt
Copyright 2006
Damien Miller (djm@mindrot.org)
GWT modified version
- Modified hex conversion utility methods -
[The Apache Software License, Version 2.0]
https://git.dorkbox.com/dorkbox/Utilities
@ -181,7 +154,7 @@
- Resource Listing - Listing the contents of a resource directory
[The Apache Software License, Version 2.0]
http://www.uofr.net/~greg/java/get-resource-listing.html
https://www.uofr.net/~greg/java/get-resource-listing.html
Copyright 2017
Greg Briggs
@ -192,17 +165,12 @@
Pronghorn Technology LLC
Dorkbox LLC
- UrlRewriteFilter - UrlRewriteFilter is a Java Web Filter for any J2EE compliant web application server
[BSD 3-Clause License]
https://github.com/paultuckey/urlrewritefilter
Copyright 2022
Paul Tuckey
- kotlinx.coroutines - Library support for Kotlin coroutines with multiplatform support
- Kotlin Coroutine CountDownLatch -
[The Apache Software License, Version 2.0]
https://github.com/Kotlin/kotlinx.coroutines
Copyright 2023
JetBrains s.r.o.
https://github.com/Kotlin/kotlinx.coroutines/issues/59
https://github.com/venkatperi/kotlin-coroutines-lib
Copyright 2018
Venkat Peri
- Java Uuid Generator - A set of Java classes for working with UUIDs
[The Apache Software License, Version 2.0]
@ -211,12 +179,6 @@
Tatu Saloranta (tatu.saloranta@iki.fi)
Contributors. See source release-notes/CREDITS
- SLF4J - Simple facade or abstraction for various logging frameworks
[MIT License]
http://www.slf4j.org
Copyright 2023
QOS.ch
- XZ for Java - Complete implementation of XZ data compression in pure Java
[Public Domain, per Creative Commons CC0]
https://tukaani.org/xz/java.html
@ -224,6 +186,13 @@
Lasse Collin
Igor Pavlov
- Netty - An event-driven asynchronous network application framework
[The Apache Software License, Version 2.0]
https://netty.io
Copyright 2023
The Netty Project
Contributors. See source NOTICE
- Kotlin -
[The Apache Software License, Version 2.0]
https://github.com/JetBrains/kotlin
@ -232,127 +201,16 @@
Kotlin Compiler, Test Data+Libraries, and Tools repository contain third-party code, to which different licenses may apply
See: https://github.com/JetBrains/kotlin/blob/master/license/README.md
- Netty - An event-driven asynchronous network application framework
- kotlinx.coroutines - Library support for Kotlin coroutines with multiplatform support
[The Apache Software License, Version 2.0]
https://netty.io
https://github.com/Kotlin/kotlinx.coroutines
Copyright 2023
The Netty Project
Contributors. See source NOTICE
- Bouncy Castle Crypto - Lightweight cryptography API and JCE Extension
[The Apache Software License, Version 2.0]
http://www.bouncycastle.org
Copyright 2023
The Legion of the Bouncy Castle Inc
- Lightweight Java Game Library - Java library that enables cross-platform access to popular native APIs
[BSD 3-Clause License]
https://github.com/LWJGL/lwjgl3
Copyright 2023
Lightweight Java Game Library
- TypeTools - A simple, zero-dependency library for working with types. Supports Java 1.6+ and Android.
[The Apache Software License, Version 2.0]
https://github.com/jhalterman/typetools
Copyright 2023
Jonathan Halterman and friends
- Collections - Niche collections to augment what is already available.
[The Apache Software License, Version 2.0]
https://git.dorkbox.com/dorkbox/Collections
Copyright 2022
Dorkbox LLC
Extra license information
- AhoCorasickDoubleArrayTrie - Niche collections to augment what is already available.
[The Apache Software License, Version 2.0]
https://github.com/hankcs/AhoCorasickDoubleArrayTrie
Copyright 2018
hankcs <me@hankcs.com>
- Bias, BinarySearch -
[MIT License]
https://git.dorkbox.com/dorkbox/Collections
https://github.com/timboudreau/util
Copyright 2013
Tim Boudreau
- ConcurrentEntry -
[The Apache Software License, Version 2.0]
https://git.dorkbox.com/dorkbox/Collections
Copyright 2016
bennidi
dorkbox
- Collection Utilities (Array, ArrayMap, BooleanArray, ByteArray, CharArray, FloatArray, IdentityMap, IntArray, IntFloatMap, IntIntMap, IntMap, IntSet, LongArray, LongMap, ObjectFloatMap, ObjectIntMap, ObjectMap, ObjectSet, OrderedMap, OrderedSet) -
[The Apache Software License, Version 2.0]
https://git.dorkbox.com/dorkbox/Collections
https://github.com/libgdx/libgdx/blob/master/gdx/src/com/badlogic/gdx/utils
Copyright 2011
LibGDX
Mario Zechner (badlogicgames@gmail.com)
Nathan Sweet (nathan.sweet@gmail.com)
- Predicate -
[The Apache Software License, Version 2.0]
https://git.dorkbox.com/dorkbox/Collections
https://github.com/libgdx/libgdx/blob/master/gdx/src/com/badlogic/gdx/utils
Copyright 2011
LibGDX
Mario Zechner (badlogicgames@gmail.com)
Nathan Sweet (nathan.sweet@gmail.com)
xoppa
- Select, QuickSelect -
[The Apache Software License, Version 2.0]
https://git.dorkbox.com/dorkbox/Collections
https://github.com/libgdx/libgdx/blob/master/gdx/src/com/badlogic/gdx/utils
Copyright 2011
LibGDX
Mario Zechner (badlogicgames@gmail.com)
Nathan Sweet (nathan.sweet@gmail.com)
Jon Renner
- TimSort, ComparableTimSort -
[The Apache Software License, Version 2.0]
https://git.dorkbox.com/dorkbox/Collections
https://github.com/libgdx/libgdx/blob/master/gdx/src/com/badlogic/gdx/utils
Copyright 2008
The Android Open Source Project
- ConcurrentWeakIdentityHashMap - Concurrent WeakIdentity HashMap
[The Apache Software License, Version 2.0]
https://github.com/spring-projects/spring-loaded/blob/master/springloaded/src/main/java/org/springsource/loaded/support/ConcurrentWeakIdentityHashMap.java
Copyright 2016
zhanhb
- Kotlin -
[The Apache Software License, Version 2.0]
https://github.com/JetBrains/kotlin
Copyright 2020
JetBrains s.r.o. and Kotlin Programming Language contributors
Kotlin Compiler, Test Data+Libraries, and Tools repository contain third-party code, to which different licenses may apply
See: https://github.com/JetBrains/kotlin/blob/master/license/README.md
- Updates - Software Update Management
[The Apache Software License, Version 2.0]
https://git.dorkbox.com/dorkbox/Updates
Copyright 2021
Dorkbox LLC
Extra license information
- Kotlin -
[The Apache Software License, Version 2.0]
https://github.com/JetBrains/kotlin
Copyright 2020
JetBrains s.r.o. and Kotlin Programming Language contributors
Kotlin Compiler, Test Data+Libraries, and Tools repository contain third-party code, to which different licenses may apply
See: https://github.com/JetBrains/kotlin/blob/master/license/README.md
JetBrains s.r.o.
- Executor - Shell, JVM, and SSH command execution on Linux, MacOS, or Windows for Java 8+
[The Apache Software License, Version 2.0]
https://git.dorkbox.com/dorkbox/Executor
Copyright 2022
Copyright 2023
Dorkbox LLC
Extra license information
@ -379,25 +237,25 @@
- kotlinx.coroutines - Library support for Kotlin coroutines with multiplatform support
[The Apache Software License, Version 2.0]
https://github.com/Kotlin/kotlinx.coroutines
Copyright 2022
Copyright 2023
JetBrains s.r.o.
- SLF4J - Simple facade or abstraction for various logging frameworks
[MIT License]
http://www.slf4j.org
Copyright 2022
https://www.slf4j.org
Copyright 2023
QOS.ch
- Logback - Logback is a logging framework for Java applications
[The Apache Software License, Version 2.0]
http://logback.qos.ch
Copyright 2022
https://logback.qos.ch
Copyright 2023
QOS.ch
- SSHJ - SSHv2 library for Java
[The Apache Software License, Version 2.0]
https://github.com/hierynomus/sshj
Copyright 2022
Copyright 2023
Jeroen van Erp
SSHJ Contributors
@ -414,13 +272,13 @@
- JZlib -
[The Apache Software License, Version 2.0]
http://www.jcraft.com/jzlib
https://github.com/ymnk/jzlib
Atsuhiko Yamanaka
JCraft, Inc.
- Bouncy Castle Crypto -
[The Apache Software License, Version 2.0]
http://www.bouncycastle.org
https://www.bouncycastle.org
The Legion of the Bouncy Castle Inc
- ed25519-java -
@ -443,169 +301,6 @@
Kotlin Compiler, Test Data+Libraries, and Tools repository contain third-party code, to which different licenses may apply
See: https://github.com/JetBrains/kotlin/blob/master/license/README.md
- NetworkUtils - Utilities for managing network configurations, IP/MAC address conversion, and ping (via OS native commands)
[The Apache Software License, Version 2.0]
https://git.dorkbox.com/dorkbox/NetworkUtils
Copyright 2022
Dorkbox LLC
Extra license information
- Netty -
[The Apache Software License, Version 2.0]
https://netty.io/
Copyright 2014
The Netty Project
This product contains a modified portion of Netty Network Utils
- Apache Harmony -
[The Apache Software License, Version 2.0]
http://archive.apache.org/dist/harmony/
Copyright 2010
The Apache Software Foundation
This product contains a modified portion of 'Apache Harmony', an open source Java SE
- Apache HTTP Utils -
[The Apache Software License, Version 2.0]
http://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/psl/
Copyright 2010
The Apache Software Foundation
This product contains a modified portion of 'PublicSuffixDomainFilter.java'
- SLF4J - Simple facade or abstraction for various logging frameworks
[MIT License]
http://www.slf4j.org
Copyright 2022
QOS.ch
- JNA - Simplified native library access for Java.
[The Apache Software License, Version 2.0]
https://github.com/twall/jna
Copyright 2022
Timothy Wall
- JNA-Platform - Mappings for a number of commonly used platform functions
[The Apache Software License, Version 2.0]
https://github.com/twall/jna
Copyright 2022
Timothy Wall
- Kotlin -
[The Apache Software License, Version 2.0]
https://github.com/JetBrains/kotlin
Copyright 2020
JetBrains s.r.o. and Kotlin Programming Language contributors
Kotlin Compiler, Test Data+Libraries, and Tools repository contain third-party code, to which different licenses may apply
See: https://github.com/JetBrains/kotlin/blob/master/license/README.md
- Executor - Shell, JVM, and SSH command execution on Linux, MacOS, or Windows for Java 8+
[The Apache Software License, Version 2.0]
https://git.dorkbox.com/dorkbox/Executor
Copyright 2022
Dorkbox LLC
Extra license information
- ZT Process Executor -
[The Apache Software License, Version 2.0]
https://github.com/zeroturnaround/zt-exec
Copyright 2014
ZeroTurnaround LLC
- Apache Commons Exec -
[The Apache Software License, Version 2.0]
https://commons.apache.org/proper/commons-exec/
Copyright 2014
The Apache Software Foundation
- Kotlin -
[The Apache Software License, Version 2.0]
https://github.com/JetBrains/kotlin
Copyright 2020
JetBrains s.r.o. and Kotlin Programming Language contributors
Kotlin Compiler, Test Data+Libraries, and Tools repository contain third-party code, to which different licenses may apply
See: https://github.com/JetBrains/kotlin/blob/master/license/README.md
- kotlinx.coroutines - Library support for Kotlin coroutines with multiplatform support
[The Apache Software License, Version 2.0]
https://github.com/Kotlin/kotlinx.coroutines
Copyright 2022
JetBrains s.r.o.
- SLF4J - Simple facade or abstraction for various logging frameworks
[MIT License]
http://www.slf4j.org
Copyright 2022
QOS.ch
- Logback - Logback is a logging framework for Java applications
[The Apache Software License, Version 2.0]
http://logback.qos.ch
Copyright 2022
QOS.ch
- SSHJ - SSHv2 library for Java
[The Apache Software License, Version 2.0]
https://github.com/hierynomus/sshj
Copyright 2022
Jeroen van Erp
SSHJ Contributors
Extra license information
- Apache MINA -
[The Apache Software License, Version 2.0]
https://mina.apache.org/sshd-project/
The Apache Software Foundation
- Apache Commons-Net -
[The Apache Software License, Version 2.0]
https://commons.apache.org/proper/commons-net/
The Apache Software Foundation
- JZlib -
[The Apache Software License, Version 2.0]
http://www.jcraft.com/jzlib
Atsuhiko Yamanaka
JCraft, Inc.
- Bouncy Castle Crypto -
[The Apache Software License, Version 2.0]
http://www.bouncycastle.org
The Legion of the Bouncy Castle Inc
- ed25519-java -
[Public Domain, per Creative Commons CC0]
https://github.com/str4d/ed25519-java
https://github.com/str4d
- Updates - Software Update Management
[The Apache Software License, Version 2.0]
https://git.dorkbox.com/dorkbox/Updates
Copyright 2021
Dorkbox LLC
Extra license information
- Kotlin -
[The Apache Software License, Version 2.0]
https://github.com/JetBrains/kotlin
Copyright 2020
JetBrains s.r.o. and Kotlin Programming Language contributors
Kotlin Compiler, Test Data+Libraries, and Tools repository contain third-party code, to which different licenses may apply
See: https://github.com/JetBrains/kotlin/blob/master/license/README.md
- Updates - Software Update Management
[The Apache Software License, Version 2.0]
https://git.dorkbox.com/dorkbox/Updates
Copyright 2021
Dorkbox LLC
Extra license information
- Kotlin -
[The Apache Software License, Version 2.0]
https://github.com/JetBrains/kotlin
Copyright 2020
JetBrains s.r.o. and Kotlin Programming Language contributors
Kotlin Compiler, Test Data+Libraries, and Tools repository contain third-party code, to which different licenses may apply
See: https://github.com/JetBrains/kotlin/blob/master/license/README.md
- OS - Information about the system, Java runtime, OS, Window Manager, and Desktop Environment.
[The Apache Software License, Version 2.0]
https://git.dorkbox.com/dorkbox/OS

View File

@ -1,22 +0,0 @@
BSD License
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL <ORGANIZATION> BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

View File

@ -1,5 +1,5 @@
/*
* Copyright 2021 dorkbox, llc
* Copyright 2023 dorkbox, llc
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -26,10 +26,12 @@ gradle.startParameter.showStacktrace = ShowStacktrace.ALWAYS // always show th
gradle.startParameter.warningMode = WarningMode.All
plugins {
id("com.dorkbox.GradleUtils") version "3.9"
id("com.dorkbox.Licensing") version "2.19.1"
id("com.dorkbox.VersionUpdate") version "2.5"
id("com.dorkbox.GradlePublish") version "1.17"
id("com.dorkbox.GradleUtils") version "3.17"
id("com.dorkbox.Licensing") version "2.25"
id("com.dorkbox.VersionUpdate") version "2.8"
id("com.dorkbox.GradlePublish") version "1.18"
kotlin("jvm") version "1.8.0"
}
object Extras {
@ -44,8 +46,6 @@ object Extras {
const val vendor = "Dorkbox LLC"
const val vendorUrl = "https://dorkbox.com"
const val url = "https://git.dorkbox.com/dorkbox/CabParser"
val buildDate = Instant.now().toString()
}
///////////////////////////////
@ -64,6 +64,19 @@ licensing {
}
}
// make java source available to kotlin
kotlin {
sourceSets {
main {
// we have some java we depend on
kotlin.include("**/*.java", "**/*.kt")
}
test {
kotlin.include("**/*.java", "**/*.kt")
}
}
}
tasks.jar.get().apply {
manifest {
// https://docs.oracle.com/javase/tutorial/deployment/jar/packageman.html
@ -74,15 +87,15 @@ tasks.jar.get().apply {
attributes["Specification-Vendor"] = Extras.vendor
attributes["Implementation-Title"] = "${Extras.group}.${Extras.id}"
attributes["Implementation-Version"] = Extras.buildDate
attributes["Implementation-Version"] = GradleUtils.now()
attributes["Implementation-Vendor"] = Extras.vendor
}
}
dependencies {
api("com.dorkbox:ByteUtilities:1.6")
api("com.dorkbox:ByteUtilities:1.13")
api("com.dorkbox:Updates:1.1")
api("com.dorkbox:Utilities:1.39")
api("com.dorkbox:Utilities:1.44")
}
publishToSonatype {

View File

@ -1,5 +1,5 @@
/*
* Copyright 2012 dorkbox, llc
* Copyright 2023 dorkbox, llc
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -13,15 +13,9 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package dorkbox.cabParser;
package dorkbox.cabParser
public class CabException extends Exception {
private static final long serialVersionUID = 1L;
public CabException(String errorMessage) {
super(errorMessage);
}
public CabException() {
}
open class CabException : Exception {
constructor(errorMessage: String?) : super(errorMessage)
constructor()
}

View File

@ -1,142 +0,0 @@
/*
* Copyright 2012 dorkbox, llc
*
* 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 dorkbox.cabParser;
import java.io.IOException;
import java.io.InputStream;
final class CabInputStream extends InputStream {
private InputStream inputStream;
private long position;
private long a;
private boolean markSupported;
@Override
public void close() throws IOException {
this.inputStream.close();
}
@Override
public synchronized void reset() throws IOException {
if (this.markSupported) {
this.inputStream.reset();
this.position = this.a;
return;
}
throw new IOException();
}
CabInputStream(InputStream inputStream) {
this.inputStream = inputStream;
this.position = 0L;
this.markSupported = this.inputStream.markSupported();
}
@Override
public int read() throws IOException {
int i = this.inputStream.read();
if (i >= 0) {
this.position += 1L;
}
return i;
}
@Override
public int read(byte[] bytes) throws IOException {
int i = this.inputStream.read(bytes);
if (i > 0) {
this.position += i;
}
return i;
}
@Override
public int read(byte[] bytes, int offset, int length) throws IOException {
int i = this.inputStream.read(bytes, offset, length);
if (i > 0) {
this.position += i;
}
return i;
}
@Override
public int available() throws IOException {
throw new IOException();
}
@Override
public synchronized void mark(int paramInt) {
if (this.markSupported) {
this.a = this.position;
this.inputStream.mark(paramInt);
}
}
public long getCurrentPosition() {
return this.position;
}
@Override
public boolean markSupported() {
return this.markSupported;
}
public void seek(long location) throws IOException {
if (location < this.position) {
throw new IOException("Cannot seek backwards");
}
if (location > this.position) {
skip(location - this.position);
}
}
@Override
public long skip(long ammount) throws IOException {
long l = betterSkip(this.inputStream, ammount);
this.position += (int) l;
return l;
}
/**
* Reliably skips over and discards n bytes of data from the input stream
* @param is input stream
* @param n the number of bytes to be skipped
* @return the actual number of bytes skipped
* @throws IOException
*/
public static long betterSkip(InputStream is, long n) throws IOException {
long left = n;
while(left > 0) {
long l = is.skip(left);
if(l > 0) {
left -= l;
} else if(l == 0) { // should we retry? lets read one byte
if(is.read() == -1) // EOF
break;
else
left--;
} else {
throw new IOException("skip() returned a negative value. This should never happen");
}
}
return n - left;
}
}

View File

@ -0,0 +1,141 @@
/*
* Copyright 2023 dorkbox, llc
*
* 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 dorkbox.cabParser
import java.io.IOException
import java.io.InputStream
internal class CabInputStream(private val inputStream: InputStream) : InputStream() {
companion object {
/**
* Reliably skips over and discards n bytes of data from the input stream
* @param is input stream
* @param n the number of bytes to be skipped
* @return the actual number of bytes skipped
*
* @throws IOException
*/
@Throws(IOException::class)
fun betterSkip(`is`: InputStream, n: Long): Long {
var left = n
while (left > 0) {
val l = `is`.skip(left)
if (l > 0) {
left -= l
}
else if (l == 0L) { // should we retry? lets read one byte
if (`is`.read() == -1) // EOF
break
else left--
}
else {
throw IOException("skip() returned a negative value. This should never happen")
}
}
return n - left
}
}
var currentPosition = 0L
private set
private var a: Long = 0
private val markSupported: Boolean
init {
markSupported = inputStream.markSupported()
}
@Throws(IOException::class)
override fun close() {
inputStream.close()
}
@Synchronized
@Throws(IOException::class)
override fun reset() {
if (markSupported) {
inputStream.reset()
currentPosition = a
return
}
throw IOException()
}
@Throws(IOException::class)
override fun read(): Int {
val i = inputStream.read()
if (i >= 0) {
currentPosition += 1L
}
return i
}
@Throws(IOException::class)
override fun read(bytes: ByteArray): Int {
val i = inputStream.read(bytes)
if (i > 0) {
currentPosition += i.toLong()
}
return i
}
@Throws(IOException::class)
override fun read(bytes: ByteArray, offset: Int, length: Int): Int {
val i = inputStream.read(bytes, offset, length)
if (i > 0) {
currentPosition += i.toLong()
}
return i
}
@Throws(IOException::class)
override fun available(): Int {
throw IOException()
}
@Synchronized
override fun mark(paramInt: Int) {
if (markSupported) {
a = currentPosition
inputStream.mark(paramInt)
}
}
override fun markSupported(): Boolean {
return markSupported
}
@Throws(IOException::class)
fun seek(location: Long) {
if (location < currentPosition) {
throw IOException("Cannot seek backwards")
}
if (location > currentPosition) {
skip(location - currentPosition)
}
}
@Throws(IOException::class)
override fun skip(ammount: Long): Long {
val l = betterSkip(inputStream, ammount)
currentPosition += l.toInt().toLong()
return l
}
}

View File

@ -1,207 +0,0 @@
/*
* Copyright 2012 dorkbox, llc
*
* 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 dorkbox.cabParser;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.File;
import java.util.Enumeration;
import dorkbox.cabParser.decompress.CabDecompressor;
import dorkbox.cabParser.structure.CabEnumerator;
import dorkbox.cabParser.structure.CabFileEntry;
import dorkbox.cabParser.structure.CabFolderEntry;
import dorkbox.cabParser.structure.CabHeader;
public final class CabParser {
/**
* Gets the version number.
*/
public static
String getVersion() {
return "3.2";
}
static {
// Add this project to the updates system, which verifies this class + UUID + version information
dorkbox.updates.Updates.INSTANCE.add(CabParser.class, "41f560ca51c04bfdbca21328e0cbf206", getVersion());
}
private CabInputStream cabInputStream;
private CabStreamSaver streamSaver;
private ByteArrayOutputStream outputStream = null;
public CabHeader header;
public CabFolderEntry[] folders;
public CabFileEntry[] files;
public
CabParser(InputStream inputStream, final String fileNameToExtract) throws CabException, IOException {
if (fileNameToExtract == null || fileNameToExtract.isEmpty()) {
throw new IllegalArgumentException("Filename must be valid!");
}
this.cabInputStream = new CabInputStream(inputStream);
this.streamSaver = new CabStreamSaver() {
@Override
public boolean saveReservedAreaData(byte[] data, int dataLength) {
return false;
}
@Override
public OutputStream openOutputStream(CabFileEntry cabFile) {
String name = cabFile.getName();
if (fileNameToExtract.equalsIgnoreCase(name)) {
CabParser.this.outputStream = new ByteArrayOutputStream((int) cabFile.getSize());
return CabParser.this.outputStream;
} else {
return null;
}
}
@Override
public void closeOutputStream(OutputStream outputStream, CabFileEntry cabFile) {
if (outputStream != null) {
try {
outputStream.close();
} catch (IOException ignored) {
}
}
}
};
readData();
}
public
CabParser(InputStream inputStream, CabStreamSaver streamSaver) throws CabException, IOException {
this.streamSaver = streamSaver;
this.cabInputStream = new CabInputStream(inputStream);
readData();
}
public
CabParser(InputStream inputStream, File extractPath) throws CabException, IOException {
this.streamSaver = new DefaultCabStreamSaver(extractPath);
this.cabInputStream = new CabInputStream(inputStream);
readData();
}
public Enumeration<Object> entries() {
return new CabEnumerator(this, false);
}
public Enumeration<Object> entries(boolean b) {
return new CabEnumerator(this, b);
}
private void readData() throws CabException, IOException {
this.header = new CabHeader(this.streamSaver);
this.header.read(this.cabInputStream);
this.folders = new CabFolderEntry[this.header.cFolders];
for (int i = 0; i < this.header.cFolders; i++) {
this.folders[i] = new CabFolderEntry();
this.folders[i].read(this.cabInputStream);
}
this.files = new CabFileEntry[this.header.cFiles];
this.cabInputStream.seek(this.header.coffFiles);
for (int i = 0; i < this.header.cFiles; i++) {
this.files[i] = new CabFileEntry();
this.files[i].read(this.cabInputStream);
}
}
public ByteArrayOutputStream extractStream() throws CabException, IOException {
int folderCount = -1;
int currentCount = 0;
int totalCount = 0;
boolean init = true;
CabDecompressor extractor = new CabDecompressor(this.cabInputStream, this.header.cbCFData);
for (int fileIndex = 0; fileIndex < this.header.cFiles; fileIndex++) {
CabFileEntry entry = this.files[fileIndex];
if (entry.iFolder != folderCount) {
if (folderCount + 1 >= this.header.cFolders) {
throw new CorruptCabException();
}
folderCount++;
init = true;
currentCount = 0;
totalCount = 0;
}
OutputStream localOutputStream = this.streamSaver.openOutputStream(entry);
if (localOutputStream != null) {
if (init) {
CabFolderEntry cabFolderEntry = this.folders[folderCount];
this.cabInputStream.seek(cabFolderEntry.coffCabStart);
extractor.initialize(cabFolderEntry.compressionMethod);
init = false;
}
if (currentCount != totalCount) {
extractor.read(totalCount - currentCount, new OutputStream() {
@Override
public
void write(int i) throws IOException {
//do nothing
}
@Override
public
void write(byte[] b) throws IOException {
//do nothing
}
@Override
public
void write(byte[] b, int off, int len) throws IOException {
//do nothing
}
@Override
public
void flush() throws IOException {
//do nothing
}
});
currentCount = totalCount;
}
extractor.read(entry.cbFile, localOutputStream);
this.streamSaver.closeOutputStream(localOutputStream, entry);
currentCount = (int) (currentCount + entry.cbFile);
}
totalCount = (int) (totalCount + entry.cbFile);
}
return this.outputStream;
}
}

View File

@ -0,0 +1,178 @@
/*
* Copyright 2023 dorkbox, llc
*
* 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 dorkbox.cabParser
import dorkbox.cabParser.decompress.CabDecompressor
import dorkbox.cabParser.structure.CabEnumerator
import dorkbox.cabParser.structure.CabFileEntry
import dorkbox.cabParser.structure.CabFolderEntry
import dorkbox.cabParser.structure.CabHeader
import dorkbox.updates.Updates.add
import java.io.*
import java.util.*
class CabParser {
companion object {
/**
* Gets the version number.
*/
const val version: String = "3.2"
init {
// Add this project to the updates system, which verifies this class + UUID + version information
add(CabParser::class.java, "41f560ca51c04bfdbca21328e0cbf206", version)
}
}
private var cabInputStream: CabInputStream
private var streamSaver: CabStreamSaver
private var outputStream: ByteArrayOutputStream? = null
lateinit var header: CabHeader
lateinit var folders: Array<CabFolderEntry>
lateinit var files: Array<CabFileEntry>
constructor(inputStream: InputStream, fileNameToExtract: String) {
cabInputStream = CabInputStream(inputStream)
streamSaver = object : CabStreamSaver {
override fun saveReservedAreaData(data: ByteArray?, dataLength: Int): Boolean {
return false
}
override fun openOutputStream(entry: CabFileEntry): OutputStream? {
val name = entry.name
return if (fileNameToExtract.equals(name, ignoreCase = true)) {
outputStream = ByteArrayOutputStream(entry.size.toInt())
outputStream!!
}
else {
null
}
}
override fun closeOutputStream(outputStream: OutputStream, cabFile: CabFileEntry) {
try {
outputStream.close()
}
catch (ignored: IOException) {
}
}
}
readData()
}
constructor(inputStream: InputStream, streamSaver: CabStreamSaver) {
this.streamSaver = streamSaver
cabInputStream = CabInputStream(inputStream)
readData()
}
constructor(inputStream: InputStream, extractPath: File?) {
streamSaver = DefaultCabStreamSaver(extractPath)
cabInputStream = CabInputStream(inputStream)
readData()
}
fun entries(): Enumeration<Any> {
return CabEnumerator(this, false)
}
fun entries(b: Boolean): Enumeration<Any> {
return CabEnumerator(this, b)
}
@Suppress("UNCHECKED_CAST")
@Throws(CabException::class, IOException::class)
private fun readData() {
header = CabHeader(streamSaver)
header.read(cabInputStream)
folders = arrayOfNulls<CabFolderEntry>(header.cFolders) as Array<CabFolderEntry>
for (i in 0 until header.cFolders) {
folders[i] = CabFolderEntry()
folders[i].read(cabInputStream)
}
files = arrayOfNulls<CabFileEntry>(header.cFiles) as Array<CabFileEntry>
cabInputStream.seek(header.coffFiles)
for (i in 0 until header.cFiles) {
files[i] = CabFileEntry()
files[i].read(cabInputStream)
}
}
@Throws(CabException::class, IOException::class)
fun extractStream(): ByteArrayOutputStream? {
var folderCount = -1
var currentCount = 0
var totalCount = 0
var init = true
val extractor = CabDecompressor(cabInputStream, header.cbCFData)
for (fileIndex in 0 until header.cFiles) {
val entry = files[fileIndex]
if (entry.iFolder != folderCount) {
if (folderCount + 1 >= header.cFolders) {
throw CorruptCabException()
}
folderCount++
init = true
currentCount = 0
totalCount = 0
}
val localOutputStream = streamSaver.openOutputStream(entry)
if (localOutputStream != null) {
if (init) {
val cabFolderEntry = folders[folderCount]
cabInputStream.seek(cabFolderEntry.coffCabStart)
extractor.initialize(cabFolderEntry.compressionMethod)
init = false
}
if (currentCount != totalCount) {
extractor.read((totalCount - currentCount).toLong(), object : OutputStream() {
@Throws(IOException::class)
override fun write(i: Int) {
//do nothing
}
@Throws(IOException::class)
override fun write(b: ByteArray) {
//do nothing
}
@Throws(IOException::class)
override fun write(b: ByteArray, off: Int, len: Int) {
//do nothing
}
@Throws(IOException::class)
override fun flush() {
//do nothing
}
})
currentCount = totalCount
}
extractor.read(entry.cbFile, localOutputStream)
streamSaver.closeOutputStream(localOutputStream, entry)
currentCount = (currentCount + entry.cbFile).toInt()
}
totalCount = (totalCount + entry.cbFile).toInt()
}
return outputStream
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright 2012 dorkbox, llc
* Copyright 2023 dorkbox, llc
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -13,14 +13,13 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package dorkbox.cabParser;
package dorkbox.cabParser
import java.io.OutputStream;
import dorkbox.cabParser.structure.CabFileEntry
import java.io.OutputStream
import dorkbox.cabParser.structure.CabFileEntry;
public interface CabStreamSaver {
OutputStream openOutputStream(CabFileEntry entry);
void closeOutputStream(OutputStream outputStream, CabFileEntry entry);
boolean saveReservedAreaData(byte[] data, int dataLength);
interface CabStreamSaver {
fun openOutputStream(entry: CabFileEntry): OutputStream?
fun closeOutputStream(outputStream: OutputStream, entry: CabFileEntry)
fun saveReservedAreaData(data: ByteArray?, dataLength: Int): Boolean
}

View File

@ -1,5 +1,5 @@
/*
* Copyright 2012 dorkbox, llc
* Copyright 2023 dorkbox, llc
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -13,16 +13,9 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package dorkbox.cabParser;
package dorkbox.cabParser
public final class CorruptCabException extends CabException {
private static final long serialVersionUID = 1L;
public CorruptCabException(String errorMessage) {
super(errorMessage);
}
public CorruptCabException() {
}
class CorruptCabException : CabException {
constructor(errorMessage: String?) : super(errorMessage)
constructor()
}

View File

@ -1,77 +0,0 @@
/*
* Copyright 2012 dorkbox, llc
*
* 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 dorkbox.cabParser;
import dorkbox.cabParser.structure.CabFileEntry;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.io.FileOutputStream;
import java.io.File;
import java.io.FileNotFoundException;
/**
* provide default CabStreamSaver
*/
public class DefaultCabStreamSaver implements CabStreamSaver{
private File extractPath;
public DefaultCabStreamSaver(File extractPath) throws CabException {
this.extractPath = extractPath;
if(extractPath!=null){
if(!extractPath.exists()){
extractPath.mkdirs();
}else if(!extractPath.isDirectory()){
throw new CabException("extractPath is not directory");
}
}
}
@Override
public OutputStream openOutputStream(CabFileEntry entry) {
return new ByteArrayOutputStream((int) entry.getSize());
}
@Override
public void closeOutputStream(OutputStream outputStream, CabFileEntry entry) {
if (outputStream != null) {
try {
ByteArrayOutputStream bos = (ByteArrayOutputStream)outputStream;
File cabEntityFile = new File(extractPath, entry.getName().replace("\\", File.separator));
cabEntityFile.getParentFile().mkdirs();
FileOutputStream fileOutputStream = new FileOutputStream(cabEntityFile);
try {
bos.writeTo(fileOutputStream);
} finally {
fileOutputStream.close();
}
} catch (FileNotFoundException e) {
} catch (IOException e) {
} finally {
try {
outputStream.close();
} catch (IOException e) {
}
}
}
}
@Override
public boolean saveReservedAreaData(byte[] data, int dataLength) {
return false;
}
}

View File

@ -0,0 +1,69 @@
/*
* Copyright 2023 dorkbox, llc
*
* 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 dorkbox.cabParser
import dorkbox.cabParser.structure.CabFileEntry
import java.io.*
/**
* provide default CabStreamSaver
*/
class DefaultCabStreamSaver(private val extractPath: File?) : CabStreamSaver {
init {
if (extractPath != null) {
if (!extractPath.exists()) {
extractPath.mkdirs()
}
else if (!extractPath.isDirectory()) {
throw CabException("extractPath is not directory")
}
}
}
override fun openOutputStream(entry: CabFileEntry): OutputStream? {
return ByteArrayOutputStream(entry.size.toInt())
}
override fun closeOutputStream(outputStream: OutputStream, entry: CabFileEntry) {
try {
val bos = outputStream as ByteArrayOutputStream
val cabEntityFile = File(extractPath, entry.name.replace("\\", File.separator))
cabEntityFile.getParentFile().mkdirs()
val fileOutputStream = FileOutputStream(cabEntityFile)
try {
bos.writeTo(fileOutputStream)
}
finally {
fileOutputStream.close()
}
}
catch (e: FileNotFoundException) {