├── .editorconfig ├── .gitignore ├── .travis.yml ├── COPYING.LESSER ├── LICENSE-2.0.txt ├── README.md ├── build.gradle ├── buildSrc └── src │ └── main │ ├── groovy │ └── foo │ │ └── DetectSplitPackagesPlugin.groovy │ └── resources │ └── META-INF │ └── gradle-plugins │ └── detect-split-packages.properties ├── config ├── checkstyle │ ├── checkstyle.xml │ └── suppressions.xml ├── javadoc.options ├── javadoc10.options └── pmd │ └── ruleSet.xml ├── dependencyDefinitions.gradle ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── licenseTemplateLGPL.java ├── miscJars ├── InstallJLayer.txt ├── jl1.0.jar └── jlayer-pom.xml ├── projectDependencies.gradle ├── settings.gradle ├── sulky-blobs └── src │ ├── main │ └── java │ │ └── de │ │ └── huxhorn │ │ └── sulky │ │ └── blobs │ │ ├── AmbiguousIdException.java │ │ ├── BlobRepository.java │ │ └── impl │ │ └── BlobRepositoryImpl.java │ └── test │ ├── java │ └── de │ │ └── huxhorn │ │ └── sulky │ │ └── blobs │ │ ├── AmbiguousIdExceptionTest.java │ │ └── impl │ │ └── BlobRepositoryImplTest.java │ └── resources │ └── logback-test.xml ├── sulky-buffers-filtering └── src │ └── main │ └── java │ └── de │ └── huxhorn │ └── sulky │ └── buffers │ └── filtering │ ├── FilteringBuffer.java │ └── FilteringCallable.java ├── sulky-buffers-table └── src │ ├── main │ └── java │ │ └── de │ │ └── huxhorn │ │ └── sulky │ │ └── buffers │ │ └── table │ │ └── BufferTableModel.java │ └── test │ └── resources │ └── logback-test.xml ├── sulky-buffers └── src │ ├── main │ └── java │ │ └── de │ │ └── huxhorn │ │ └── sulky │ │ └── buffers │ │ ├── AppendOperation.java │ │ ├── BasicBufferIterator.java │ │ ├── BlockingCircularBuffer.java │ │ ├── Buffer.java │ │ ├── CircularBuffer.java │ │ ├── Dispose.java │ │ ├── DisposeOperation.java │ │ ├── ElementProcessor.java │ │ ├── FileBuffer.java │ │ ├── Flush.java │ │ ├── FlushOperation.java │ │ ├── OverwritingCircularBuffer.java │ │ ├── RemoveOperation.java │ │ ├── Reset.java │ │ ├── ResetOperation.java │ │ ├── SerializingFileBuffer.java │ │ ├── SetOperation.java │ │ └── SoftReferenceCachingBuffer.java │ └── test │ ├── java │ └── de │ │ └── huxhorn │ │ └── sulky │ │ └── buffers │ │ ├── OverwritingCircularBufferTest.java │ │ └── SerializingFileBufferTest.java │ └── resources │ └── logback-test.xml ├── sulky-codec-filebuffer ├── regenerate ├── regenerate.bat └── src │ ├── main │ ├── java │ │ └── de │ │ │ └── huxhorn │ │ │ └── sulky │ │ │ └── codec │ │ │ └── filebuffer │ │ │ ├── CodecFileBuffer.java │ │ │ ├── DataStrategy.java │ │ │ ├── DefaultDataStrategy.java │ │ │ ├── DefaultFileHeaderStrategy.java │ │ │ ├── DefaultIndexStrategy.java │ │ │ ├── FileHeader.java │ │ │ ├── FileHeaderStrategy.java │ │ │ ├── IndexStrategy.java │ │ │ ├── MetaData.java │ │ │ ├── MetaDataCodec.java │ │ │ ├── MetaDataDecoder.java │ │ │ ├── MetaDataEncoder.java │ │ │ ├── ReadOnlyExclusiveCodecFileBuffer.java │ │ │ ├── SparseDataStrategy.java │ │ │ └── generated │ │ │ └── MetaDataProto.java │ └── protobuf │ │ └── MetaDataProto.proto │ └── test │ ├── groovy │ └── de │ │ └── huxhorn │ │ └── sulky │ │ └── codec │ │ └── filebuffer │ │ ├── CodecFileBufferSpec.groovy │ │ ├── DataStrategySpecBase.groovy │ │ ├── DefaultDataStrategySpec.groovy │ │ ├── DefaultFileHeaderStrategySpec.groovy │ │ ├── DefaultIndexStrategySpec.groovy │ │ ├── MetaDataSpec.groovy │ │ └── SparseDataStrategySpec.groovy │ └── resources │ └── logback-test.xml ├── sulky-codec └── src │ ├── main │ └── java │ │ └── de │ │ └── huxhorn │ │ └── sulky │ │ └── codec │ │ ├── Codec.java │ │ ├── CompressingSerializableCodec.java │ │ ├── Decoder.java │ │ ├── DelegatingCodecBase.java │ │ ├── Encoder.java │ │ ├── EnumPersistenceDelegate.java │ │ ├── SerializableCodec.java │ │ ├── SerializableDecoder.java │ │ ├── SerializableEncoder.java │ │ ├── XmlDecoder.java │ │ ├── XmlEncoder.java │ │ └── streaming │ │ ├── DecoderBridge.java │ │ ├── DelegatingStreamingCodecBase.java │ │ ├── EncoderBridge.java │ │ ├── GZIPStreamingDecoderWrapper.java │ │ ├── GZIPStreamingEncoderWrapper.java │ │ ├── StreamingCodec.java │ │ ├── StreamingDecoder.java │ │ ├── StreamingEncoder.java │ │ └── StreamingSerializableCodec.java │ └── test │ └── java │ └── de │ └── huxhorn │ └── sulky │ └── codec │ ├── CompressingSerializableCodecTest.java │ ├── SerializableCodecTest.java │ ├── XmlCodecTest.java │ └── streaming │ ├── GZIPStreamingWrapperTest.java │ └── StreamingSerializableCodecTest.java ├── sulky-conditions └── src │ ├── main │ └── java │ │ └── de │ │ └── huxhorn │ │ └── sulky │ │ └── conditions │ │ ├── And.java │ │ ├── BooleanValues.java │ │ ├── Condition.java │ │ ├── ConditionGroup.java │ │ ├── ConditionWrapper.java │ │ ├── Conditions.java │ │ ├── Not.java │ │ └── Or.java │ └── test │ ├── java │ └── de │ │ └── huxhorn │ │ └── sulky │ │ └── conditions │ │ ├── AndTest.java │ │ ├── BooleanValuesTest.java │ │ ├── ConditionTestBase.java │ │ ├── ConditionsTest.java │ │ ├── NotTest.java │ │ └── OrTest.java │ └── resources │ └── logback-test.xml ├── sulky-formatting └── src │ ├── main │ └── java │ │ └── de │ │ └── huxhorn │ │ └── sulky │ │ └── formatting │ │ ├── HumanReadable.java │ │ ├── ReplaceInvalidXmlCharacterReader.java │ │ ├── SafeString.java │ │ └── SimpleXml.java │ └── test │ ├── groovy │ └── de │ │ └── huxhorn │ │ └── sulky │ │ └── formatting │ │ ├── HumanReadableSpec.groovy │ │ ├── ReplaceInvalidXmlCharacterReaderSpec.groovy │ │ ├── SafeStringSpec.groovy │ │ └── SimpleXmlSpec.groovy │ └── resources │ └── logback-test.xml ├── sulky-generics └── src │ ├── main │ └── java │ │ └── de │ │ └── huxhorn │ │ └── sulky │ │ └── generics │ │ ├── GenericWrapper.java │ │ └── Wrapper.java │ └── test │ └── groovy │ └── de │ └── huxhorn │ └── sulky │ └── generics │ └── GenericWrapperSpec.groovy ├── sulky-groovy └── src │ ├── main │ └── java │ │ └── de │ │ └── huxhorn │ │ └── sulky │ │ └── groovy │ │ └── GroovyInstance.java │ └── test │ ├── java │ └── de │ │ └── huxhorn │ │ └── sulky │ │ └── groovy │ │ └── GroovyInstanceTest.java │ └── resources │ ├── Bar.groovy │ ├── Broken.b0rken │ ├── Foo.groovy │ └── logback-test.xml ├── sulky-io └── src │ ├── main │ └── java │ │ └── de │ │ └── huxhorn │ │ └── sulky │ │ └── io │ │ ├── IOUtilities.java │ │ └── TimeoutOutputStream.java │ └── test │ └── java │ └── de │ └── huxhorn │ └── sulky │ └── io │ └── TimeoutOutputStreamTest.java ├── sulky-junit └── src │ ├── main │ └── java │ │ └── de │ │ └── huxhorn │ │ └── sulky │ │ └── junit │ │ ├── JUnitTools.java │ │ └── LoggingTestBase.java │ └── test │ ├── groovy │ └── de │ │ └── huxhorn │ │ └── sulky │ │ └── junit │ │ ├── JUnitToolsSpec.groovy │ │ └── LoggingTestBaseExampleTest.java │ └── resources │ └── logback-test.xml ├── sulky-logging └── src │ ├── main │ └── java │ │ └── de │ │ └── huxhorn │ │ └── sulky │ │ └── logging │ │ ├── LoggingPropertyChangeListener.java │ │ └── SwingLogging.java │ └── test │ ├── groovy │ └── de │ │ └── huxhorn │ │ └── sulky │ │ └── logging │ │ └── LoggingPropertyChangeListenerSpec.groovy │ └── resources │ └── logback-test.xml ├── sulky-plist └── src │ ├── main │ └── java │ │ └── de │ │ └── huxhorn │ │ └── sulky │ │ └── plist │ │ ├── PropertyList.java │ │ ├── PropertyListDecoder.java │ │ ├── PropertyListEncoder.java │ │ └── impl │ │ ├── PropertyListConstants.java │ │ ├── PropertyListReader.java │ │ └── PropertyListWriter.java │ └── test │ ├── java │ └── de │ │ └── huxhorn │ │ └── sulky │ │ └── plist │ │ └── PropertyListIOTest.java │ └── resources │ └── logback-test.xml ├── sulky-resources ├── licenseTemplateLGPL.java └── src │ ├── main │ └── java │ │ ├── de │ │ └── huxhorn │ │ │ └── sulky │ │ │ └── resources │ │ │ ├── CyclicLinkException.java │ │ │ ├── Localizable.java │ │ │ ├── LocalizableFactory.java │ │ │ ├── MapLoader.java │ │ │ ├── PathTools.java │ │ │ ├── ResourceMaps.java │ │ │ ├── ResourceSupport.java │ │ │ ├── Resources.java │ │ │ └── package.html │ │ └── overview.html │ └── test │ ├── java │ ├── PackagelessTest.java │ └── de │ │ └── huxhorn │ │ └── sulky │ │ └── resources │ │ ├── LocalizableFactoryTest.java │ │ ├── PathToolsTest.java │ │ ├── ResourceMapsTest.java │ │ ├── ResourceSupportTest.java │ │ ├── ResourceTestHelper.java │ │ ├── ResourcesTest.java │ │ └── junit │ │ ├── BaseClass.java │ │ └── Foobar.java │ └── resources │ ├── de │ └── huxhorn │ │ └── sulky │ │ └── resources │ │ └── junit │ │ ├── BaseClass │ │ ├── baseFallback.txt │ │ ├── overloaded.txt │ │ └── resources.properties │ │ ├── Foobar │ │ ├── Internal │ │ │ └── test.txt │ │ ├── StaticInternal │ │ │ ├── de │ │ │ │ └── test.txt │ │ │ └── test.txt │ │ ├── cyclic1.link │ │ ├── cyclic2.link │ │ ├── cyclic3.link │ │ ├── cyclicFallback1 │ │ ├── cyclicFallback1.link │ │ ├── cyclicFallback2.link │ │ ├── cyclicFallback3.link │ │ ├── de │ │ │ ├── locale.html │ │ │ └── locale.txt │ │ ├── de_DE │ │ │ ├── locale.html │ │ │ ├── locale.txt │ │ │ └── resources.properties │ │ ├── de_DE_hessisch │ │ │ ├── locale.txt │ │ │ └── resources.properties │ │ ├── defaultFallback.txt.link │ │ ├── en │ │ │ └── locale.txt │ │ ├── en_US │ │ │ └── locale.txt │ │ ├── link.txt.link │ │ ├── locale.txt │ │ ├── overloaded.txt │ │ ├── resources.properties │ │ └── test.txt │ │ └── defaultFallback.txt │ └── logback-test.xml ├── sulky-sounds-api └── src │ └── main │ └── java │ └── de │ └── huxhorn │ └── sulky │ └── sounds │ └── Sounds.java ├── sulky-sounds-impl-jlayer └── src │ └── main │ └── java │ └── de │ └── huxhorn │ └── sulky │ └── sounds │ └── jlayer │ └── JLayerSounds.java ├── sulky-stax └── src │ ├── main │ └── java │ │ └── de │ │ └── huxhorn │ │ └── sulky │ │ └── stax │ │ ├── DateTimeFormatter.java │ │ ├── GenericStreamReader.java │ │ ├── GenericStreamWriter.java │ │ ├── IndentingXMLStreamWriter.java │ │ ├── StaxUtilities.java │ │ └── WhiteSpaceHandling.java │ └── test │ ├── groovy │ └── de │ │ └── huxhorn │ │ └── sulky │ │ └── stax │ │ └── DateTimeFormatterSpec.groovy │ └── java │ └── de │ └── huxhorn │ └── sulky │ └── stax │ └── StaxUtilitiesTest.java ├── sulky-swing └── src │ ├── main │ └── java │ │ └── de │ │ └── huxhorn │ │ └── sulky │ │ └── swing │ │ ├── GraphicsUtilities.java │ │ ├── KeyStrokes.java │ │ ├── ListComboBoxModel.java │ │ ├── MemoryStatus.java │ │ ├── PersistentTableColumnModel.java │ │ ├── PropertyChangeWrapper.java │ │ ├── RowBasedTableModel.java │ │ ├── Tables.java │ │ ├── Windows.java │ │ └── filters │ │ ├── AbstractFilter.java │ │ └── ColorTintFilter.java │ └── test │ └── groovy │ └── de │ └── huxhorn │ └── sulky │ └── swing │ └── KeyStrokesSpec.groovy ├── sulky-tasks └── src │ ├── main │ └── java │ │ └── de │ │ └── huxhorn │ │ └── sulky │ │ └── tasks │ │ ├── AbstractProgressingCallable.java │ │ ├── ProgressingCallable.java │ │ ├── Task.java │ │ ├── TaskListener.java │ │ ├── TaskManager.java │ │ └── package-info.java │ └── test │ ├── java │ └── de │ │ └── huxhorn │ │ └── sulky │ │ └── tasks │ │ └── TaskManagerTest.java │ └── resources │ └── logback-test.xml ├── sulky-ulid ├── README.md └── src │ ├── jmh │ └── java │ │ └── de │ │ └── huxhorn │ │ └── sulky │ │ └── ulid │ │ └── ULIDBenchmark.java │ ├── main │ └── java │ │ └── de │ │ └── huxhorn │ │ └── sulky │ │ └── ulid │ │ └── ULID.java │ └── test │ └── groovy │ └── de │ └── huxhorn │ └── sulky │ └── ulid │ └── ULIDSpec.groovy └── sulky-version └── src ├── main └── java │ └── de │ └── huxhorn │ └── sulky │ └── version │ ├── ClassFileScanner.java │ ├── ClassFileVersion.java │ ├── ClassStatisticMapper.java │ ├── JavaVersion.java │ ├── Jep223JavaVersion.java │ ├── Main.java │ ├── SemanticVersion.java │ ├── YeOldeJavaVersion.java │ └── mappers │ ├── DuplicateClassMapper.java │ ├── HighestVersionMapper.java │ ├── PackageVersionMapper.java │ └── SourceVersionMapper.java └── test ├── groovy └── de │ └── huxhorn │ └── sulky │ └── version │ ├── ClassFileScannerSpec.groovy │ ├── ClassFileVersionSpec.groovy │ ├── ExceptionMainClass.java │ ├── JUnitTools.java │ ├── JavaVersionInitSpec.groovy │ ├── JavaVersionSpec.groovy │ ├── Jep223JavaVersionSpec.groovy │ ├── MainSpec.groovy │ ├── MissingMainClass.java │ ├── NonPublicMainClass.java │ ├── SemanticVersionSpec.groovy │ ├── TestMainClass.java │ ├── TestSecurityManager.java │ ├── YeOldeJavaVersionSpec.groovy │ └── mappers │ ├── AbstractMapperSpec.groovy │ ├── DuplicateClassMapperSpec.groovy │ ├── HighestVersionMapperSpec.groovy │ ├── PackageVersionMapperSpec.groovy │ └── SourceVersionMapperSpec.groovy └── resources ├── classNotFound.properties ├── exceptionMain.properties ├── foo.jar ├── invalidJavaVersion.properties ├── main.properties ├── malformed.properties ├── missingJavaVersion.properties ├── missingMain.properties ├── missingMainClass.properties ├── nonPublicMain.properties ├── slf4j-api-1.7.10.jar ├── slf4j-api-1.7.9.jar └── versionMismatch.properties /.editorconfig: -------------------------------------------------------------------------------- 1 | # editorconfig.org 2 | 3 | root = true 4 | 5 | [*] 6 | indent_style = tab 7 | 8 | end_of_line = lf 9 | charset = utf-8 10 | trim_trailing_whitespace = true 11 | insert_final_newline = true 12 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | build 2 | .gradle 3 | target 4 | .DS_Store 5 | .idea 6 | *.iml 7 | *.iws 8 | *.ipr 9 | /out/ 10 | /.gradletasknamecache -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | sudo: false 2 | language: java 3 | 4 | jdk: 5 | - openjdk8 6 | - openjdk11 7 | 8 | env: 9 | - TERM=dumb 10 | 11 | cache: 12 | directories: 13 | - $HOME/.gradle 14 | 15 | #before_install: 16 | # - rm -r ~/.gradle/caches 17 | 18 | script: 19 | - ./gradlew --stacktrace 20 | - git clone https://github.com/huxi/lilith.git ~/builds/lilith 21 | - pushd ~/builds/lilith 22 | - git checkout $TRAVIS_BRANCH 23 | - ./gradlew --stacktrace install 24 | - popd 25 | 26 | after_success: 27 | - ./gradlew --stacktrace cleanTest 28 | - ./gradlew --stacktrace jacocoRootReport 29 | - ./gradlew --stacktrace coveralls 30 | - bash <(curl -s https://codecov.io/bash) 31 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # sulky Modules [![Build Status](https://travis-ci.com/huxi/sulky.png?branch=master)](https://travis-ci.com/huxi/sulky) [![Coverage Status](https://coveralls.io/repos/huxi/sulky/badge.png)](https://coveralls.io/r/huxi/sulky) [![Maven Central](https://img.shields.io/maven-central/v/de.huxhorn.sulky/de.huxhorn.sulky.ulid.svg)](http://search.maven.org/#search%7Cga%7C1%7Cg%3A%22de.huxhorn.sulky%22) 2 | 3 | sulky is the umbrella project for several general purpose modules used by Lilith. 4 | In contrast to Lilith, sulky modules are licensed LGPLv3 & ASLv2. 5 | -------------------------------------------------------------------------------- /buildSrc/src/main/resources/META-INF/gradle-plugins/detect-split-packages.properties: -------------------------------------------------------------------------------- 1 | implementation-class=foo.DetectSplitPackagesPlugin -------------------------------------------------------------------------------- /config/checkstyle/checkstyle.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | -------------------------------------------------------------------------------- /config/checkstyle/suppressions.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /config/javadoc.options: -------------------------------------------------------------------------------- 1 | -encoding UTF-8 2 | -------------------------------------------------------------------------------- /config/javadoc10.options: -------------------------------------------------------------------------------- 1 | -encoding UTF-8 -html5 2 | -------------------------------------------------------------------------------- /dependencyDefinitions.gradle: -------------------------------------------------------------------------------- 1 | project.ext.versions = [ 2 | 'bytebuddy': '1.12.3', 3 | 'groovy': '2.5.15', 4 | 'logback': '1.2.8', 5 | 'protobuf': '3.19.1', 6 | 'slf4j': '1.7.32', 7 | 'spock': '1.3-groovy-2.5' 8 | ] 9 | 10 | project.ext.libraries = [ 11 | 'byte-buddy': "net.bytebuddy:byte-buddy:${versions.bytebuddy}", 12 | 'commons-codec': 'commons-codec:commons-codec:1.15', 13 | 'commons-io': 'commons-io:commons-io:2.11.0', 14 | 'easymock': 'org.easymock:easymock:3.6', 15 | 'groovy': "org.codehaus.groovy:groovy:${versions.groovy}", 16 | 'jcl-over-slf4j': "org.slf4j:jcl-over-slf4j:${versions.slf4j}", 17 | 'jlayer': 'de.huxhorn.sulky:de.huxhorn.sulky.3rdparty.jlayer:1.0', 18 | 'junit': 'junit:junit:4.13.2', 19 | 'logback-access': "ch.qos.logback:logback-access:${versions.logback}", 20 | 'logback-classic': "ch.qos.logback:logback-classic:${versions.logback}", 21 | 'logback-core': "ch.qos.logback:logback-core:${versions.logback}", 22 | 'protobuf': "com.google.protobuf:protobuf-java:${versions.protobuf}", 23 | 'slf4j-api': "org.slf4j:slf4j-api:${versions.slf4j}", 24 | 'spock-core': "org.spockframework:spock-core:${versions.spock}" 25 | ] 26 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huxi/sulky/27c8d809f2e3af6eafa9c7324f158cd9b482b351/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-6.8.1-bin.zip 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @rem 2 | @rem Copyright 2015 the original author or authors. 3 | @rem 4 | @rem Licensed under the Apache License, Version 2.0 (the "License"); 5 | @rem you may not use this file except in compliance with the License. 6 | @rem You may obtain a copy of the License at 7 | @rem 8 | @rem https://www.apache.org/licenses/LICENSE-2.0 9 | @rem 10 | @rem Unless required by applicable law or agreed to in writing, software 11 | @rem distributed under the License is distributed on an "AS IS" BASIS, 12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | @rem See the License for the specific language governing permissions and 14 | @rem limitations under the License. 15 | @rem 16 | 17 | @if "%DEBUG%" == "" @echo off 18 | @rem ########################################################################## 19 | @rem 20 | @rem Gradle startup script for Windows 21 | @rem 22 | @rem ########################################################################## 23 | 24 | @rem Set local scope for the variables with windows NT shell 25 | if "%OS%"=="Windows_NT" setlocal 26 | 27 | set DIRNAME=%~dp0 28 | if "%DIRNAME%" == "" set DIRNAME=. 29 | set APP_BASE_NAME=%~n0 30 | set APP_HOME=%DIRNAME% 31 | 32 | @rem Resolve any "." and ".." in APP_HOME to make it shorter. 33 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi 34 | 35 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 36 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" 37 | 38 | @rem Find java.exe 39 | if defined JAVA_HOME goto findJavaFromJavaHome 40 | 41 | set JAVA_EXE=java.exe 42 | %JAVA_EXE% -version >NUL 2>&1 43 | if "%ERRORLEVEL%" == "0" goto execute 44 | 45 | echo. 46 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 47 | echo. 48 | echo Please set the JAVA_HOME variable in your environment to match the 49 | echo location of your Java installation. 50 | 51 | goto fail 52 | 53 | :findJavaFromJavaHome 54 | set JAVA_HOME=%JAVA_HOME:"=% 55 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 56 | 57 | if exist "%JAVA_EXE%" goto execute 58 | 59 | echo. 60 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 61 | echo. 62 | echo Please set the JAVA_HOME variable in your environment to match the 63 | echo location of your Java installation. 64 | 65 | goto fail 66 | 67 | :execute 68 | @rem Setup the command line 69 | 70 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 71 | 72 | 73 | @rem Execute Gradle 74 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* 75 | 76 | :end 77 | @rem End local scope for the variables with windows NT shell 78 | if "%ERRORLEVEL%"=="0" goto mainEnd 79 | 80 | :fail 81 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 82 | rem the _cmd.exe /c_ return code! 83 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 84 | exit /b 1 85 | 86 | :mainEnd 87 | if "%OS%"=="Windows_NT" endlocal 88 | 89 | :omega 90 | -------------------------------------------------------------------------------- /licenseTemplateLGPL.java: -------------------------------------------------------------------------------- 1 | /* 2 | * sulky-modules - several general-purpose modules. 3 | * Copyright (C) 2007-2011 Joern Huxhorn 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Lesser General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | /* 20 | * Copyright 2007-2011 Joern Huxhorn 21 | * 22 | * Licensed under the Apache License, Version 2.0 (the "License"); 23 | * you may not use this file except in compliance with the License. 24 | * You may obtain a copy of the License at 25 | * 26 | * http://www.apache.org/licenses/LICENSE-2.0 27 | * 28 | * Unless required by applicable law or agreed to in writing, software 29 | * distributed under the License is distributed on an "AS IS" BASIS, 30 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 31 | * See the License for the specific language governing permissions and 32 | * limitations under the License. 33 | */ 34 | 35 | -------------------------------------------------------------------------------- /miscJars/InstallJLayer.txt: -------------------------------------------------------------------------------- 1 | Execute the following line: 2 | mvn install:install-file -Dpackaging=jar -DcreateChecksum=true -DgeneratePom=true -DgroupId=de.huxhorn.sulky -DartifactId=de.huxhorn.sulky.3rdparty.jlayer -Dversion=1.0 -Dfile=jl1.0.jar 3 | 4 | mvn deploy:deploy-file -Durl=scp://shell.sourceforge.net/home/groups/s/su/sulky/htdocs/repository -DrepositoryId=sulky-repos -Dfile=jl1.0.jar -DpomFile=jlayer-pom.xml 5 | -------------------------------------------------------------------------------- /miscJars/jl1.0.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huxi/sulky/27c8d809f2e3af6eafa9c7324f158cd9b482b351/miscJars/jl1.0.jar -------------------------------------------------------------------------------- /miscJars/jlayer-pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | de.huxhorn.sulky 6 | de.huxhorn.sulky.3rdparty.jlayer 7 | 1.0 8 | jar 9 | Javazoom JLayer MP3 Library 10 | This is the third-party library JLayer that isn't available in the central maven repository. 11 | http://www.javazoom.net/javalayer/javalayer.html 12 | 13 | 14 | GNU Lesser General Public License (LGPL) 15 | http://www.gnu.org/copyleft/lesser.html 16 | repo 17 | 18 | 19 | 20 | 21 | scm:svn:https://sulky.svn.sourceforge.net/svnroot/sulky/trunk/sulky-sounds-impl-jlayer/miscJars 22 | scm:svn:https://sulky.svn.sourceforge.net/svnroot/sulky/trunk/sulky-sounds-impl-jlayer/miscJars 23 | http://sulky.svn.sourceforge.net/viewvc/sulky/trunk/sulky-sounds-impl-jlayer/miscJars 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include 'sulky-version' 2 | include 'sulky-blobs' 3 | include 'sulky-buffers' 4 | include 'sulky-buffers-filtering' 5 | include 'sulky-buffers-table' 6 | include 'sulky-codec' 7 | include 'sulky-codec-filebuffer' 8 | include 'sulky-conditions' 9 | include 'sulky-formatting' 10 | include 'sulky-generics' 11 | include 'sulky-groovy' 12 | include 'sulky-io' 13 | include 'sulky-junit' 14 | include 'sulky-logging' 15 | include 'sulky-plist' 16 | include 'sulky-resources' 17 | include 'sulky-sounds-api' 18 | include 'sulky-sounds-impl-jlayer' 19 | include 'sulky-stax' 20 | include 'sulky-swing' 21 | include 'sulky-tasks' 22 | include 'sulky-ulid' 23 | -------------------------------------------------------------------------------- /sulky-blobs/src/main/java/de/huxhorn/sulky/blobs/AmbiguousIdException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * sulky-modules - several general-purpose modules. 3 | * Copyright (C) 2007-2018 Joern Huxhorn 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Lesser General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | /* 20 | * Copyright 2007-2018 Joern Huxhorn 21 | * 22 | * Licensed under the Apache License, Version 2.0 (the "License"); 23 | * you may not use this file except in compliance with the License. 24 | * You may obtain a copy of the License at 25 | * 26 | * http://www.apache.org/licenses/LICENSE-2.0 27 | * 28 | * Unless required by applicable law or agreed to in writing, software 29 | * distributed under the License is distributed on an "AS IS" BASIS, 30 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 31 | * See the License for the specific language governing permissions and 32 | * limitations under the License. 33 | */ 34 | 35 | package de.huxhorn.sulky.blobs; 36 | 37 | import java.util.Arrays; 38 | 39 | /** 40 | * This exception is thrown by BlobRepository implementations if an id used to reference a blob could reference more than 41 | * one blob. 42 | */ 43 | public class AmbiguousIdException 44 | extends Exception 45 | { 46 | private static final long serialVersionUID = -4288324439851962675L; 47 | 48 | private final String id; 49 | private final String[] candidates; 50 | 51 | public AmbiguousIdException(String id, String[] candidates) 52 | { 53 | super("The id '"+id+"' does not uniquely identify a blob. Candidates are: "+ Arrays.toString(candidates)); 54 | this.id = id; 55 | if(candidates == null) 56 | { 57 | throw new IllegalArgumentException("candidates must not be null!"); 58 | } 59 | this.candidates = new String[candidates.length]; 60 | System.arraycopy(candidates, 0, this.candidates, 0, candidates.length); 61 | } 62 | 63 | /** 64 | * Returns the id that caused this exception. 65 | * 66 | * @return the id that caused this exception. 67 | */ 68 | public String getId() 69 | { 70 | return id; 71 | } 72 | 73 | /** 74 | * Returns the ids of possible blob candidates. 75 | * 76 | * @return the ids of possible blob candidates. 77 | */ 78 | public String[] getCandidates() 79 | { 80 | String[] result=new String[this.candidates.length]; 81 | System.arraycopy(this.candidates, 0, result, 0, this.candidates.length); 82 | return result; 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /sulky-blobs/src/test/java/de/huxhorn/sulky/blobs/AmbiguousIdExceptionTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * sulky-modules - several general-purpose modules. 3 | * Copyright (C) 2007-2019 Joern Huxhorn 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Lesser General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | /* 20 | * Copyright 2007-2019 Joern Huxhorn 21 | * 22 | * Licensed under the Apache License, Version 2.0 (the "License"); 23 | * you may not use this file except in compliance with the License. 24 | * You may obtain a copy of the License at 25 | * 26 | * http://www.apache.org/licenses/LICENSE-2.0 27 | * 28 | * Unless required by applicable law or agreed to in writing, software 29 | * distributed under the License is distributed on an "AS IS" BASIS, 30 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 31 | * See the License for the specific language governing permissions and 32 | * limitations under the License. 33 | */ 34 | 35 | package de.huxhorn.sulky.blobs; 36 | 37 | import org.junit.Test; 38 | 39 | import static org.junit.Assert.assertArrayEquals; 40 | import static org.junit.Assert.assertEquals; 41 | import static org.junit.Assert.assertNotSame; 42 | 43 | public class AmbiguousIdExceptionTest 44 | { 45 | @SuppressWarnings({"ThrowableInstanceNeverThrown"}) 46 | @Test 47 | public void normal() 48 | { 49 | String[] candidates = {"foo", "bar"}; 50 | AmbiguousIdException ex=new AmbiguousIdException("id", candidates); 51 | assertEquals("id", ex.getId()); 52 | assertArrayEquals(candidates, ex.getCandidates()); 53 | assertNotSame(candidates, ex.getCandidates()); 54 | } 55 | 56 | @SuppressWarnings({"ThrowableInstanceNeverThrown"}) 57 | @Test (expected = IllegalArgumentException.class) 58 | public void error() 59 | { 60 | new AmbiguousIdException("id", null); 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /sulky-blobs/src/test/resources/logback-test.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | %-5level - %d{HH:mm:ss.SSS} [%thread] - %file:%line - %msg%n%ex{full} 7 | 8 | 9 | 10 | 17 | 18 | 19 | 20 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /sulky-buffers-table/src/test/resources/logback-test.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | %-5level - %d{HH:mm:ss.SSS} [%thread] - %file:%line - %msg%n%ex{full} 7 | 8 | 9 | 10 | 18 | 19 | 20 | 21 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /sulky-buffers/src/main/java/de/huxhorn/sulky/buffers/AppendOperation.java: -------------------------------------------------------------------------------- 1 | /* 2 | * sulky-modules - several general-purpose modules. 3 | * Copyright (C) 2007-2011 Joern Huxhorn 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Lesser General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | /* 20 | * Copyright 2007-2011 Joern Huxhorn 21 | * 22 | * Licensed under the Apache License, Version 2.0 (the "License"); 23 | * you may not use this file except in compliance with the License. 24 | * You may obtain a copy of the License at 25 | * 26 | * http://www.apache.org/licenses/LICENSE-2.0 27 | * 28 | * Unless required by applicable law or agreed to in writing, software 29 | * distributed under the License is distributed on an "AS IS" BASIS, 30 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 31 | * See the License for the specific language governing permissions and 32 | * limitations under the License. 33 | */ 34 | 35 | package de.huxhorn.sulky.buffers; 36 | 37 | import java.util.List; 38 | 39 | public interface AppendOperation 40 | { 41 | /** 42 | * Adds the given element. 43 | * 44 | * @param element to add. 45 | */ 46 | void add(E element); 47 | 48 | /** 49 | * Adds all the given elements. 50 | * 51 | * @param elements to add. 52 | */ 53 | void addAll(List elements); 54 | 55 | /** 56 | * Adds all the given elements. 57 | * 58 | * @param elements to add. 59 | */ 60 | void addAll(E[] elements); 61 | 62 | boolean isFull(); 63 | } 64 | -------------------------------------------------------------------------------- /sulky-buffers/src/main/java/de/huxhorn/sulky/buffers/BasicBufferIterator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * sulky-modules - several general-purpose modules. 3 | * Copyright (C) 2007-2017 Joern Huxhorn 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Lesser General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | /* 20 | * Copyright 2007-2017 Joern Huxhorn 21 | * 22 | * Licensed under the Apache License, Version 2.0 (the "License"); 23 | * you may not use this file except in compliance with the License. 24 | * You may obtain a copy of the License at 25 | * 26 | * http://www.apache.org/licenses/LICENSE-2.0 27 | * 28 | * Unless required by applicable law or agreed to in writing, software 29 | * distributed under the License is distributed on an "AS IS" BASIS, 30 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 31 | * See the License for the specific language governing permissions and 32 | * limitations under the License. 33 | */ 34 | 35 | package de.huxhorn.sulky.buffers; 36 | 37 | import java.util.Iterator; 38 | import java.util.NoSuchElementException; 39 | import java.util.Objects; 40 | 41 | public class BasicBufferIterator 42 | implements Iterator 43 | { 44 | private final Buffer buffer; 45 | private final long size; 46 | private long current; 47 | 48 | public BasicBufferIterator(Buffer buffer) 49 | { 50 | this.buffer = Objects.requireNonNull(buffer, "buffer must not be null!"); 51 | this.size = buffer.getSize(); 52 | this.current = 0; 53 | } 54 | 55 | @Override 56 | public boolean hasNext() 57 | { 58 | return current < size; 59 | } 60 | 61 | @Override 62 | public E next() 63 | { 64 | if(!hasNext()) 65 | { 66 | throw new NoSuchElementException("Iterator doesn't have more entries"); 67 | } 68 | E result = buffer.get(current); 69 | current++; 70 | return result; 71 | } 72 | 73 | @Override 74 | public void remove() 75 | { 76 | throw new UnsupportedOperationException("Buffer does not support removal of arbitrary elements!"); 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /sulky-buffers/src/main/java/de/huxhorn/sulky/buffers/Buffer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * sulky-modules - several general-purpose modules. 3 | * Copyright (C) 2007-2011 Joern Huxhorn 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Lesser General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | /* 20 | * Copyright 2007-2011 Joern Huxhorn 21 | * 22 | * Licensed under the Apache License, Version 2.0 (the "License"); 23 | * you may not use this file except in compliance with the License. 24 | * You may obtain a copy of the License at 25 | * 26 | * http://www.apache.org/licenses/LICENSE-2.0 27 | * 28 | * Unless required by applicable law or agreed to in writing, software 29 | * distributed under the License is distributed on an "AS IS" BASIS, 30 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 31 | * See the License for the specific language governing permissions and 32 | * limitations under the License. 33 | */ 34 | 35 | package de.huxhorn.sulky.buffers; 36 | 37 | public interface Buffer 38 | extends Iterable 39 | { 40 | /** 41 | * Returns the value at the given index. 42 | * index must be in the range [0..(getSize()-1)]. 43 | * Returns null if a value couldn't be resolved, e.g. in case of a volatile buffer. 44 | * 45 | * @param index must be in the range [0..(getSize()-1)]. 46 | * @return the value at the given index. 47 | */ 48 | E get(long index); 49 | 50 | /** 51 | * @return the size of the buffer. 52 | */ 53 | long getSize(); 54 | } 55 | -------------------------------------------------------------------------------- /sulky-buffers/src/main/java/de/huxhorn/sulky/buffers/CircularBuffer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * sulky-modules - several general-purpose modules. 3 | * Copyright (C) 2007-2014 Joern Huxhorn 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Lesser General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | /* 20 | * Copyright 2007-2014 Joern Huxhorn 21 | * 22 | * Licensed under the Apache License, Version 2.0 (the "License"); 23 | * you may not use this file except in compliance with the License. 24 | * You may obtain a copy of the License at 25 | * 26 | * http://www.apache.org/licenses/LICENSE-2.0 27 | * 28 | * Unless required by applicable law or agreed to in writing, software 29 | * distributed under the License is distributed on an "AS IS" BASIS, 30 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 31 | * See the License for the specific language governing permissions and 32 | * limitations under the License. 33 | */ 34 | 35 | package de.huxhorn.sulky.buffers; 36 | 37 | public interface CircularBuffer 38 | extends Buffer, AppendOperation, RemoveOperation, ResetOperation 39 | { 40 | /** 41 | * Returns the element at the given index. index must be in the 42 | * range [0..(getAvailableElements()-1)]. 43 | * 44 | * @param index must be in the range [0..(getAvailableElements()-1)]. 45 | * @return the entry. 46 | */ 47 | E getRelative(int index); 48 | 49 | /** 50 | * Sets the element at the given index. index must be in the 51 | * range [0..(getAvailableElements()-1)]. 52 | * 53 | * @param element the element to be set. 54 | * @param index must be in the range [0..(getAvailableElements()-1)]. 55 | * @return the previous entry. 56 | */ 57 | E setRelative(int index, E element); 58 | 59 | long getOverflowCounter(); 60 | 61 | int getAvailableElements(); 62 | 63 | int getBufferSize(); 64 | } 65 | -------------------------------------------------------------------------------- /sulky-buffers/src/main/java/de/huxhorn/sulky/buffers/Dispose.java: -------------------------------------------------------------------------------- 1 | /* 2 | * sulky-modules - several general-purpose modules. 3 | * Copyright (C) 2007-2011 Joern Huxhorn 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Lesser General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | /* 20 | * Copyright 2007-2011 Joern Huxhorn 21 | * 22 | * Licensed under the Apache License, Version 2.0 (the "License"); 23 | * you may not use this file except in compliance with the License. 24 | * You may obtain a copy of the License at 25 | * 26 | * http://www.apache.org/licenses/LICENSE-2.0 27 | * 28 | * Unless required by applicable law or agreed to in writing, software 29 | * distributed under the License is distributed on an "AS IS" BASIS, 30 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 31 | * See the License for the specific language governing permissions and 32 | * limitations under the License. 33 | */ 34 | 35 | package de.huxhorn.sulky.buffers; 36 | 37 | public final class Dispose 38 | { 39 | private Dispose() 40 | {} 41 | 42 | /** 43 | * Executes dispose() on the given object if it implements DisposeOperation. Does nothing otherwise. 44 | * 45 | * @param obj an object that might implement DisposeOperation 46 | * @return true if dispose() has been called. 47 | */ 48 | public static boolean dispose(Object obj) 49 | { 50 | if(obj instanceof DisposeOperation) 51 | { 52 | DisposeOperation dispose = (DisposeOperation) obj; 53 | dispose.dispose(); 54 | return true; 55 | } 56 | return false; 57 | } 58 | 59 | /** 60 | * @param obj an object that might implement DisposeOperation 61 | * @return false if obj does not implement DisposeOperation, obj.isDisposed() otherwise. 62 | */ 63 | public static boolean isDisposed(Object obj) 64 | { 65 | if(obj instanceof DisposeOperation) 66 | { 67 | DisposeOperation dispose = (DisposeOperation) obj; 68 | return dispose.isDisposed(); 69 | } 70 | return false; 71 | } 72 | 73 | } 74 | -------------------------------------------------------------------------------- /sulky-buffers/src/main/java/de/huxhorn/sulky/buffers/DisposeOperation.java: -------------------------------------------------------------------------------- 1 | /* 2 | * sulky-modules - several general-purpose modules. 3 | * Copyright (C) 2007-2011 Joern Huxhorn 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Lesser General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | /* 20 | * Copyright 2007-2011 Joern Huxhorn 21 | * 22 | * Licensed under the Apache License, Version 2.0 (the "License"); 23 | * you may not use this file except in compliance with the License. 24 | * You may obtain a copy of the License at 25 | * 26 | * http://www.apache.org/licenses/LICENSE-2.0 27 | * 28 | * Unless required by applicable law or agreed to in writing, software 29 | * distributed under the License is distributed on an "AS IS" BASIS, 30 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 31 | * See the License for the specific language governing permissions and 32 | * limitations under the License. 33 | */ 34 | 35 | package de.huxhorn.sulky.buffers; 36 | 37 | public interface DisposeOperation 38 | { 39 | void dispose(); 40 | 41 | boolean isDisposed(); 42 | } 43 | -------------------------------------------------------------------------------- /sulky-buffers/src/main/java/de/huxhorn/sulky/buffers/ElementProcessor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * sulky-modules - several general-purpose modules. 3 | * Copyright (C) 2007-2011 Joern Huxhorn 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Lesser General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | /* 20 | * Copyright 2007-2011 Joern Huxhorn 21 | * 22 | * Licensed under the Apache License, Version 2.0 (the "License"); 23 | * you may not use this file except in compliance with the License. 24 | * You may obtain a copy of the License at 25 | * 26 | * http://www.apache.org/licenses/LICENSE-2.0 27 | * 28 | * Unless required by applicable law or agreed to in writing, software 29 | * distributed under the License is distributed on an "AS IS" BASIS, 30 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 31 | * See the License for the specific language governing permissions and 32 | * limitations under the License. 33 | */ 34 | 35 | package de.huxhorn.sulky.buffers; 36 | 37 | import java.util.List; 38 | 39 | public interface ElementProcessor 40 | { 41 | void processElement(E element); 42 | void processElements(List element); 43 | } 44 | -------------------------------------------------------------------------------- /sulky-buffers/src/main/java/de/huxhorn/sulky/buffers/FileBuffer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * sulky-modules - several general-purpose modules. 3 | * Copyright (C) 2007-2011 Joern Huxhorn 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Lesser General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | /* 20 | * Copyright 2007-2011 Joern Huxhorn 21 | * 22 | * Licensed under the Apache License, Version 2.0 (the "License"); 23 | * you may not use this file except in compliance with the License. 24 | * You may obtain a copy of the License at 25 | * 26 | * http://www.apache.org/licenses/LICENSE-2.0 27 | * 28 | * Unless required by applicable law or agreed to in writing, software 29 | * distributed under the License is distributed on an "AS IS" BASIS, 30 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 31 | * See the License for the specific language governing permissions and 32 | * limitations under the License. 33 | */ 34 | 35 | package de.huxhorn.sulky.buffers; 36 | 37 | import java.io.File; 38 | 39 | public interface FileBuffer 40 | extends Buffer, AppendOperation, ResetOperation 41 | { 42 | File getDataFile(); 43 | } 44 | -------------------------------------------------------------------------------- /sulky-buffers/src/main/java/de/huxhorn/sulky/buffers/Flush.java: -------------------------------------------------------------------------------- 1 | /* 2 | * sulky-modules - several general-purpose modules. 3 | * Copyright (C) 2007-2011 Joern Huxhorn 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Lesser General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | /* 20 | * Copyright 2007-2011 Joern Huxhorn 21 | * 22 | * Licensed under the Apache License, Version 2.0 (the "License"); 23 | * you may not use this file except in compliance with the License. 24 | * You may obtain a copy of the License at 25 | * 26 | * http://www.apache.org/licenses/LICENSE-2.0 27 | * 28 | * Unless required by applicable law or agreed to in writing, software 29 | * distributed under the License is distributed on an "AS IS" BASIS, 30 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 31 | * See the License for the specific language governing permissions and 32 | * limitations under the License. 33 | */ 34 | 35 | package de.huxhorn.sulky.buffers; 36 | 37 | public final class Flush 38 | { 39 | private Flush() 40 | {} 41 | 42 | /** 43 | * Executes flush() on the given object if it implements FlushOperation. Does nothing otherwise. 44 | * 45 | * @param obj an object that might implement FlushOperation 46 | * @return true if flush() has been called. 47 | */ 48 | public static boolean flush(Object obj) 49 | { 50 | if(obj instanceof FlushOperation) 51 | { 52 | FlushOperation flush = (FlushOperation) obj; 53 | flush.flush(); 54 | return true; 55 | } 56 | return false; 57 | } 58 | 59 | } 60 | -------------------------------------------------------------------------------- /sulky-buffers/src/main/java/de/huxhorn/sulky/buffers/FlushOperation.java: -------------------------------------------------------------------------------- 1 | /* 2 | * sulky-modules - several general-purpose modules. 3 | * Copyright (C) 2007-2011 Joern Huxhorn 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Lesser General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | /* 20 | * Copyright 2007-2011 Joern Huxhorn 21 | * 22 | * Licensed under the Apache License, Version 2.0 (the "License"); 23 | * you may not use this file except in compliance with the License. 24 | * You may obtain a copy of the License at 25 | * 26 | * http://www.apache.org/licenses/LICENSE-2.0 27 | * 28 | * Unless required by applicable law or agreed to in writing, software 29 | * distributed under the License is distributed on an "AS IS" BASIS, 30 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 31 | * See the License for the specific language governing permissions and 32 | * limitations under the License. 33 | */ 34 | 35 | package de.huxhorn.sulky.buffers; 36 | 37 | public interface FlushOperation 38 | { 39 | void flush(); 40 | } 41 | -------------------------------------------------------------------------------- /sulky-buffers/src/main/java/de/huxhorn/sulky/buffers/RemoveOperation.java: -------------------------------------------------------------------------------- 1 | /* 2 | * sulky-modules - several general-purpose modules. 3 | * Copyright (C) 2007-2011 Joern Huxhorn 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Lesser General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | /* 20 | * Copyright 2007-2011 Joern Huxhorn 21 | * 22 | * Licensed under the Apache License, Version 2.0 (the "License"); 23 | * you may not use this file except in compliance with the License. 24 | * You may obtain a copy of the License at 25 | * 26 | * http://www.apache.org/licenses/LICENSE-2.0 27 | * 28 | * Unless required by applicable law or agreed to in writing, software 29 | * distributed under the License is distributed on an "AS IS" BASIS, 30 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 31 | * See the License for the specific language governing permissions and 32 | * limitations under the License. 33 | */ 34 | 35 | package de.huxhorn.sulky.buffers; 36 | 37 | import java.util.List; 38 | 39 | public interface RemoveOperation 40 | { 41 | E removeFirst(); 42 | 43 | List removeAll(); 44 | 45 | void clear(); 46 | 47 | boolean isEmpty(); 48 | } 49 | -------------------------------------------------------------------------------- /sulky-buffers/src/main/java/de/huxhorn/sulky/buffers/Reset.java: -------------------------------------------------------------------------------- 1 | /* 2 | * sulky-modules - several general-purpose modules. 3 | * Copyright (C) 2007-2011 Joern Huxhorn 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Lesser General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | /* 20 | * Copyright 2007-2011 Joern Huxhorn 21 | * 22 | * Licensed under the Apache License, Version 2.0 (the "License"); 23 | * you may not use this file except in compliance with the License. 24 | * You may obtain a copy of the License at 25 | * 26 | * http://www.apache.org/licenses/LICENSE-2.0 27 | * 28 | * Unless required by applicable law or agreed to in writing, software 29 | * distributed under the License is distributed on an "AS IS" BASIS, 30 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 31 | * See the License for the specific language governing permissions and 32 | * limitations under the License. 33 | */ 34 | 35 | package de.huxhorn.sulky.buffers; 36 | 37 | public final class Reset 38 | { 39 | private Reset() 40 | {} 41 | 42 | /** 43 | * Executes reset() on the given object if it implements ResetOperation. Does nothing otherwise. 44 | * 45 | * @param obj an object that might implement ResetOperation 46 | * @return true if reset() has been called. 47 | */ 48 | public static boolean reset(Object obj) 49 | { 50 | if(obj instanceof ResetOperation) 51 | { 52 | ResetOperation reset = (ResetOperation) obj; 53 | reset.reset(); 54 | return true; 55 | } 56 | return false; 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /sulky-buffers/src/main/java/de/huxhorn/sulky/buffers/ResetOperation.java: -------------------------------------------------------------------------------- 1 | /* 2 | * sulky-modules - several general-purpose modules. 3 | * Copyright (C) 2007-2011 Joern Huxhorn 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Lesser General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | /* 20 | * Copyright 2007-2011 Joern Huxhorn 21 | * 22 | * Licensed under the Apache License, Version 2.0 (the "License"); 23 | * you may not use this file except in compliance with the License. 24 | * You may obtain a copy of the License at 25 | * 26 | * http://www.apache.org/licenses/LICENSE-2.0 27 | * 28 | * Unless required by applicable law or agreed to in writing, software 29 | * distributed under the License is distributed on an "AS IS" BASIS, 30 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 31 | * See the License for the specific language governing permissions and 32 | * limitations under the License. 33 | */ 34 | 35 | package de.huxhorn.sulky.buffers; 36 | 37 | public interface ResetOperation 38 | { 39 | void reset(); 40 | } 41 | -------------------------------------------------------------------------------- /sulky-buffers/src/main/java/de/huxhorn/sulky/buffers/SetOperation.java: -------------------------------------------------------------------------------- 1 | /* 2 | * sulky-modules - several general-purpose modules. 3 | * Copyright (C) 2007-2011 Joern Huxhorn 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Lesser General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | /* 20 | * Copyright 2007-2011 Joern Huxhorn 21 | * 22 | * Licensed under the Apache License, Version 2.0 (the "License"); 23 | * you may not use this file except in compliance with the License. 24 | * You may obtain a copy of the License at 25 | * 26 | * http://www.apache.org/licenses/LICENSE-2.0 27 | * 28 | * Unless required by applicable law or agreed to in writing, software 29 | * distributed under the License is distributed on an "AS IS" BASIS, 30 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 31 | * See the License for the specific language governing permissions and 32 | * limitations under the License. 33 | */ 34 | 35 | package de.huxhorn.sulky.buffers; 36 | 37 | public interface SetOperation 38 | { 39 | /** 40 | * Set the element at the given index to object. 41 | * 42 | * @param index the index of the given object 43 | * @param object the object to be set at index 44 | * @return true if the object could be set at the given index, false if that was not possible (for example because that spot was already used and the buffer is a write-once buffer) 45 | * @throws UnsupportedOperationException if isSetSupported returns false. 46 | */ 47 | boolean set(long index, E object); 48 | 49 | /** 50 | * @return true if set is currently supported by this instance, false otherwise. 51 | */ 52 | boolean isSetSupported(); 53 | } 54 | -------------------------------------------------------------------------------- /sulky-buffers/src/test/resources/logback-test.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | %-5level - %d{HH:mm:ss.SSS} [%thread] - %file:%line - %msg%n%ex{full} 7 | 8 | 9 | 10 | 18 | 19 | 20 | 21 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /sulky-codec-filebuffer/regenerate: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | protoc --java_out=src/main/java src/main/protobuf/MetaDataProto.proto 3 | 4 | -------------------------------------------------------------------------------- /sulky-codec-filebuffer/regenerate.bat: -------------------------------------------------------------------------------- 1 | protoc --java_out=src\main\java src\main\protobuf\MetaDataProto.proto 2 | -------------------------------------------------------------------------------- /sulky-codec-filebuffer/src/main/java/de/huxhorn/sulky/codec/filebuffer/DataStrategy.java: -------------------------------------------------------------------------------- 1 | /* 2 | * sulky-modules - several general-purpose modules. 3 | * Copyright (C) 2007-2019 Joern Huxhorn 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Lesser General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | /* 20 | * Copyright 2007-2019 Joern Huxhorn 21 | * 22 | * Licensed under the Apache License, Version 2.0 (the "License"); 23 | * you may not use this file except in compliance with the License. 24 | * You may obtain a copy of the License at 25 | * 26 | * http://www.apache.org/licenses/LICENSE-2.0 27 | * 28 | * Unless required by applicable law or agreed to in writing, software 29 | * distributed under the License is distributed on an "AS IS" BASIS, 30 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 31 | * See the License for the specific language governing permissions and 32 | * limitations under the License. 33 | */ 34 | 35 | package de.huxhorn.sulky.codec.filebuffer; 36 | 37 | import de.huxhorn.sulky.codec.Codec; 38 | import java.io.IOException; 39 | import java.io.RandomAccessFile; 40 | import java.util.List; 41 | 42 | public interface DataStrategy 43 | { 44 | void add(E element, 45 | RandomAccessFile indexFile, 46 | RandomAccessFile dataFile, 47 | Codec codec, 48 | IndexStrategy indexStrategy) 49 | throws IOException; 50 | 51 | 52 | void addAll(List elements, 53 | RandomAccessFile indexFile, 54 | RandomAccessFile dataFile, 55 | Codec codec, 56 | IndexStrategy indexStrategy) 57 | throws IOException; 58 | 59 | boolean set(long index, E element, 60 | RandomAccessFile indexFile, 61 | RandomAccessFile dataFile, 62 | Codec codec, 63 | IndexStrategy indexStrategy) 64 | throws IOException; 65 | 66 | boolean isSetSupported(); 67 | 68 | E get(long index, 69 | RandomAccessFile indexFile, 70 | RandomAccessFile dataFile, 71 | Codec codec, 72 | IndexStrategy indexStrategy) 73 | throws IOException, ClassNotFoundException; 74 | } 75 | -------------------------------------------------------------------------------- /sulky-codec-filebuffer/src/main/java/de/huxhorn/sulky/codec/filebuffer/DefaultIndexStrategy.java: -------------------------------------------------------------------------------- 1 | /* 2 | * sulky-modules - several general-purpose modules. 3 | * Copyright (C) 2007-2011 Joern Huxhorn 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Lesser General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | /* 20 | * Copyright 2007-2011 Joern Huxhorn 21 | * 22 | * Licensed under the Apache License, Version 2.0 (the "License"); 23 | * you may not use this file except in compliance with the License. 24 | * You may obtain a copy of the License at 25 | * 26 | * http://www.apache.org/licenses/LICENSE-2.0 27 | * 28 | * Unless required by applicable law or agreed to in writing, software 29 | * distributed under the License is distributed on an "AS IS" BASIS, 30 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 31 | * See the License for the specific language governing permissions and 32 | * limitations under the License. 33 | */ 34 | 35 | package de.huxhorn.sulky.codec.filebuffer; 36 | 37 | import java.io.IOException; 38 | import java.io.RandomAccessFile; 39 | 40 | public class DefaultIndexStrategy 41 | implements IndexStrategy 42 | { 43 | public static final long DATA_OFFSET_SIZE = 8; 44 | 45 | @Override 46 | public void setOffset(RandomAccessFile indexFile, long index, long offset) 47 | throws IOException 48 | { 49 | long offsetOffset = DATA_OFFSET_SIZE * index; 50 | long fileLength = indexFile.length(); 51 | if(fileLength < offsetOffset) 52 | { 53 | // extend file, filling with -1 54 | long lastIndex = fileLength / DATA_OFFSET_SIZE; 55 | indexFile.seek(lastIndex * DATA_OFFSET_SIZE); // this copes with malformed files 56 | for(long i = lastIndex; i < index; i++) 57 | { 58 | indexFile.writeLong(-1L); 59 | } 60 | } 61 | indexFile.seek(offsetOffset); 62 | indexFile.writeLong(offset); 63 | } 64 | 65 | @Override 66 | public long getOffset(RandomAccessFile indexFile, long index) 67 | throws IOException 68 | { 69 | if(index < 0) 70 | { 71 | return -1; 72 | } 73 | long offsetOffset = DATA_OFFSET_SIZE * index; 74 | if(indexFile.length() < offsetOffset + DATA_OFFSET_SIZE) 75 | { 76 | return -1; 77 | } 78 | indexFile.seek(offsetOffset); 79 | return indexFile.readLong(); 80 | } 81 | 82 | @Override 83 | public long getSize(RandomAccessFile indexFile) 84 | throws IOException 85 | { 86 | //if(logger.isDebugEnabled()) logger.debug("size={}", result); 87 | return indexFile.length() / DATA_OFFSET_SIZE; 88 | } 89 | 90 | } 91 | -------------------------------------------------------------------------------- /sulky-codec-filebuffer/src/main/java/de/huxhorn/sulky/codec/filebuffer/FileHeaderStrategy.java: -------------------------------------------------------------------------------- 1 | /* 2 | * sulky-modules - several general-purpose modules. 3 | * Copyright (C) 2007-2011 Joern Huxhorn 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Lesser General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | /* 20 | * Copyright 2007-2011 Joern Huxhorn 21 | * 22 | * Licensed under the Apache License, Version 2.0 (the "License"); 23 | * you may not use this file except in compliance with the License. 24 | * You may obtain a copy of the License at 25 | * 26 | * http://www.apache.org/licenses/LICENSE-2.0 27 | * 28 | * Unless required by applicable law or agreed to in writing, software 29 | * distributed under the License is distributed on an "AS IS" BASIS, 30 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 31 | * See the License for the specific language governing permissions and 32 | * limitations under the License. 33 | */ 34 | 35 | package de.huxhorn.sulky.codec.filebuffer; 36 | 37 | import java.io.File; 38 | import java.io.IOException; 39 | import java.util.Map; 40 | 41 | public interface FileHeaderStrategy 42 | { 43 | /** 44 | * @param dataFile the file to read the magic value from. 45 | * @return the magic value of the file if it is compatible, null otherwise. 46 | * @throws java.io.IOException in case of IOException :p 47 | */ 48 | Integer readMagicValue(File dataFile) 49 | throws IOException; 50 | 51 | /** 52 | * @param dataFile the file to write the header to. Must be empty or nonexistent. 53 | * @param magicValue the magic value of the file. 54 | * @param sparse if the file is supposed to support sparse entries. 55 | * @param metaData the meta data of the file, can be null. 56 | * @return the written FileHeader 57 | * @throws IllegalArgumentException if file exists and isn't empty. 58 | * @throws java.io.IOException in case of IOException :p 59 | */ 60 | FileHeader writeFileHeader(File dataFile, int magicValue, Map metaData, boolean sparse) 61 | throws IOException; 62 | 63 | /** 64 | * @param dataFile the file to read the header from. 65 | * @return the FileHeader read from the file. 66 | * @throws java.io.IOException in case of IOException :p 67 | */ 68 | FileHeader readFileHeader(File dataFile) 69 | throws IOException; 70 | 71 | int getMinimalSize(); 72 | } 73 | -------------------------------------------------------------------------------- /sulky-codec-filebuffer/src/main/java/de/huxhorn/sulky/codec/filebuffer/IndexStrategy.java: -------------------------------------------------------------------------------- 1 | /* 2 | * sulky-modules - several general-purpose modules. 3 | * Copyright (C) 2007-2011 Joern Huxhorn 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Lesser General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | /* 20 | * Copyright 2007-2011 Joern Huxhorn 21 | * 22 | * Licensed under the Apache License, Version 2.0 (the "License"); 23 | * you may not use this file except in compliance with the License. 24 | * You may obtain a copy of the License at 25 | * 26 | * http://www.apache.org/licenses/LICENSE-2.0 27 | * 28 | * Unless required by applicable law or agreed to in writing, software 29 | * distributed under the License is distributed on an "AS IS" BASIS, 30 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 31 | * See the License for the specific language governing permissions and 32 | * limitations under the License. 33 | */ 34 | 35 | package de.huxhorn.sulky.codec.filebuffer; 36 | 37 | import java.io.IOException; 38 | import java.io.RandomAccessFile; 39 | 40 | public interface IndexStrategy 41 | { 42 | void setOffset(RandomAccessFile indexFile, long index, long offset) 43 | throws IOException; 44 | 45 | long getOffset(RandomAccessFile indexFile, long index) 46 | throws IOException; 47 | 48 | long getSize(RandomAccessFile indexFile) 49 | throws IOException; 50 | } 51 | -------------------------------------------------------------------------------- /sulky-codec-filebuffer/src/main/java/de/huxhorn/sulky/codec/filebuffer/MetaDataCodec.java: -------------------------------------------------------------------------------- 1 | package de.huxhorn.sulky.codec.filebuffer; 2 | 3 | import de.huxhorn.sulky.codec.DelegatingCodecBase; 4 | 5 | public class MetaDataCodec 6 | extends DelegatingCodecBase 7 | { 8 | public MetaDataCodec() 9 | { 10 | super(new MetaDataEncoder(true), new MetaDataDecoder(true)); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /sulky-codec-filebuffer/src/main/protobuf/MetaDataProto.proto: -------------------------------------------------------------------------------- 1 | /* 2 | * sulky-modules - several general-purpose modules. 3 | * Copyright (C) 2007-2016 Joern Huxhorn 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Lesser General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program. If not, see . 17 | */ 18 | syntax = "proto2"; 19 | 20 | package de.huxhorn.sulky.codec.filebuffer; 21 | 22 | option optimize_for = SPEED; 23 | 24 | option java_package = "de.huxhorn.sulky.codec.filebuffer.generated"; 25 | //option java_multiple_files = true; 26 | 27 | message MetaData { 28 | repeated MapEntry entry = 1; 29 | optional bool sparse = 2 [default = false]; 30 | } 31 | 32 | message MapEntry { 33 | required string key = 1; 34 | optional string value = 2; 35 | } 36 | 37 | -------------------------------------------------------------------------------- /sulky-codec-filebuffer/src/test/groovy/de/huxhorn/sulky/codec/filebuffer/DefaultDataStrategySpec.groovy: -------------------------------------------------------------------------------- 1 | /* 2 | * sulky-modules - several general-purpose modules. 3 | * Copyright (C) 2007-2018 Joern Huxhorn 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Lesser General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | /* 20 | * Copyright 2007-2018 Joern Huxhorn 21 | * 22 | * Licensed under the Apache License, Version 2.0 (the "License"); 23 | * you may not use this file except in compliance with the License. 24 | * You may obtain a copy of the License at 25 | * 26 | * http://www.apache.org/licenses/LICENSE-2.0 27 | * 28 | * Unless required by applicable law or agreed to in writing, software 29 | * distributed under the License is distributed on an "AS IS" BASIS, 30 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 31 | * See the License for the specific language governing permissions and 32 | * limitations under the License. 33 | */ 34 | 35 | package de.huxhorn.sulky.codec.filebuffer 36 | 37 | class DefaultDataStrategySpec 38 | extends DataStrategySpecBase { 39 | 40 | @Override 41 | void initInstance() { 42 | instance = new DefaultDataStrategy() 43 | } 44 | 45 | def "set"() { 46 | when: 47 | instance.set(0, null, null, null, null, null) 48 | 49 | then: 50 | thrown(UnsupportedOperationException) 51 | } 52 | 53 | def "isSetSupported"() { 54 | expect: 55 | !instance.isSetSupported() 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /sulky-codec-filebuffer/src/test/groovy/de/huxhorn/sulky/codec/filebuffer/DefaultFileHeaderStrategySpec.groovy: -------------------------------------------------------------------------------- 1 | package de.huxhorn.sulky.codec.filebuffer 2 | 3 | import spock.lang.Specification 4 | import spock.lang.Unroll 5 | 6 | public class DefaultFileHeaderStrategySpec 7 | extends Specification { 8 | 9 | int magicValue = 0xDEADBEEF 10 | 11 | File file 12 | DefaultFileHeaderStrategy instance 13 | 14 | def setup() { 15 | file = File.createTempFile("DFHS", "test"); 16 | instance = new DefaultFileHeaderStrategy() 17 | } 18 | 19 | def cleanup() { 20 | file.delete() 21 | } 22 | 23 | @Unroll 24 | def "write header and read it. sparse=#sparse, metaDataMap=#metaDataMap"() { 25 | when: 26 | FileHeader fileHeader = instance.writeFileHeader(file, magicValue, metaDataMap, sparse) 27 | Integer readMagicValue = instance.readMagicValue(file) 28 | FileHeader readFileHeader = instance.readFileHeader(file) 29 | 30 | then: 31 | null != fileHeader 32 | fileHeader.metaData == new MetaData(metaDataMap, sparse) 33 | magicValue == fileHeader.magicValue 34 | 35 | null != readMagicValue 36 | magicValue == readMagicValue 37 | 38 | fileHeader == readFileHeader 39 | 40 | where: 41 | sparse | metaDataMap 42 | false | null 43 | false | [foo: 'bar', foo2: 'bar2'] 44 | true | null 45 | true | [foo: 'bar', foo2: 'bar2'] 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /sulky-codec-filebuffer/src/test/groovy/de/huxhorn/sulky/codec/filebuffer/DefaultIndexStrategySpec.groovy: -------------------------------------------------------------------------------- 1 | package de.huxhorn.sulky.codec.filebuffer 2 | 3 | import spock.lang.Specification 4 | 5 | class DefaultIndexStrategySpec 6 | extends Specification { 7 | File testFile 8 | DefaultIndexStrategy instance = new DefaultIndexStrategy() 9 | 10 | def setup() { 11 | testFile = File.createTempFile("index", "tst"); 12 | testFile.delete(); 13 | } 14 | 15 | def cleanup() { 16 | testFile.delete(); 17 | } 18 | 19 | def "empty getSize"() { 20 | setup: 21 | RandomAccessFile raf = new RandomAccessFile(testFile, "rw") 22 | 23 | when: 24 | long size = instance.getSize(raf) 25 | raf.close() 26 | 27 | then: 28 | 0 == size 29 | } 30 | 31 | def "empty getOffset"() { 32 | setup: 33 | RandomAccessFile raf = new RandomAccessFile(testFile, "rw") 34 | 35 | when: 36 | long offset = instance.getOffset(raf, 17) 37 | raf.close() 38 | 39 | then: 40 | -1 == offset 41 | } 42 | 43 | def "first offset"() { 44 | setup: 45 | RandomAccessFile raf = new RandomAccessFile(testFile, "rw") 46 | 47 | when: 48 | instance.setOffset(raf, 0, 17) 49 | long size = instance.getSize(raf) 50 | long offset = instance.getOffset(raf, 0) 51 | raf.close() 52 | 53 | then: 54 | 1 == size 55 | 17 == offset 56 | } 57 | 58 | def "any offset"() { 59 | setup: 60 | RandomAccessFile raf = new RandomAccessFile(testFile, "rw") 61 | long index = 17 62 | long value = 42 63 | 64 | when: 65 | instance.setOffset(raf, index, value) 66 | long size = instance.getSize(raf) 67 | long offset = instance.getOffset(raf, index) 68 | for(int i=0;i 2 | 3 | 4 | 5 | 6 | %-5level - %d{HH:mm:ss.SSS} [%thread] - %file:%line - %msg%n%ex{full} 7 | 8 | 9 | 10 | 17 | 18 | 19 | 20 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /sulky-codec/src/main/java/de/huxhorn/sulky/codec/Codec.java: -------------------------------------------------------------------------------- 1 | /* 2 | * sulky-modules - several general-purpose modules. 3 | * Copyright (C) 2007-2011 Joern Huxhorn 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Lesser General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | /* 20 | * Copyright 2007-2011 Joern Huxhorn 21 | * 22 | * Licensed under the Apache License, Version 2.0 (the "License"); 23 | * you may not use this file except in compliance with the License. 24 | * You may obtain a copy of the License at 25 | * 26 | * http://www.apache.org/licenses/LICENSE-2.0 27 | * 28 | * Unless required by applicable law or agreed to in writing, software 29 | * distributed under the License is distributed on an "AS IS" BASIS, 30 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 31 | * See the License for the specific language governing permissions and 32 | * limitations under the License. 33 | */ 34 | 35 | package de.huxhorn.sulky.codec; 36 | 37 | public interface Codec 38 | extends Encoder, Decoder 39 | { 40 | } 41 | -------------------------------------------------------------------------------- /sulky-codec/src/main/java/de/huxhorn/sulky/codec/CompressingSerializableCodec.java: -------------------------------------------------------------------------------- 1 | /* 2 | * sulky-modules - several general-purpose modules. 3 | * Copyright (C) 2007-2011 Joern Huxhorn 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Lesser General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | /* 20 | * Copyright 2007-2011 Joern Huxhorn 21 | * 22 | * Licensed under the Apache License, Version 2.0 (the "License"); 23 | * you may not use this file except in compliance with the License. 24 | * You may obtain a copy of the License at 25 | * 26 | * http://www.apache.org/licenses/LICENSE-2.0 27 | * 28 | * Unless required by applicable law or agreed to in writing, software 29 | * distributed under the License is distributed on an "AS IS" BASIS, 30 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 31 | * See the License for the specific language governing permissions and 32 | * limitations under the License. 33 | */ 34 | 35 | package de.huxhorn.sulky.codec; 36 | 37 | import java.io.Serializable; 38 | 39 | public class CompressingSerializableCodec 40 | extends DelegatingCodecBase 41 | { 42 | public CompressingSerializableCodec() 43 | { 44 | super(new SerializableEncoder<>(true), 45 | new SerializableDecoder<>(true)); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /sulky-codec/src/main/java/de/huxhorn/sulky/codec/Decoder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * sulky-modules - several general-purpose modules. 3 | * Copyright (C) 2007-2011 Joern Huxhorn 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Lesser General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | /* 20 | * Copyright 2007-2011 Joern Huxhorn 21 | * 22 | * Licensed under the Apache License, Version 2.0 (the "License"); 23 | * you may not use this file except in compliance with the License. 24 | * You may obtain a copy of the License at 25 | * 26 | * http://www.apache.org/licenses/LICENSE-2.0 27 | * 28 | * Unless required by applicable law or agreed to in writing, software 29 | * distributed under the License is distributed on an "AS IS" BASIS, 30 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 31 | * See the License for the specific language governing permissions and 32 | * limitations under the License. 33 | */ 34 | 35 | package de.huxhorn.sulky.codec; 36 | 37 | public interface Decoder 38 | { 39 | E decode(byte[] bytes); 40 | } 41 | -------------------------------------------------------------------------------- /sulky-codec/src/main/java/de/huxhorn/sulky/codec/DelegatingCodecBase.java: -------------------------------------------------------------------------------- 1 | /* 2 | * sulky-modules - several general-purpose modules. 3 | * Copyright (C) 2007-2011 Joern Huxhorn 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Lesser General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | /* 20 | * Copyright 2007-2011 Joern Huxhorn 21 | * 22 | * Licensed under the Apache License, Version 2.0 (the "License"); 23 | * you may not use this file except in compliance with the License. 24 | * You may obtain a copy of the License at 25 | * 26 | * http://www.apache.org/licenses/LICENSE-2.0 27 | * 28 | * Unless required by applicable law or agreed to in writing, software 29 | * distributed under the License is distributed on an "AS IS" BASIS, 30 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 31 | * See the License for the specific language governing permissions and 32 | * limitations under the License. 33 | */ 34 | 35 | package de.huxhorn.sulky.codec; 36 | 37 | public class DelegatingCodecBase 38 | implements Codec 39 | { 40 | private Encoder encoder; 41 | private Decoder decoder; 42 | 43 | protected DelegatingCodecBase() 44 | { 45 | this(null, null); 46 | } 47 | 48 | protected DelegatingCodecBase(Encoder encoder, Decoder decoder) 49 | { 50 | this.encoder = encoder; 51 | this.decoder = decoder; 52 | } 53 | 54 | protected Encoder getEncoder() 55 | { 56 | return encoder; 57 | } 58 | 59 | protected void setEncoder(Encoder encoder) 60 | { 61 | this.encoder = encoder; 62 | } 63 | 64 | protected Decoder getDecoder() 65 | { 66 | return decoder; 67 | } 68 | 69 | protected void setDecoder(Decoder decoder) 70 | { 71 | this.decoder = decoder; 72 | } 73 | 74 | @Override 75 | public byte[] encode(E object) 76 | { 77 | if(encoder == null) 78 | { 79 | throw new IllegalStateException("encoder must not be null!"); 80 | } 81 | return encoder.encode(object); 82 | } 83 | 84 | @Override 85 | public E decode(byte[] bytes) 86 | { 87 | if(decoder == null) 88 | { 89 | throw new IllegalStateException("decoder must not be null!"); 90 | } 91 | return decoder.decode(bytes); 92 | } 93 | } 94 | -------------------------------------------------------------------------------- /sulky-codec/src/main/java/de/huxhorn/sulky/codec/Encoder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * sulky-modules - several general-purpose modules. 3 | * Copyright (C) 2007-2011 Joern Huxhorn 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Lesser General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | /* 20 | * Copyright 2007-2011 Joern Huxhorn 21 | * 22 | * Licensed under the Apache License, Version 2.0 (the "License"); 23 | * you may not use this file except in compliance with the License. 24 | * You may obtain a copy of the License at 25 | * 26 | * http://www.apache.org/licenses/LICENSE-2.0 27 | * 28 | * Unless required by applicable law or agreed to in writing, software 29 | * distributed under the License is distributed on an "AS IS" BASIS, 30 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 31 | * See the License for the specific language governing permissions and 32 | * limitations under the License. 33 | */ 34 | 35 | package de.huxhorn.sulky.codec; 36 | 37 | public interface Encoder 38 | { 39 | byte[] encode(E object); 40 | } 41 | -------------------------------------------------------------------------------- /sulky-codec/src/main/java/de/huxhorn/sulky/codec/EnumPersistenceDelegate.java: -------------------------------------------------------------------------------- 1 | /* 2 | * sulky-modules - several general-purpose modules. 3 | * Copyright (C) 2007-2018 Joern Huxhorn 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Lesser General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | /* 20 | * Copyright 2007-2018 Joern Huxhorn 21 | * 22 | * Licensed under the Apache License, Version 2.0 (the "License"); 23 | * you may not use this file except in compliance with the License. 24 | * You may obtain a copy of the License at 25 | * 26 | * http://www.apache.org/licenses/LICENSE-2.0 27 | * 28 | * Unless required by applicable law or agreed to in writing, software 29 | * distributed under the License is distributed on an "AS IS" BASIS, 30 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 31 | * See the License for the specific language governing permissions and 32 | * limitations under the License. 33 | */ 34 | 35 | package de.huxhorn.sulky.codec; 36 | 37 | import java.beans.Encoder; 38 | import java.beans.Expression; 39 | import java.beans.PersistenceDelegate; 40 | 41 | /** 42 | * As described in http://weblogs.java.net/blog/malenkov/archive/2006/08/how_to_encode_e.html 43 | * @deprecated not needed anymore 44 | */ 45 | public class EnumPersistenceDelegate 46 | extends PersistenceDelegate 47 | { 48 | @Override 49 | protected boolean mutatesTo(Object oldInstance, Object newInstance) 50 | { 51 | return oldInstance == newInstance; // NOPMD 52 | } 53 | 54 | @Override 55 | protected Expression instantiate(Object oldInstance, Encoder out) 56 | { 57 | Enum e = (Enum) oldInstance; 58 | return new Expression(e, e.getClass(), "valueOf", new Object[]{e.name()}); 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /sulky-codec/src/main/java/de/huxhorn/sulky/codec/SerializableCodec.java: -------------------------------------------------------------------------------- 1 | /* 2 | * sulky-modules - several general-purpose modules. 3 | * Copyright (C) 2007-2011 Joern Huxhorn 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Lesser General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | /* 20 | * Copyright 2007-2011 Joern Huxhorn 21 | * 22 | * Licensed under the Apache License, Version 2.0 (the "License"); 23 | * you may not use this file except in compliance with the License. 24 | * You may obtain a copy of the License at 25 | * 26 | * http://www.apache.org/licenses/LICENSE-2.0 27 | * 28 | * Unless required by applicable law or agreed to in writing, software 29 | * distributed under the License is distributed on an "AS IS" BASIS, 30 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 31 | * See the License for the specific language governing permissions and 32 | * limitations under the License. 33 | */ 34 | 35 | package de.huxhorn.sulky.codec; 36 | 37 | import java.io.Serializable; 38 | 39 | public class SerializableCodec 40 | extends DelegatingCodecBase 41 | { 42 | public SerializableCodec() 43 | { 44 | super(new SerializableEncoder<>(false), 45 | new SerializableDecoder<>(false)); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /sulky-codec/src/main/java/de/huxhorn/sulky/codec/SerializableDecoder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * sulky-modules - several general-purpose modules. 3 | * Copyright (C) 2007-2018 Joern Huxhorn 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Lesser General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | /* 20 | * Copyright 2007-2018 Joern Huxhorn 21 | * 22 | * Licensed under the Apache License, Version 2.0 (the "License"); 23 | * you may not use this file except in compliance with the License. 24 | * You may obtain a copy of the License at 25 | * 26 | * http://www.apache.org/licenses/LICENSE-2.0 27 | * 28 | * Unless required by applicable law or agreed to in writing, software 29 | * distributed under the License is distributed on an "AS IS" BASIS, 30 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 31 | * See the License for the specific language governing permissions and 32 | * limitations under the License. 33 | */ 34 | 35 | package de.huxhorn.sulky.codec; 36 | 37 | import java.io.ByteArrayInputStream; 38 | import java.io.IOException; 39 | import java.io.ObjectInputStream; 40 | import java.io.Serializable; 41 | import java.util.zip.GZIPInputStream; 42 | 43 | public class SerializableDecoder 44 | implements Decoder 45 | { 46 | private boolean compressing; 47 | 48 | public SerializableDecoder() 49 | { 50 | this(false); 51 | } 52 | 53 | public SerializableDecoder(boolean compressing) 54 | { 55 | setCompressing(compressing); 56 | } 57 | 58 | public boolean isCompressing() 59 | { 60 | return compressing; 61 | } 62 | 63 | public void setCompressing(boolean compressing) 64 | { 65 | this.compressing = compressing; 66 | } 67 | 68 | @Override 69 | public E decode(byte[] bytes) 70 | { 71 | try(ObjectInputStream ois = createObjectInputStream(bytes)) 72 | { 73 | Object result = ois.readObject(); 74 | @SuppressWarnings({"unchecked"}) 75 | E e =(E) result; 76 | return e; 77 | } 78 | catch(Throwable e) 79 | { 80 | // silently ignore any problems 81 | return null; 82 | } 83 | } 84 | 85 | private ObjectInputStream createObjectInputStream(byte[] bytes) 86 | throws IOException 87 | { 88 | ByteArrayInputStream bis = new ByteArrayInputStream(bytes); 89 | if(compressing) 90 | { 91 | GZIPInputStream gis = new GZIPInputStream(bis); 92 | return new ObjectInputStream(gis); 93 | } 94 | return new ObjectInputStream(bis); 95 | } 96 | 97 | @Override 98 | public String toString() 99 | { 100 | return "SerializableDecoder[compressing=" + compressing + "]"; 101 | } 102 | 103 | } 104 | -------------------------------------------------------------------------------- /sulky-codec/src/main/java/de/huxhorn/sulky/codec/SerializableEncoder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * sulky-modules - several general-purpose modules. 3 | * Copyright (C) 2007-2018 Joern Huxhorn 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Lesser General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | /* 20 | * Copyright 2007-2018 Joern Huxhorn 21 | * 22 | * Licensed under the Apache License, Version 2.0 (the "License"); 23 | * you may not use this file except in compliance with the License. 24 | * You may obtain a copy of the License at 25 | * 26 | * http://www.apache.org/licenses/LICENSE-2.0 27 | * 28 | * Unless required by applicable law or agreed to in writing, software 29 | * distributed under the License is distributed on an "AS IS" BASIS, 30 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 31 | * See the License for the specific language governing permissions and 32 | * limitations under the License. 33 | */ 34 | 35 | package de.huxhorn.sulky.codec; 36 | 37 | import java.io.ByteArrayOutputStream; 38 | import java.io.IOException; 39 | import java.io.ObjectOutputStream; 40 | import java.io.Serializable; 41 | import java.util.zip.GZIPOutputStream; 42 | 43 | public class SerializableEncoder 44 | implements Encoder 45 | { 46 | private boolean compressing; 47 | 48 | public SerializableEncoder() 49 | { 50 | this(false); 51 | } 52 | 53 | public SerializableEncoder(boolean compressing) 54 | { 55 | this.compressing = compressing; 56 | } 57 | 58 | public boolean isCompressing() 59 | { 60 | return compressing; 61 | } 62 | 63 | public void setCompressing(boolean compressing) 64 | { 65 | this.compressing = compressing; 66 | } 67 | 68 | @Override 69 | public byte[] encode(E object) 70 | { 71 | ByteArrayOutputStream bos = new ByteArrayOutputStream(); 72 | 73 | try(ObjectOutputStream oos = createObjectOutputStream(bos)) 74 | { 75 | oos.writeObject(object); 76 | oos.flush(); 77 | oos.close(); 78 | return bos.toByteArray(); 79 | } 80 | catch(IOException e) 81 | { 82 | e.printStackTrace(); // NOPMD 83 | return null; 84 | } 85 | } 86 | 87 | private ObjectOutputStream createObjectOutputStream(ByteArrayOutputStream bos) 88 | throws IOException 89 | { 90 | if(compressing) 91 | { 92 | GZIPOutputStream gos = new GZIPOutputStream(bos); 93 | return new ObjectOutputStream(gos); 94 | } 95 | return new ObjectOutputStream(bos); 96 | } 97 | 98 | @Override 99 | public String toString() 100 | { 101 | return "SerializableEncoder[compressing=" + compressing + "]"; 102 | } 103 | } 104 | -------------------------------------------------------------------------------- /sulky-codec/src/main/java/de/huxhorn/sulky/codec/XmlDecoder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * sulky-modules - several general-purpose modules. 3 | * Copyright (C) 2007-2018 Joern Huxhorn 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Lesser General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | /* 20 | * Copyright 2007-2018 Joern Huxhorn 21 | * 22 | * Licensed under the Apache License, Version 2.0 (the "License"); 23 | * you may not use this file except in compliance with the License. 24 | * You may obtain a copy of the License at 25 | * 26 | * http://www.apache.org/licenses/LICENSE-2.0 27 | * 28 | * Unless required by applicable law or agreed to in writing, software 29 | * distributed under the License is distributed on an "AS IS" BASIS, 30 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 31 | * See the License for the specific language governing permissions and 32 | * limitations under the License. 33 | */ 34 | 35 | package de.huxhorn.sulky.codec; 36 | 37 | import java.beans.XMLDecoder; 38 | import java.io.ByteArrayInputStream; 39 | import java.io.IOException; 40 | import java.util.zip.GZIPInputStream; 41 | 42 | public class XmlDecoder 43 | implements Decoder 44 | { 45 | private boolean compressing; 46 | 47 | public XmlDecoder() 48 | { 49 | this(false); 50 | } 51 | 52 | public XmlDecoder(boolean compressing) 53 | { 54 | setCompressing(compressing); 55 | } 56 | 57 | public boolean isCompressing() 58 | { 59 | return compressing; 60 | } 61 | 62 | public void setCompressing(boolean compressing) 63 | { 64 | this.compressing = compressing; 65 | } 66 | 67 | @Override 68 | public E decode(byte[] bytes) 69 | { 70 | try(XMLDecoder decoder=createXMLDecoder(bytes)) 71 | { 72 | Object result = decoder.readObject(); 73 | @SuppressWarnings({"unchecked"}) 74 | E e = (E) result; 75 | return e; 76 | } 77 | catch(Throwable e) 78 | { 79 | // silently ignore any problems 80 | return null; 81 | } 82 | } 83 | 84 | private XMLDecoder createXMLDecoder(byte[] bytes) 85 | throws IOException 86 | { 87 | ByteArrayInputStream bis = new ByteArrayInputStream(bytes); 88 | if(compressing) 89 | { 90 | GZIPInputStream gis = new GZIPInputStream(bis); 91 | return new XMLDecoder(gis); 92 | } 93 | return new XMLDecoder(bis); 94 | } 95 | 96 | @Override 97 | public String toString() 98 | { 99 | return "XmlDecoder[compressing=" + compressing + "]"; 100 | } 101 | } 102 | -------------------------------------------------------------------------------- /sulky-codec/src/main/java/de/huxhorn/sulky/codec/streaming/DecoderBridge.java: -------------------------------------------------------------------------------- 1 | /* 2 | * sulky-modules - several general-purpose modules. 3 | * Copyright (C) 2007-2019 Joern Huxhorn 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Lesser General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | /* 20 | * Copyright 2007-2019 Joern Huxhorn 21 | * 22 | * Licensed under the Apache License, Version 2.0 (the "License"); 23 | * you may not use this file except in compliance with the License. 24 | * You may obtain a copy of the License at 25 | * 26 | * http://www.apache.org/licenses/LICENSE-2.0 27 | * 28 | * Unless required by applicable law or agreed to in writing, software 29 | * distributed under the License is distributed on an "AS IS" BASIS, 30 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 31 | * See the License for the specific language governing permissions and 32 | * limitations under the License. 33 | */ 34 | 35 | package de.huxhorn.sulky.codec.streaming; 36 | 37 | import de.huxhorn.sulky.codec.Decoder; 38 | import java.io.ByteArrayInputStream; 39 | import java.io.IOException; 40 | import java.util.Objects; 41 | import org.slf4j.Logger; 42 | import org.slf4j.LoggerFactory; 43 | 44 | public class DecoderBridge 45 | implements Decoder 46 | { 47 | private final Logger logger = LoggerFactory.getLogger(DecoderBridge.class); 48 | 49 | private final StreamingDecoder wrapped; 50 | 51 | public DecoderBridge(StreamingDecoder wrapped) 52 | { 53 | this.wrapped = Objects.requireNonNull(wrapped, "wrapped must not be null!"); 54 | } 55 | 56 | @Override 57 | public E decode(byte[] bytes) 58 | { 59 | try(ByteArrayInputStream bis=new ByteArrayInputStream(bytes)) 60 | { 61 | return wrapped.decode(bis); 62 | } 63 | catch (IOException e) 64 | { 65 | if(logger.isWarnEnabled()) logger.warn("Couldn't decode!", e); 66 | } 67 | return null; 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /sulky-codec/src/main/java/de/huxhorn/sulky/codec/streaming/DelegatingStreamingCodecBase.java: -------------------------------------------------------------------------------- 1 | /* 2 | * sulky-modules - several general-purpose modules. 3 | * Copyright (C) 2007-2011 Joern Huxhorn 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Lesser General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | /* 20 | * Copyright 2007-2011 Joern Huxhorn 21 | * 22 | * Licensed under the Apache License, Version 2.0 (the "License"); 23 | * you may not use this file except in compliance with the License. 24 | * You may obtain a copy of the License at 25 | * 26 | * http://www.apache.org/licenses/LICENSE-2.0 27 | * 28 | * Unless required by applicable law or agreed to in writing, software 29 | * distributed under the License is distributed on an "AS IS" BASIS, 30 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 31 | * See the License for the specific language governing permissions and 32 | * limitations under the License. 33 | */ 34 | 35 | package de.huxhorn.sulky.codec.streaming; 36 | 37 | import java.io.IOException; 38 | import java.io.InputStream; 39 | import java.io.OutputStream; 40 | 41 | public class DelegatingStreamingCodecBase 42 | implements StreamingCodec 43 | { 44 | private StreamingEncoder encoder; 45 | private StreamingDecoder decoder; 46 | 47 | protected DelegatingStreamingCodecBase() 48 | { 49 | this(null, null); 50 | } 51 | 52 | protected DelegatingStreamingCodecBase(StreamingEncoder encoder, StreamingDecoder decoder) 53 | { 54 | this.encoder = encoder; 55 | this.decoder = decoder; 56 | } 57 | 58 | protected StreamingEncoder getEncoder() 59 | { 60 | return encoder; 61 | } 62 | 63 | protected void setEncoder(StreamingEncoder encoder) 64 | { 65 | this.encoder = encoder; 66 | } 67 | 68 | protected StreamingDecoder getDecoder() 69 | { 70 | return decoder; 71 | } 72 | 73 | protected void setDecoder(StreamingDecoder decoder) 74 | { 75 | this.decoder = decoder; 76 | } 77 | 78 | @Override 79 | public E decode(InputStream from) throws IOException 80 | { 81 | return decoder.decode(from); 82 | } 83 | 84 | @Override 85 | public void encode(E obj, OutputStream into) throws IOException 86 | { 87 | encoder.encode(obj, into); 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /sulky-codec/src/main/java/de/huxhorn/sulky/codec/streaming/EncoderBridge.java: -------------------------------------------------------------------------------- 1 | /* 2 | * sulky-modules - several general-purpose modules. 3 | * Copyright (C) 2007-2021 Joern Huxhorn 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Lesser General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | /* 20 | * Copyright 2007-2021 Joern Huxhorn 21 | * 22 | * Licensed under the Apache License, Version 2.0 (the "License"); 23 | * you may not use this file except in compliance with the License. 24 | * You may obtain a copy of the License at 25 | * 26 | * http://www.apache.org/licenses/LICENSE-2.0 27 | * 28 | * Unless required by applicable law or agreed to in writing, software 29 | * distributed under the License is distributed on an "AS IS" BASIS, 30 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 31 | * See the License for the specific language governing permissions and 32 | * limitations under the License. 33 | */ 34 | 35 | package de.huxhorn.sulky.codec.streaming; 36 | 37 | import de.huxhorn.sulky.codec.Encoder; 38 | import java.io.ByteArrayOutputStream; 39 | import java.io.IOException; 40 | import java.util.Objects; 41 | import org.slf4j.Logger; 42 | import org.slf4j.LoggerFactory; 43 | 44 | public class EncoderBridge 45 | implements Encoder 46 | { 47 | private final Logger logger = LoggerFactory.getLogger(EncoderBridge.class); 48 | 49 | private final StreamingEncoder wrapped; 50 | 51 | public EncoderBridge(StreamingEncoder wrapped) 52 | { 53 | this.wrapped = Objects.requireNonNull(wrapped, "wrapped must not be null!"); 54 | } 55 | 56 | @Override 57 | @SuppressWarnings("PMD.ReturnEmptyCollectionRatherThanNull") 58 | public byte[] encode(E object) 59 | { 60 | ByteArrayOutputStream bos = new ByteArrayOutputStream(); 61 | try 62 | { 63 | wrapped.encode(object, bos); 64 | return bos.toByteArray(); 65 | } 66 | catch (IOException e) 67 | { 68 | if(logger.isWarnEnabled()) logger.warn("Exception while encoding {}!", object, e); 69 | } 70 | return null; 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /sulky-codec/src/main/java/de/huxhorn/sulky/codec/streaming/GZIPStreamingDecoderWrapper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * sulky-modules - several general-purpose modules. 3 | * Copyright (C) 2007-2019 Joern Huxhorn 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Lesser General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | /* 20 | * Copyright 2007-2019 Joern Huxhorn 21 | * 22 | * Licensed under the Apache License, Version 2.0 (the "License"); 23 | * you may not use this file except in compliance with the License. 24 | * You may obtain a copy of the License at 25 | * 26 | * http://www.apache.org/licenses/LICENSE-2.0 27 | * 28 | * Unless required by applicable law or agreed to in writing, software 29 | * distributed under the License is distributed on an "AS IS" BASIS, 30 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 31 | * See the License for the specific language governing permissions and 32 | * limitations under the License. 33 | */ 34 | 35 | package de.huxhorn.sulky.codec.streaming; 36 | 37 | import java.io.IOException; 38 | import java.io.InputStream; 39 | import java.util.zip.GZIPInputStream; 40 | 41 | public class GZIPStreamingDecoderWrapper 42 | implements StreamingDecoder 43 | { 44 | private final StreamingDecoder wrapped; 45 | 46 | public GZIPStreamingDecoderWrapper(StreamingDecoder wrapped) 47 | { 48 | this.wrapped = wrapped; 49 | } 50 | 51 | @Override 52 | public E decode(InputStream from) throws IOException 53 | { 54 | try(GZIPInputStream gis=new GZIPInputStream(from)) 55 | { 56 | return wrapped.decode(gis); 57 | } 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /sulky-codec/src/main/java/de/huxhorn/sulky/codec/streaming/GZIPStreamingEncoderWrapper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * sulky-modules - several general-purpose modules. 3 | * Copyright (C) 2007-2019 Joern Huxhorn 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Lesser General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | /* 20 | * Copyright 2007-2019 Joern Huxhorn 21 | * 22 | * Licensed under the Apache License, Version 2.0 (the "License"); 23 | * you may not use this file except in compliance with the License. 24 | * You may obtain a copy of the License at 25 | * 26 | * http://www.apache.org/licenses/LICENSE-2.0 27 | * 28 | * Unless required by applicable law or agreed to in writing, software 29 | * distributed under the License is distributed on an "AS IS" BASIS, 30 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 31 | * See the License for the specific language governing permissions and 32 | * limitations under the License. 33 | */ 34 | 35 | package de.huxhorn.sulky.codec.streaming; 36 | 37 | import java.io.IOException; 38 | import java.io.OutputStream; 39 | import java.util.zip.GZIPOutputStream; 40 | 41 | public class GZIPStreamingEncoderWrapper 42 | implements StreamingEncoder 43 | { 44 | private final StreamingEncoder wrapped; 45 | 46 | public GZIPStreamingEncoderWrapper(StreamingEncoder wrapped) 47 | { 48 | this.wrapped = wrapped; 49 | } 50 | 51 | @Override 52 | public void encode(E obj, OutputStream into) throws IOException 53 | { 54 | try(GZIPOutputStream gos=new GZIPOutputStream(into)) 55 | { 56 | wrapped.encode(obj, gos); 57 | gos.finish(); 58 | } 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /sulky-codec/src/main/java/de/huxhorn/sulky/codec/streaming/StreamingCodec.java: -------------------------------------------------------------------------------- 1 | /* 2 | * sulky-modules - several general-purpose modules. 3 | * Copyright (C) 2007-2011 Joern Huxhorn 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Lesser General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | /* 20 | * Copyright 2007-2011 Joern Huxhorn 21 | * 22 | * Licensed under the Apache License, Version 2.0 (the "License"); 23 | * you may not use this file except in compliance with the License. 24 | * You may obtain a copy of the License at 25 | * 26 | * http://www.apache.org/licenses/LICENSE-2.0 27 | * 28 | * Unless required by applicable law or agreed to in writing, software 29 | * distributed under the License is distributed on an "AS IS" BASIS, 30 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 31 | * See the License for the specific language governing permissions and 32 | * limitations under the License. 33 | */ 34 | 35 | package de.huxhorn.sulky.codec.streaming; 36 | 37 | public interface StreamingCodec extends StreamingEncoder, StreamingDecoder 38 | { 39 | } 40 | -------------------------------------------------------------------------------- /sulky-codec/src/main/java/de/huxhorn/sulky/codec/streaming/StreamingDecoder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * sulky-modules - several general-purpose modules. 3 | * Copyright (C) 2007-2011 Joern Huxhorn 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Lesser General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | /* 20 | * Copyright 2007-2011 Joern Huxhorn 21 | * 22 | * Licensed under the Apache License, Version 2.0 (the "License"); 23 | * you may not use this file except in compliance with the License. 24 | * You may obtain a copy of the License at 25 | * 26 | * http://www.apache.org/licenses/LICENSE-2.0 27 | * 28 | * Unless required by applicable law or agreed to in writing, software 29 | * distributed under the License is distributed on an "AS IS" BASIS, 30 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 31 | * See the License for the specific language governing permissions and 32 | * limitations under the License. 33 | */ 34 | 35 | package de.huxhorn.sulky.codec.streaming; 36 | 37 | import java.io.IOException; 38 | import java.io.InputStream; 39 | 40 | public interface StreamingDecoder 41 | { 42 | T decode(InputStream from) throws IOException; 43 | } 44 | -------------------------------------------------------------------------------- /sulky-codec/src/main/java/de/huxhorn/sulky/codec/streaming/StreamingEncoder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * sulky-modules - several general-purpose modules. 3 | * Copyright (C) 2007-2011 Joern Huxhorn 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Lesser General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | /* 20 | * Copyright 2007-2011 Joern Huxhorn 21 | * 22 | * Licensed under the Apache License, Version 2.0 (the "License"); 23 | * you may not use this file except in compliance with the License. 24 | * You may obtain a copy of the License at 25 | * 26 | * http://www.apache.org/licenses/LICENSE-2.0 27 | * 28 | * Unless required by applicable law or agreed to in writing, software 29 | * distributed under the License is distributed on an "AS IS" BASIS, 30 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 31 | * See the License for the specific language governing permissions and 32 | * limitations under the License. 33 | */ 34 | 35 | package de.huxhorn.sulky.codec.streaming; 36 | 37 | import java.io.IOException; 38 | import java.io.OutputStream; 39 | 40 | public interface StreamingEncoder 41 | { 42 | void encode(T obj, OutputStream into) throws IOException; 43 | } 44 | -------------------------------------------------------------------------------- /sulky-codec/src/main/java/de/huxhorn/sulky/codec/streaming/StreamingSerializableCodec.java: -------------------------------------------------------------------------------- 1 | /* 2 | * sulky-modules - several general-purpose modules. 3 | * Copyright (C) 2007-2019 Joern Huxhorn 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Lesser General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | /* 20 | * Copyright 2007-2019 Joern Huxhorn 21 | * 22 | * Licensed under the Apache License, Version 2.0 (the "License"); 23 | * you may not use this file except in compliance with the License. 24 | * You may obtain a copy of the License at 25 | * 26 | * http://www.apache.org/licenses/LICENSE-2.0 27 | * 28 | * Unless required by applicable law or agreed to in writing, software 29 | * distributed under the License is distributed on an "AS IS" BASIS, 30 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 31 | * See the License for the specific language governing permissions and 32 | * limitations under the License. 33 | */ 34 | 35 | package de.huxhorn.sulky.codec.streaming; 36 | 37 | import java.io.IOException; 38 | import java.io.InputStream; 39 | import java.io.ObjectInputStream; 40 | import java.io.ObjectOutputStream; 41 | import java.io.OutputStream; 42 | import java.io.Serializable; 43 | 44 | public class StreamingSerializableCodec 45 | implements StreamingCodec 46 | { 47 | @Override 48 | public E decode(InputStream from) throws IOException 49 | { 50 | try(ObjectInputStream ois = new ObjectInputStream(from)) 51 | { 52 | Object result = ois.readObject(); 53 | @SuppressWarnings({"unchecked"}) 54 | E e=(E) result; 55 | return e; 56 | } 57 | catch (ClassNotFoundException e) 58 | { 59 | throw new IOException("Coudln't decode!",e); 60 | } 61 | } 62 | 63 | @Override 64 | public void encode(E obj, OutputStream into) throws IOException 65 | { 66 | try(ObjectOutputStream oos = new ObjectOutputStream(into)) 67 | { 68 | oos.writeObject(obj); 69 | oos.flush(); 70 | } 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /sulky-codec/src/test/java/de/huxhorn/sulky/codec/CompressingSerializableCodecTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * sulky-modules - several general-purpose modules. 3 | * Copyright (C) 2007-2011 Joern Huxhorn 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Lesser General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | /* 20 | * Copyright 2007-2011 Joern Huxhorn 21 | * 22 | * Licensed under the Apache License, Version 2.0 (the "License"); 23 | * you may not use this file except in compliance with the License. 24 | * You may obtain a copy of the License at 25 | * 26 | * http://www.apache.org/licenses/LICENSE-2.0 27 | * 28 | * Unless required by applicable law or agreed to in writing, software 29 | * distributed under the License is distributed on an "AS IS" BASIS, 30 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 31 | * See the License for the specific language governing permissions and 32 | * limitations under the License. 33 | */ 34 | 35 | package de.huxhorn.sulky.codec; 36 | 37 | import org.junit.Test; 38 | 39 | import static org.junit.Assert.assertEquals; 40 | 41 | public class CompressingSerializableCodecTest 42 | { 43 | @Test 44 | public void test() 45 | { 46 | String obj = "Foo"; 47 | CompressingSerializableCodec instance = new CompressingSerializableCodec<>(); 48 | byte[] encoded = instance.encode(obj); 49 | String decoded = instance.decode(encoded); 50 | assertEquals(obj, decoded); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /sulky-codec/src/test/java/de/huxhorn/sulky/codec/SerializableCodecTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * sulky-modules - several general-purpose modules. 3 | * Copyright (C) 2007-2011 Joern Huxhorn 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Lesser General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | /* 20 | * Copyright 2007-2011 Joern Huxhorn 21 | * 22 | * Licensed under the Apache License, Version 2.0 (the "License"); 23 | * you may not use this file except in compliance with the License. 24 | * You may obtain a copy of the License at 25 | * 26 | * http://www.apache.org/licenses/LICENSE-2.0 27 | * 28 | * Unless required by applicable law or agreed to in writing, software 29 | * distributed under the License is distributed on an "AS IS" BASIS, 30 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 31 | * See the License for the specific language governing permissions and 32 | * limitations under the License. 33 | */ 34 | 35 | package de.huxhorn.sulky.codec; 36 | 37 | import org.junit.Test; 38 | 39 | import static org.junit.Assert.assertEquals; 40 | 41 | public class SerializableCodecTest 42 | { 43 | @Test 44 | public void test() 45 | { 46 | String obj = "Foo"; 47 | SerializableCodec instance = new SerializableCodec<>(); 48 | byte[] encoded = instance.encode(obj); 49 | String decoded = instance.decode(encoded); 50 | assertEquals(obj, decoded); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /sulky-codec/src/test/java/de/huxhorn/sulky/codec/XmlCodecTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * sulky-modules - several general-purpose modules. 3 | * Copyright (C) 2007-2011 Joern Huxhorn 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Lesser General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | /* 20 | * Copyright 2007-2011 Joern Huxhorn 21 | * 22 | * Licensed under the Apache License, Version 2.0 (the "License"); 23 | * you may not use this file except in compliance with the License. 24 | * You may obtain a copy of the License at 25 | * 26 | * http://www.apache.org/licenses/LICENSE-2.0 27 | * 28 | * Unless required by applicable law or agreed to in writing, software 29 | * distributed under the License is distributed on an "AS IS" BASIS, 30 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 31 | * See the License for the specific language governing permissions and 32 | * limitations under the License. 33 | */ 34 | 35 | package de.huxhorn.sulky.codec; 36 | 37 | import org.junit.Test; 38 | 39 | import static org.junit.Assert.assertEquals; 40 | 41 | public class XmlCodecTest 42 | { 43 | @Test 44 | public void test() 45 | { 46 | String obj = "Foo"; 47 | XmlEncoder encoder = new XmlEncoder<>(); 48 | XmlDecoder decoder = new XmlDecoder<>(); 49 | byte[] encoded = encoder.encode(obj); 50 | String decoded = decoder.decode(encoded); 51 | assertEquals(obj, decoded); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /sulky-codec/src/test/java/de/huxhorn/sulky/codec/streaming/GZIPStreamingWrapperTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * sulky-modules - several general-purpose modules. 3 | * Copyright (C) 2007-2019 Joern Huxhorn 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Lesser General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | /* 20 | * Copyright 2007-2019 Joern Huxhorn 21 | * 22 | * Licensed under the Apache License, Version 2.0 (the "License"); 23 | * you may not use this file except in compliance with the License. 24 | * You may obtain a copy of the License at 25 | * 26 | * http://www.apache.org/licenses/LICENSE-2.0 27 | * 28 | * Unless required by applicable law or agreed to in writing, software 29 | * distributed under the License is distributed on an "AS IS" BASIS, 30 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 31 | * See the License for the specific language governing permissions and 32 | * limitations under the License. 33 | */ 34 | 35 | package de.huxhorn.sulky.codec.streaming; 36 | 37 | import java.io.ByteArrayInputStream; 38 | import java.io.ByteArrayOutputStream; 39 | import java.io.IOException; 40 | import org.junit.Test; 41 | 42 | import static org.junit.Assert.assertEquals; 43 | 44 | public class GZIPStreamingWrapperTest 45 | { 46 | @Test 47 | public void test() throws IOException 48 | { 49 | String obj = "Foo"; 50 | StreamingEncoder encoder = new GZIPStreamingEncoderWrapper<>(new StreamingSerializableCodec<>()); 51 | StreamingDecoder decoder = new GZIPStreamingDecoderWrapper<>(new StreamingSerializableCodec<>()); 52 | try(ByteArrayOutputStream bos=new ByteArrayOutputStream()) 53 | { 54 | encoder.encode(obj, bos); 55 | try(ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray())) 56 | { 57 | String decoded = decoder.decode(bis); 58 | assertEquals(obj, decoded); 59 | } 60 | } 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /sulky-codec/src/test/java/de/huxhorn/sulky/codec/streaming/StreamingSerializableCodecTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * sulky-modules - several general-purpose modules. 3 | * Copyright (C) 2007-2019 Joern Huxhorn 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Lesser General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | /* 20 | * Copyright 2007-2019 Joern Huxhorn 21 | * 22 | * Licensed under the Apache License, Version 2.0 (the "License"); 23 | * you may not use this file except in compliance with the License. 24 | * You may obtain a copy of the License at 25 | * 26 | * http://www.apache.org/licenses/LICENSE-2.0 27 | * 28 | * Unless required by applicable law or agreed to in writing, software 29 | * distributed under the License is distributed on an "AS IS" BASIS, 30 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 31 | * See the License for the specific language governing permissions and 32 | * limitations under the License. 33 | */ 34 | 35 | package de.huxhorn.sulky.codec.streaming; 36 | 37 | import java.io.ByteArrayInputStream; 38 | import java.io.ByteArrayOutputStream; 39 | import java.io.IOException; 40 | import org.junit.Test; 41 | 42 | import static org.junit.Assert.assertEquals; 43 | 44 | public class StreamingSerializableCodecTest 45 | { 46 | @Test 47 | public void test() throws IOException 48 | { 49 | String obj = "Foo"; 50 | StreamingSerializableCodec instance = new StreamingSerializableCodec<>(); 51 | try(ByteArrayOutputStream bos=new ByteArrayOutputStream()) 52 | { 53 | instance.encode(obj, bos); 54 | try(ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray())) 55 | { 56 | String decoded = instance.decode(bis); 57 | assertEquals(obj, decoded); 58 | } 59 | } 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /sulky-conditions/src/main/java/de/huxhorn/sulky/conditions/BooleanValues.java: -------------------------------------------------------------------------------- 1 | /* 2 | * sulky-modules - several general-purpose modules. 3 | * Copyright (C) 2007-2017 Joern Huxhorn 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Lesser General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | /* 20 | * Copyright 2007-2017 Joern Huxhorn 21 | * 22 | * Licensed under the Apache License, Version 2.0 (the "License"); 23 | * you may not use this file except in compliance with the License. 24 | * You may obtain a copy of the License at 25 | * 26 | * http://www.apache.org/licenses/LICENSE-2.0 27 | * 28 | * Unless required by applicable law or agreed to in writing, software 29 | * distributed under the License is distributed on an "AS IS" BASIS, 30 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 31 | * See the License for the specific language governing permissions and 32 | * limitations under the License. 33 | */ 34 | 35 | package de.huxhorn.sulky.conditions; 36 | 37 | public final class BooleanValues 38 | implements Condition, Cloneable 39 | { 40 | private static final long serialVersionUID = 1780367398890411212L; 41 | 42 | /** 43 | * true singleton 44 | */ 45 | public static final BooleanValues TRUE = new BooleanValues(true); 46 | 47 | /** 48 | * false singleton 49 | */ 50 | public static final BooleanValues FALSE = new BooleanValues(false); 51 | 52 | private final boolean value; 53 | private final transient String string; 54 | 55 | private BooleanValues(boolean b) 56 | { 57 | this.value = b; 58 | this.string = String.valueOf(b); 59 | } 60 | 61 | /** 62 | * Returns either true or false, depending on the instance. 63 | * 64 | * @param element the element to be evaluated. 65 | * @return either true or false, depending on the instance. 66 | */ 67 | @Override 68 | public boolean isTrue(Object element) 69 | { 70 | return value; 71 | } 72 | 73 | //@edu.umd.cs.findbugs.annotations.SuppressWarnings(value="CN_IDIOM_NO_SUPER_CALL",justification="") 74 | @SuppressWarnings({"CloneDoesntCallSuperClone"}) 75 | @Override 76 | public BooleanValues clone() 77 | throws CloneNotSupportedException 78 | { 79 | // this is not a bug! - Bad practice - clone method does not call super.clone() 80 | return this; //NOSONAR 81 | } 82 | 83 | private Object readResolve() 84 | { 85 | return getInstance(value); 86 | } 87 | 88 | @Override 89 | public String toString() 90 | { 91 | return string; 92 | } 93 | 94 | public static BooleanValues getInstance(boolean value) 95 | { 96 | return value ? TRUE : FALSE; 97 | } 98 | } 99 | -------------------------------------------------------------------------------- /sulky-conditions/src/main/java/de/huxhorn/sulky/conditions/Condition.java: -------------------------------------------------------------------------------- 1 | /* 2 | * sulky-modules - several general-purpose modules. 3 | * Copyright (C) 2007-2011 Joern Huxhorn 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Lesser General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | /* 20 | * Copyright 2007-2011 Joern Huxhorn 21 | * 22 | * Licensed under the Apache License, Version 2.0 (the "License"); 23 | * you may not use this file except in compliance with the License. 24 | * You may obtain a copy of the License at 25 | * 26 | * http://www.apache.org/licenses/LICENSE-2.0 27 | * 28 | * Unless required by applicable law or agreed to in writing, software 29 | * distributed under the License is distributed on an "AS IS" BASIS, 30 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 31 | * See the License for the specific language governing permissions and 32 | * limitations under the License. 33 | */ 34 | 35 | package de.huxhorn.sulky.conditions; 36 | 37 | import java.io.Serializable; 38 | 39 | public interface Condition 40 | extends Cloneable, Serializable 41 | { 42 | boolean isTrue(Object element); 43 | 44 | /** 45 | * This method is expected to perform a deep clone, i.e. all sub-conditions must be cloned, too. 46 | * 47 | * @return a clone of the Condition. 48 | * @throws CloneNotSupportedException Guess what? 49 | */ 50 | @SuppressWarnings("PMD.MissingOverride") 51 | Condition clone() 52 | throws CloneNotSupportedException; 53 | } 54 | -------------------------------------------------------------------------------- /sulky-conditions/src/main/java/de/huxhorn/sulky/conditions/ConditionGroup.java: -------------------------------------------------------------------------------- 1 | /* 2 | * sulky-modules - several general-purpose modules. 3 | * Copyright (C) 2007-2011 Joern Huxhorn 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Lesser General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | /* 20 | * Copyright 2007-2011 Joern Huxhorn 21 | * 22 | * Licensed under the Apache License, Version 2.0 (the "License"); 23 | * you may not use this file except in compliance with the License. 24 | * You may obtain a copy of the License at 25 | * 26 | * http://www.apache.org/licenses/LICENSE-2.0 27 | * 28 | * Unless required by applicable law or agreed to in writing, software 29 | * distributed under the License is distributed on an "AS IS" BASIS, 30 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 31 | * See the License for the specific language governing permissions and 32 | * limitations under the License. 33 | */ 34 | 35 | package de.huxhorn.sulky.conditions; 36 | 37 | import java.util.List; 38 | 39 | public interface ConditionGroup 40 | extends Condition 41 | { 42 | List getConditions(); 43 | 44 | void setConditions(List conditions); 45 | } 46 | -------------------------------------------------------------------------------- /sulky-conditions/src/main/java/de/huxhorn/sulky/conditions/ConditionWrapper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * sulky-modules - several general-purpose modules. 3 | * Copyright (C) 2007-2011 Joern Huxhorn 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Lesser General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | /* 20 | * Copyright 2007-2011 Joern Huxhorn 21 | * 22 | * Licensed under the Apache License, Version 2.0 (the "License"); 23 | * you may not use this file except in compliance with the License. 24 | * You may obtain a copy of the License at 25 | * 26 | * http://www.apache.org/licenses/LICENSE-2.0 27 | * 28 | * Unless required by applicable law or agreed to in writing, software 29 | * distributed under the License is distributed on an "AS IS" BASIS, 30 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 31 | * See the License for the specific language governing permissions and 32 | * limitations under the License. 33 | */ 34 | 35 | package de.huxhorn.sulky.conditions; 36 | 37 | public interface ConditionWrapper 38 | extends Condition 39 | { 40 | Condition getCondition(); 41 | 42 | void setCondition(Condition condition); 43 | } 44 | -------------------------------------------------------------------------------- /sulky-conditions/src/main/java/de/huxhorn/sulky/conditions/Conditions.java: -------------------------------------------------------------------------------- 1 | /* 2 | * sulky-modules - several general-purpose modules. 3 | * Copyright (C) 2007-2014 Joern Huxhorn 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Lesser General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | /* 20 | * Copyright 2007-2014 Joern Huxhorn 21 | * 22 | * Licensed under the Apache License, Version 2.0 (the "License"); 23 | * you may not use this file except in compliance with the License. 24 | * You may obtain a copy of the License at 25 | * 26 | * http://www.apache.org/licenses/LICENSE-2.0 27 | * 28 | * Unless required by applicable law or agreed to in writing, software 29 | * distributed under the License is distributed on an "AS IS" BASIS, 30 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 31 | * See the License for the specific language governing permissions and 32 | * limitations under the License. 33 | */ 34 | 35 | package de.huxhorn.sulky.conditions; 36 | 37 | import java.util.List; 38 | 39 | public final class Conditions 40 | { 41 | static 42 | { 43 | // for the sake of coverage 44 | new Conditions(); 45 | } 46 | 47 | private Conditions() 48 | {} 49 | 50 | /** 51 | * Returns true if condition contains otherCondition. 52 | * 53 | * Conditions "contain" themselves so this method returns true if condition equals otherCondition. 54 | * 55 | * @param condition the condition to be checked for containment 56 | * @param otherCondition the condition that might contain condition. 57 | * @return true if condition contains otherCondition. 58 | */ 59 | public static boolean contains(Condition condition, Condition otherCondition) 60 | { 61 | if(condition == null) 62 | { 63 | return false; 64 | } 65 | if(condition.equals(otherCondition)) 66 | { 67 | return true; 68 | } 69 | if(condition instanceof ConditionWrapper) 70 | { 71 | ConditionWrapper conditionWrapper = (ConditionWrapper) condition; 72 | Condition wrappedCondition = conditionWrapper.getCondition(); 73 | if(wrappedCondition == null) 74 | { 75 | return otherCondition == null; 76 | } 77 | return contains(wrappedCondition, otherCondition); 78 | } 79 | else if(condition instanceof ConditionGroup) 80 | { 81 | ConditionGroup conditionGroup = (ConditionGroup) condition; 82 | List conditions = conditionGroup.getConditions(); 83 | if(conditions == null) 84 | { 85 | return false; 86 | } 87 | for(Condition c : conditions) 88 | { 89 | if(contains(c, otherCondition)) 90 | { 91 | return true; 92 | } 93 | } 94 | } 95 | return false; 96 | } 97 | } 98 | -------------------------------------------------------------------------------- /sulky-conditions/src/test/resources/logback-test.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | %-5level - %d{HH:mm:ss.SSS} [%thread] - %file:%line - %msg%n%ex{full} 7 | 8 | 9 | 10 | 18 | 19 | 20 | 21 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /sulky-formatting/src/test/resources/logback-test.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | %-5level - %d{HH:mm:ss.SSS} [%thread] - %file:%line - %msg%n%ex{full} 7 | 8 | 9 | 10 | 18 | 19 | 20 | 21 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /sulky-generics/src/main/java/de/huxhorn/sulky/generics/Wrapper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * sulky-modules - several general-purpose modules. 3 | * Copyright (C) 2007-2019 Joern Huxhorn 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Lesser General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | /* 20 | * Copyright 2007-2019 Joern Huxhorn 21 | * 22 | * Licensed under the Apache License, Version 2.0 (the "License"); 23 | * you may not use this file except in compliance with the License. 24 | * You may obtain a copy of the License at 25 | * 26 | * http://www.apache.org/licenses/LICENSE-2.0 27 | * 28 | * Unless required by applicable law or agreed to in writing, software 29 | * distributed under the License is distributed on an "AS IS" BASIS, 30 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 31 | * See the License for the specific language governing permissions and 32 | * limitations under the License. 33 | */ 34 | 35 | package de.huxhorn.sulky.generics; 36 | 37 | /** 38 | * This interface is similar to java.sql.Wrapper. It should be in java.util since it's really handy... 39 | */ 40 | public interface Wrapper 41 | { 42 | 43 | T unwrap(Class iface); 44 | 45 | boolean isWrapperFor(Class iface); 46 | 47 | } 48 | -------------------------------------------------------------------------------- /sulky-groovy/src/test/resources/Bar.groovy: -------------------------------------------------------------------------------- 1 | return 'Bar' 2 | -------------------------------------------------------------------------------- /sulky-groovy/src/test/resources/Broken.b0rken: -------------------------------------------------------------------------------- 1 | someError(xyz) { 2 | -------------------------------------------------------------------------------- /sulky-groovy/src/test/resources/Foo.groovy: -------------------------------------------------------------------------------- 1 | return 'Foo' 2 | -------------------------------------------------------------------------------- /sulky-groovy/src/test/resources/logback-test.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | %-5level - %d{HH:mm:ss.SSS} [%thread] - %file:%line - %msg%n%ex{full} 7 | 8 | 9 | 10 | 17 | 18 | 19 | 20 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /sulky-junit/src/test/groovy/de/huxhorn/sulky/junit/LoggingTestBaseExampleTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * sulky-modules - several general-purpose modules. 3 | * Copyright (C) 2007-2016 Joern Huxhorn 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Lesser General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | /* 20 | * Copyright 2007-2016 Joern Huxhorn 21 | * 22 | * Licensed under the Apache License, Version 2.0 (the "License"); 23 | * you may not use this file except in compliance with the License. 24 | * You may obtain a copy of the License at 25 | * 26 | * http://www.apache.org/licenses/LICENSE-2.0 27 | * 28 | * Unless required by applicable law or agreed to in writing, software 29 | * distributed under the License is distributed on an "AS IS" BASIS, 30 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 31 | * See the License for the specific language governing permissions and 32 | * limitations under the License. 33 | */ 34 | 35 | package de.huxhorn.sulky.junit; 36 | 37 | import org.junit.Test; 38 | import org.slf4j.Logger; 39 | import org.slf4j.LoggerFactory; 40 | 41 | /** 42 | */ 43 | public class LoggingTestBaseExampleTest 44 | extends LoggingTestBase 45 | { 46 | private final Logger logger = LoggerFactory.getLogger(LoggingTestBaseExampleTest.class); 47 | 48 | public LoggingTestBaseExampleTest(Boolean logging) 49 | { 50 | super(logging); 51 | } 52 | 53 | @Test 54 | public void someTest() 55 | { 56 | if(logger.isDebugEnabled()) logger.debug("Shouldn't show up in default mode."); 57 | if(logger.isInfoEnabled()) logger.info("Just some logging message to see if everything works."); 58 | 59 | } 60 | 61 | @Test 62 | public void someOtherTest() 63 | { 64 | if(logger.isDebugEnabled()) logger.debug("Other - Shouldn't show up in default mode."); 65 | if(logger.isInfoEnabled()) logger.info("Other - Just some logging message to see if everything works."); 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /sulky-junit/src/test/resources/logback-test.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | %-5level - %d{HH:mm:ss.SSS} [%thread] - %file:%line - %msg%n%ex{full} 7 | 8 | 9 | 10 | 18 | 19 | 20 | 21 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /sulky-logging/src/main/java/de/huxhorn/sulky/logging/LoggingPropertyChangeListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * sulky-modules - several general-purpose modules. 3 | * Copyright (C) 2007-2017 Joern Huxhorn 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Lesser General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | /* 20 | * Copyright 2007-2017 Joern Huxhorn 21 | * 22 | * Licensed under the Apache License, Version 2.0 (the "License"); 23 | * you may not use this file except in compliance with the License. 24 | * You may obtain a copy of the License at 25 | * 26 | * http://www.apache.org/licenses/LICENSE-2.0 27 | * 28 | * Unless required by applicable law or agreed to in writing, software 29 | * distributed under the License is distributed on an "AS IS" BASIS, 30 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 31 | * See the License for the specific language governing permissions and 32 | * limitations under the License. 33 | */ 34 | 35 | package de.huxhorn.sulky.logging; 36 | 37 | import java.beans.PropertyChangeEvent; 38 | import java.beans.PropertyChangeListener; 39 | import org.slf4j.Logger; 40 | import org.slf4j.LoggerFactory; 41 | 42 | public class LoggingPropertyChangeListener 43 | implements PropertyChangeListener 44 | { 45 | private final Logger logger; 46 | 47 | public LoggingPropertyChangeListener() 48 | { 49 | this(LoggerFactory.getLogger(LoggingPropertyChangeListener.class)); 50 | } 51 | 52 | public LoggingPropertyChangeListener(Logger logger) 53 | { 54 | this.logger = logger; 55 | if(logger == null) 56 | { 57 | throw new IllegalArgumentException("logger must not be null!"); 58 | } 59 | } 60 | 61 | @Override 62 | public void propertyChange(PropertyChangeEvent event) 63 | { 64 | if(logger.isInfoEnabled()) logger.info("PropertyChangeEvent:\n\tpropertyName='{}'\n\toldValue={}\n\tnewValue={}", event.getPropertyName(), event.getOldValue(), event.getNewValue()); 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /sulky-logging/src/test/resources/logback-test.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | %-5level - %d{HH:mm:ss.SSS} [%thread] - %file:%line - %msg%n%ex{full} 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /sulky-plist/src/main/java/de/huxhorn/sulky/plist/impl/PropertyListConstants.java: -------------------------------------------------------------------------------- 1 | /* 2 | * sulky-modules - several general-purpose modules. 3 | * Copyright (C) 2007-2015 Joern Huxhorn 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Lesser General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | /* 20 | * Copyright 2007-2015 Joern Huxhorn 21 | * 22 | * Licensed under the Apache License, Version 2.0 (the "License"); 23 | * you may not use this file except in compliance with the License. 24 | * You may obtain a copy of the License at 25 | * 26 | * http://www.apache.org/licenses/LICENSE-2.0 27 | * 28 | * Unless required by applicable law or agreed to in writing, software 29 | * distributed under the License is distributed on an "AS IS" BASIS, 30 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 31 | * See the License for the specific language governing permissions and 32 | * limitations under the License. 33 | */ 34 | 35 | package de.huxhorn.sulky.plist.impl; 36 | 37 | public interface PropertyListConstants 38 | { 39 | String PLIST_NODE = "plist"; 40 | String PLIST_VERSION_ATTRIBUTE = "version"; 41 | String PLIST_VERSION = "1.0"; 42 | 43 | // Collections 44 | String ARRAY_NODE = "array"; 45 | String DICT_NODE = "dict"; 46 | String KEY_NODE = "key"; 47 | 48 | // Primitive types 49 | String STRING_NODE = "string"; 50 | /** 51 | * Contents interpreted as Base-64 encoded 52 | */ 53 | String DATA_NODE = "data"; 54 | 55 | /** 56 | * Contents should conform to a subset of ISO 8601 57 | * (in particular, YYYY '-' MM '-' DD 'T' HH ':' MM ':' SS 'Z'. 58 | * Smaller units may be omitted with a loss of precision) 59 | */ 60 | String DATE_NODE = "date"; 61 | 62 | // Numerical primitives 63 | /** 64 | * Boolean constant true 65 | */ 66 | String TRUE_NODE = "true"; 67 | 68 | /** 69 | * Boolean constant false 70 | */ 71 | String FALSE_NODE = "false"; 72 | 73 | /** 74 | * Contents should represent a floating point number matching 75 | * ("+" | "-")? d+ ("."d*)? ("E" ("+" | "-") d+)? where d is a digit 0-9. 76 | */ 77 | String REAL_NODE = "real"; 78 | 79 | /** 80 | * Contents should represent a (possibly signed) integer number in base 10 81 | */ 82 | String INTEGER_NODE = "integer"; 83 | } 84 | -------------------------------------------------------------------------------- /sulky-plist/src/test/resources/logback-test.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | %-5level - %d{HH:mm:ss.SSS} [%thread] - %file:%line - %msg%n%ex{full} 7 | 8 | 9 | 10 | 18 | 19 | 20 | 21 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /sulky-resources/licenseTemplateLGPL.java: -------------------------------------------------------------------------------- 1 | /* 2 | * sulky-resources - inheritance-safe class resources. 3 | * Copyright (C) 2002-2011 Joern Huxhorn 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Lesser General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | /* 20 | * Copyright 2002-2011 Joern Huxhorn 21 | * 22 | * Licensed under the Apache License, Version 2.0 (the "License"); 23 | * you may not use this file except in compliance with the License. 24 | * You may obtain a copy of the License at 25 | * 26 | * http://www.apache.org/licenses/LICENSE-2.0 27 | * 28 | * Unless required by applicable law or agreed to in writing, software 29 | * distributed under the License is distributed on an "AS IS" BASIS, 30 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 31 | * See the License for the specific language governing permissions and 32 | * limitations under the License. 33 | */ 34 | 35 | -------------------------------------------------------------------------------- /sulky-resources/src/main/java/de/huxhorn/sulky/resources/CyclicLinkException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * sulky-resources - inheritance-safe class resources. 3 | * Copyright (C) 2002-2017 Joern Huxhorn 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Lesser General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | /* 20 | * Copyright 2002-2017 Joern Huxhorn 21 | * 22 | * Licensed under the Apache License, Version 2.0 (the "License"); 23 | * you may not use this file except in compliance with the License. 24 | * You may obtain a copy of the License at 25 | * 26 | * http://www.apache.org/licenses/LICENSE-2.0 27 | * 28 | * Unless required by applicable law or agreed to in writing, software 29 | * distributed under the License is distributed on an "AS IS" BASIS, 30 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 31 | * See the License for the specific language governing permissions and 32 | * limitations under the License. 33 | */ 34 | 35 | package de.huxhorn.sulky.resources; 36 | 37 | import java.util.List; 38 | import java.util.Objects; 39 | 40 | /** 41 | * DOCUMENT: CyclicLinkException 42 | */ 43 | public class CyclicLinkException 44 | extends Exception 45 | { 46 | private static final long serialVersionUID = 5197383554254357523L; 47 | 48 | private final List linkStack; 49 | private final String cycleCause; 50 | 51 | public CyclicLinkException(List linkStack, String cycleCause) 52 | { 53 | this.linkStack = Objects.requireNonNull(linkStack, "linkStack must not be null!"); 54 | this.cycleCause = cycleCause; 55 | } 56 | 57 | public String getCycleCause() 58 | { 59 | return cycleCause; 60 | } 61 | 62 | public String getLinkStackString() 63 | { 64 | StringBuilder result = new StringBuilder(); 65 | for(int i = 0; i < linkStack.size(); i++) 66 | { 67 | if(i != 0) 68 | { 69 | result.append(" => "); 70 | } 71 | result.append('"').append(linkStack.get(i)).append('"'); 72 | } 73 | 74 | return result.toString(); 75 | } 76 | 77 | @Override 78 | public String toString() 79 | { 80 | return "CyclicLinkException: " + 81 | "Link-Stack: {" + 82 | getLinkStackString() + 83 | " => \"" + 84 | cycleCause + 85 | "\"}"; 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /sulky-resources/src/main/java/de/huxhorn/sulky/resources/Localizable.java: -------------------------------------------------------------------------------- 1 | /* 2 | * sulky-resources - inheritance-safe class resources. 3 | * Copyright (C) 2002-2011 Joern Huxhorn 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Lesser General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | /* 20 | * Copyright 2002-2011 Joern Huxhorn 21 | * 22 | * Licensed under the Apache License, Version 2.0 (the "License"); 23 | * you may not use this file except in compliance with the License. 24 | * You may obtain a copy of the License at 25 | * 26 | * http://www.apache.org/licenses/LICENSE-2.0 27 | * 28 | * Unless required by applicable law or agreed to in writing, software 29 | * distributed under the License is distributed on an "AS IS" BASIS, 30 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 31 | * See the License for the specific language governing permissions and 32 | * limitations under the License. 33 | */ 34 | 35 | package de.huxhorn.sulky.resources; 36 | 37 | import java.util.Locale; 38 | 39 | /** 40 | * This interface is used for Proxy-creation in sulky-resources and should have been 41 | * part of J2SDK anyway. 42 | */ 43 | public interface Localizable 44 | { 45 | void setLocale(Locale l); 46 | 47 | Locale getLocale(); 48 | } 49 | -------------------------------------------------------------------------------- /sulky-resources/src/main/java/overview.html: -------------------------------------------------------------------------------- 1 | 2 | DOCUMENT: de.huxhorn.sulky.resources overview 3 | 4 | -------------------------------------------------------------------------------- /sulky-resources/src/test/java/PackagelessTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * sulky-resources - inheritance-safe class resources. 3 | * Copyright (C) 2002-2017 Joern Huxhorn 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Lesser General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | /* 20 | * Copyright 2002-2017 Joern Huxhorn 21 | * 22 | * Licensed under the Apache License, Version 2.0 (the "License"); 23 | * you may not use this file except in compliance with the License. 24 | * You may obtain a copy of the License at 25 | * 26 | * http://www.apache.org/licenses/LICENSE-2.0 27 | * 28 | * Unless required by applicable law or agreed to in writing, software 29 | * distributed under the License is distributed on an "AS IS" BASIS, 30 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 31 | * See the License for the specific language governing permissions and 32 | * limitations under the License. 33 | */ 34 | 35 | import de.huxhorn.sulky.resources.Resources; 36 | import org.junit.Test; 37 | 38 | import static org.junit.Assert.assertEquals; 39 | 40 | /** 41 | * DOCUMENT: PackagelessTest 42 | * A seperate class to test Resources.getShortClassName() without package. 43 | */ 44 | @SuppressWarnings("PMD.NoPackage") 45 | public class PackagelessTest 46 | { 47 | @Test 48 | public void getShortClassName() 49 | throws Exception 50 | { 51 | String str; 52 | 53 | str = Resources.getShortClassName(PackagelessTest.class); 54 | assertEquals("PackagelessTest", str); 55 | } 56 | 57 | @Test 58 | public void getPathToPackage() 59 | throws Exception 60 | { 61 | String str; 62 | 63 | str = Resources.getPathToPackage(PackagelessTest.class); 64 | assertEquals("/", str); 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /sulky-resources/src/test/java/de/huxhorn/sulky/resources/junit/BaseClass.java: -------------------------------------------------------------------------------- 1 | /* 2 | * sulky-resources - inheritance-safe class resources. 3 | * Copyright (C) 2002-2016 Joern Huxhorn 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Lesser General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | /* 20 | * Copyright 2002-2016 Joern Huxhorn 21 | * 22 | * Licensed under the Apache License, Version 2.0 (the "License"); 23 | * you may not use this file except in compliance with the License. 24 | * You may obtain a copy of the License at 25 | * 26 | * http://www.apache.org/licenses/LICENSE-2.0 27 | * 28 | * Unless required by applicable law or agreed to in writing, software 29 | * distributed under the License is distributed on an "AS IS" BASIS, 30 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 31 | * See the License for the specific language governing permissions and 32 | * limitations under the License. 33 | */ 34 | 35 | package de.huxhorn.sulky.resources.junit; 36 | 37 | class BaseClass 38 | { 39 | } 40 | -------------------------------------------------------------------------------- /sulky-resources/src/test/resources/de/huxhorn/sulky/resources/junit/BaseClass/baseFallback.txt: -------------------------------------------------------------------------------- 1 | baseFallback -------------------------------------------------------------------------------- /sulky-resources/src/test/resources/de/huxhorn/sulky/resources/junit/BaseClass/overloaded.txt: -------------------------------------------------------------------------------- 1 | base value -------------------------------------------------------------------------------- /sulky-resources/src/test/resources/de/huxhorn/sulky/resources/junit/BaseClass/resources.properties: -------------------------------------------------------------------------------- 1 | base.txt=BaseClass 2 | -------------------------------------------------------------------------------- /sulky-resources/src/test/resources/de/huxhorn/sulky/resources/junit/Foobar/Internal/test.txt: -------------------------------------------------------------------------------- 1 | Test -------------------------------------------------------------------------------- /sulky-resources/src/test/resources/de/huxhorn/sulky/resources/junit/Foobar/StaticInternal/de/test.txt: -------------------------------------------------------------------------------- 1 | Tescht -------------------------------------------------------------------------------- /sulky-resources/src/test/resources/de/huxhorn/sulky/resources/junit/Foobar/StaticInternal/test.txt: -------------------------------------------------------------------------------- 1 | Test -------------------------------------------------------------------------------- /sulky-resources/src/test/resources/de/huxhorn/sulky/resources/junit/Foobar/cyclic1.link: -------------------------------------------------------------------------------- 1 | cyclic2 -------------------------------------------------------------------------------- /sulky-resources/src/test/resources/de/huxhorn/sulky/resources/junit/Foobar/cyclic2.link: -------------------------------------------------------------------------------- 1 | cyclic3 -------------------------------------------------------------------------------- /sulky-resources/src/test/resources/de/huxhorn/sulky/resources/junit/Foobar/cyclic3.link: -------------------------------------------------------------------------------- 1 | cyclic1 -------------------------------------------------------------------------------- /sulky-resources/src/test/resources/de/huxhorn/sulky/resources/junit/Foobar/cyclicFallback1: -------------------------------------------------------------------------------- 1 | cyclicFallback -------------------------------------------------------------------------------- /sulky-resources/src/test/resources/de/huxhorn/sulky/resources/junit/Foobar/cyclicFallback1.link: -------------------------------------------------------------------------------- 1 | cyclicFallback2 -------------------------------------------------------------------------------- /sulky-resources/src/test/resources/de/huxhorn/sulky/resources/junit/Foobar/cyclicFallback2.link: -------------------------------------------------------------------------------- 1 | cyclicFallback3 -------------------------------------------------------------------------------- /sulky-resources/src/test/resources/de/huxhorn/sulky/resources/junit/Foobar/cyclicFallback3.link: -------------------------------------------------------------------------------- 1 | cyclicFallback1 -------------------------------------------------------------------------------- /sulky-resources/src/test/resources/de/huxhorn/sulky/resources/junit/Foobar/de/locale.html: -------------------------------------------------------------------------------- 1 | locale -------------------------------------------------------------------------------- /sulky-resources/src/test/resources/de/huxhorn/sulky/resources/junit/Foobar/de/locale.txt: -------------------------------------------------------------------------------- 1 | locale -------------------------------------------------------------------------------- /sulky-resources/src/test/resources/de/huxhorn/sulky/resources/junit/Foobar/de_DE/locale.html: -------------------------------------------------------------------------------- 1 | locale -------------------------------------------------------------------------------- /sulky-resources/src/test/resources/de/huxhorn/sulky/resources/junit/Foobar/de_DE/locale.txt: -------------------------------------------------------------------------------- 1 | locale -------------------------------------------------------------------------------- /sulky-resources/src/test/resources/de/huxhorn/sulky/resources/junit/Foobar/de_DE/resources.properties: -------------------------------------------------------------------------------- 1 | attention.txt=Achtung! 2 | cancel.txt=Abbruch 3 | -------------------------------------------------------------------------------- /sulky-resources/src/test/resources/de/huxhorn/sulky/resources/junit/Foobar/de_DE_hessisch/locale.txt: -------------------------------------------------------------------------------- 1 | locale -------------------------------------------------------------------------------- /sulky-resources/src/test/resources/de/huxhorn/sulky/resources/junit/Foobar/de_DE_hessisch/resources.properties: -------------------------------------------------------------------------------- 1 | attention.txt=Uffbasse! 2 | -------------------------------------------------------------------------------- /sulky-resources/src/test/resources/de/huxhorn/sulky/resources/junit/Foobar/defaultFallback.txt.link: -------------------------------------------------------------------------------- 1 | # A comment 2 | # notFound.txt will not be found... 3 | notFound.txt 4 | ................/underflow.txt -------------------------------------------------------------------------------- /sulky-resources/src/test/resources/de/huxhorn/sulky/resources/junit/Foobar/en/locale.txt: -------------------------------------------------------------------------------- 1 | locale -------------------------------------------------------------------------------- /sulky-resources/src/test/resources/de/huxhorn/sulky/resources/junit/Foobar/en_US/locale.txt: -------------------------------------------------------------------------------- 1 | locale -------------------------------------------------------------------------------- /sulky-resources/src/test/resources/de/huxhorn/sulky/resources/junit/Foobar/link.txt.link: -------------------------------------------------------------------------------- 1 | # A comment 2 | # notFound.txt will not be found... 3 | notFound.txt 4 | 5 | # That's the resource that will actually be used. 6 | test.txt -------------------------------------------------------------------------------- /sulky-resources/src/test/resources/de/huxhorn/sulky/resources/junit/Foobar/locale.txt: -------------------------------------------------------------------------------- 1 | locale -------------------------------------------------------------------------------- /sulky-resources/src/test/resources/de/huxhorn/sulky/resources/junit/Foobar/overloaded.txt: -------------------------------------------------------------------------------- 1 | overloaded -------------------------------------------------------------------------------- /sulky-resources/src/test/resources/de/huxhorn/sulky/resources/junit/Foobar/resources.properties: -------------------------------------------------------------------------------- 1 | attention.txt=Attention! 2 | ok.txt=OK 3 | cancel.txt=Cancel 4 | -------------------------------------------------------------------------------- /sulky-resources/src/test/resources/de/huxhorn/sulky/resources/junit/Foobar/test.txt: -------------------------------------------------------------------------------- 1 | Test -------------------------------------------------------------------------------- /sulky-resources/src/test/resources/de/huxhorn/sulky/resources/junit/defaultFallback.txt: -------------------------------------------------------------------------------- 1 | defaultFallback -------------------------------------------------------------------------------- /sulky-resources/src/test/resources/logback-test.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | %-5level - %d{HH:mm:ss.SSS} [%thread] - %file:%line - %msg%n%ex{full} 7 | 8 | 9 | 10 | 18 | 19 | 20 | 21 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /sulky-sounds-api/src/main/java/de/huxhorn/sulky/sounds/Sounds.java: -------------------------------------------------------------------------------- 1 | /* 2 | * sulky-modules - several general-purpose modules. 3 | * Copyright (C) 2007-2014 Joern Huxhorn 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Lesser General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | /* 20 | * Copyright 2007-2014 Joern Huxhorn 21 | * 22 | * Licensed under the Apache License, Version 2.0 (the "License"); 23 | * you may not use this file except in compliance with the License. 24 | * You may obtain a copy of the License at 25 | * 26 | * http://www.apache.org/licenses/LICENSE-2.0 27 | * 28 | * Unless required by applicable law or agreed to in writing, software 29 | * distributed under the License is distributed on an "AS IS" BASIS, 30 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 31 | * See the License for the specific language governing permissions and 32 | * limitations under the License. 33 | */ 34 | 35 | package de.huxhorn.sulky.sounds; 36 | 37 | import java.util.Map; 38 | 39 | public interface Sounds 40 | { 41 | /** 42 | * Plays the sound with the given name. 43 | * 44 | * If ignoreDuplicates is true, another instance 45 | * of the same sound will not be 46 | * added to the playlist while it is still played or waiting to be played. 47 | * 48 | * @param soundName the name of the sound to be played. 49 | * @param ignoreDuplicates if true, another instance of the same sound will not be added to the playlist. 50 | */ 51 | void play(String soundName, boolean ignoreDuplicates); 52 | 53 | /** 54 | * Shortcut for play(soundName, true). 55 | * 56 | * @param soundName the name of the sound to be played. 57 | */ 58 | void play(String soundName); 59 | 60 | void setMute(boolean mute); 61 | 62 | boolean isMute(); 63 | 64 | Map getSoundLocations(); 65 | 66 | void setSoundLocations(Map soundLocations); 67 | } 68 | -------------------------------------------------------------------------------- /sulky-stax/src/main/java/de/huxhorn/sulky/stax/GenericStreamReader.java: -------------------------------------------------------------------------------- 1 | /* 2 | * sulky-modules - several general-purpose modules. 3 | * Copyright (C) 2007-2011 Joern Huxhorn 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Lesser General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | /* 20 | * Copyright 2007-2011 Joern Huxhorn 21 | * 22 | * Licensed under the Apache License, Version 2.0 (the "License"); 23 | * you may not use this file except in compliance with the License. 24 | * You may obtain a copy of the License at 25 | * 26 | * http://www.apache.org/licenses/LICENSE-2.0 27 | * 28 | * Unless required by applicable law or agreed to in writing, software 29 | * distributed under the License is distributed on an "AS IS" BASIS, 30 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 31 | * See the License for the specific language governing permissions and 32 | * limitations under the License. 33 | */ 34 | 35 | package de.huxhorn.sulky.stax; 36 | 37 | import javax.xml.stream.XMLStreamException; 38 | import javax.xml.stream.XMLStreamReader; 39 | 40 | public interface GenericStreamReader 41 | { 42 | T read(XMLStreamReader reader) 43 | throws XMLStreamException; 44 | } 45 | -------------------------------------------------------------------------------- /sulky-stax/src/main/java/de/huxhorn/sulky/stax/GenericStreamWriter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * sulky-modules - several general-purpose modules. 3 | * Copyright (C) 2007-2011 Joern Huxhorn 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Lesser General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | /* 20 | * Copyright 2007-2011 Joern Huxhorn 21 | * 22 | * Licensed under the Apache License, Version 2.0 (the "License"); 23 | * you may not use this file except in compliance with the License. 24 | * You may obtain a copy of the License at 25 | * 26 | * http://www.apache.org/licenses/LICENSE-2.0 27 | * 28 | * Unless required by applicable law or agreed to in writing, software 29 | * distributed under the License is distributed on an "AS IS" BASIS, 30 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 31 | * See the License for the specific language governing permissions and 32 | * limitations under the License. 33 | */ 34 | 35 | package de.huxhorn.sulky.stax; 36 | 37 | import javax.xml.stream.XMLStreamException; 38 | import javax.xml.stream.XMLStreamWriter; 39 | 40 | public interface GenericStreamWriter 41 | { 42 | void write(XMLStreamWriter writer, T object, boolean isRoot) 43 | throws XMLStreamException; 44 | } 45 | -------------------------------------------------------------------------------- /sulky-stax/src/main/java/de/huxhorn/sulky/stax/WhiteSpaceHandling.java: -------------------------------------------------------------------------------- 1 | /* 2 | * sulky-modules - several general-purpose modules. 3 | * Copyright (C) 2007-2011 Joern Huxhorn 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Lesser General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | /* 20 | * Copyright 2007-2011 Joern Huxhorn 21 | * 22 | * Licensed under the Apache License, Version 2.0 (the "License"); 23 | * you may not use this file except in compliance with the License. 24 | * You may obtain a copy of the License at 25 | * 26 | * http://www.apache.org/licenses/LICENSE-2.0 27 | * 28 | * Unless required by applicable law or agreed to in writing, software 29 | * distributed under the License is distributed on an "AS IS" BASIS, 30 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 31 | * See the License for the specific language governing permissions and 32 | * limitations under the License. 33 | */ 34 | 35 | package de.huxhorn.sulky.stax; 36 | 37 | public enum WhiteSpaceHandling 38 | { 39 | PRESERVE, 40 | PRESERVE_NORMALIZE_NEWLINE, 41 | REPLACE, 42 | COLLAPSE 43 | } 44 | -------------------------------------------------------------------------------- /sulky-swing/src/main/java/de/huxhorn/sulky/swing/PropertyChangeWrapper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * sulky-modules - several general-purpose modules. 3 | * Copyright (C) 2007-2017 Joern Huxhorn 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Lesser General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | /* 20 | * Copyright 2007-2017 Joern Huxhorn 21 | * 22 | * Licensed under the Apache License, Version 2.0 (the "License"); 23 | * you may not use this file except in compliance with the License. 24 | * You may obtain a copy of the License at 25 | * 26 | * http://www.apache.org/licenses/LICENSE-2.0 27 | * 28 | * Unless required by applicable law or agreed to in writing, software 29 | * distributed under the License is distributed on an "AS IS" BASIS, 30 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 31 | * See the License for the specific language governing permissions and 32 | * limitations under the License. 33 | */ 34 | 35 | package de.huxhorn.sulky.swing; 36 | 37 | import de.huxhorn.sulky.generics.GenericWrapper; 38 | import java.awt.EventQueue; 39 | import java.beans.PropertyChangeEvent; 40 | import java.beans.PropertyChangeListener; 41 | 42 | /** 43 | * A wrapper for PropertyChangeListener that ensures that the wrapped listeners propertyChange method is invoked 44 | * on the EventDispatchThread. 45 | */ 46 | public class PropertyChangeWrapper 47 | extends GenericWrapper 48 | implements PropertyChangeListener 49 | { 50 | public PropertyChangeWrapper(PropertyChangeListener wrapped) 51 | { 52 | super(wrapped); 53 | } 54 | 55 | @Override 56 | public void propertyChange(final PropertyChangeEvent evt) 57 | { 58 | final PropertyChangeListener wrapped = getWrapped(); 59 | if(EventQueue.isDispatchThread()) 60 | { 61 | wrapped.propertyChange(evt); 62 | } 63 | else 64 | { 65 | EventQueue.invokeLater(new PropertyChangeRunnable(evt)); 66 | } 67 | } 68 | 69 | private class PropertyChangeRunnable 70 | implements Runnable 71 | { 72 | private final PropertyChangeEvent event; 73 | 74 | PropertyChangeRunnable(PropertyChangeEvent event) 75 | { 76 | this.event=event; 77 | } 78 | 79 | @Override 80 | public void run() 81 | { 82 | getWrapped().propertyChange(event); 83 | } 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /sulky-swing/src/main/java/de/huxhorn/sulky/swing/RowBasedTableModel.java: -------------------------------------------------------------------------------- 1 | /* 2 | * sulky-modules - several general-purpose modules. 3 | * Copyright (C) 2007-2011 Joern Huxhorn 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Lesser General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | /* 20 | * Copyright 2007-2011 Joern Huxhorn 21 | * 22 | * Licensed under the Apache License, Version 2.0 (the "License"); 23 | * you may not use this file except in compliance with the License. 24 | * You may obtain a copy of the License at 25 | * 26 | * http://www.apache.org/licenses/LICENSE-2.0 27 | * 28 | * Unless required by applicable law or agreed to in writing, software 29 | * distributed under the License is distributed on an "AS IS" BASIS, 30 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 31 | * See the License for the specific language governing permissions and 32 | * limitations under the License. 33 | */ 34 | 35 | package de.huxhorn.sulky.swing; 36 | 37 | import javax.swing.table.TableModel; 38 | 39 | public interface RowBasedTableModel 40 | extends TableModel 41 | { 42 | T getValueAt(int row); 43 | } 44 | -------------------------------------------------------------------------------- /sulky-swing/src/main/java/de/huxhorn/sulky/swing/Tables.java: -------------------------------------------------------------------------------- 1 | /* 2 | * sulky-modules - several general-purpose modules. 3 | * Copyright (C) 2007-2015 Joern Huxhorn 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Lesser General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | /* 20 | * Copyright 2007-2015 Joern Huxhorn 21 | * 22 | * Licensed under the Apache License, Version 2.0 (the "License"); 23 | * you may not use this file except in compliance with the License. 24 | * You may obtain a copy of the License at 25 | * 26 | * http://www.apache.org/licenses/LICENSE-2.0 27 | * 28 | * Unless required by applicable law or agreed to in writing, software 29 | * distributed under the License is distributed on an "AS IS" BASIS, 30 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 31 | * See the License for the specific language governing permissions and 32 | * limitations under the License. 33 | */ 34 | 35 | package de.huxhorn.sulky.swing; 36 | 37 | import javax.swing.JTable; 38 | 39 | public final class Tables 40 | { 41 | private Tables() 42 | {} 43 | 44 | // Just call JTable.setAutoCreateRowSorter 45 | @Deprecated 46 | public static void setAutoCreateRowSorter(JTable table, boolean auto) 47 | { 48 | table.setAutoCreateRowSorter(auto); 49 | } 50 | 51 | // Just call JTable.convertRowIndexToModel 52 | @Deprecated 53 | public static int convertRowIndexToModel(JTable table, int row) 54 | { 55 | return table.convertRowIndexToModel(row); 56 | } 57 | 58 | } 59 | -------------------------------------------------------------------------------- /sulky-swing/src/test/groovy/de/huxhorn/sulky/swing/KeyStrokesSpec.groovy: -------------------------------------------------------------------------------- 1 | /* 2 | * sulky-modules - several general-purpose modules. 3 | * Copyright (C) 2007-2017 Joern Huxhorn 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Lesser General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | /* 20 | * Copyright 2007-2017 Joern Huxhorn 21 | * 22 | * Licensed under the Apache License, Version 2.0 (the "License"); 23 | * you may not use this file except in compliance with the License. 24 | * You may obtain a copy of the License at 25 | * 26 | * http://www.apache.org/licenses/LICENSE-2.0 27 | * 28 | * Unless required by applicable law or agreed to in writing, software 29 | * distributed under the License is distributed on an "AS IS" BASIS, 30 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 31 | * See the License for the specific language governing permissions and 32 | * limitations under the License. 33 | */ 34 | 35 | package de.huxhorn.sulky.swing 36 | 37 | import spock.lang.Specification 38 | 39 | import javax.swing.KeyStroke 40 | import java.awt.event.KeyEvent 41 | 42 | class KeyStrokesSpec extends Specification { 43 | def 'KeyStrokes.resolveAcceleratorKeyStroke(...) with valid input works as expected.'() { 44 | when: 'given a valid input' 45 | KeyStroke keyStroke = KeyStrokes.resolveAcceleratorKeyStroke('command shift A') 46 | 47 | then: 'modifiers of the resulting KeyStroke are initialized correctly' 48 | (keyStroke.modifiers & KeyStrokes.COMMAND_MODIFIERS) != 0 49 | (keyStroke.modifiers & KeyEvent.SHIFT_MASK) != 0 50 | (keyStroke.modifiers & KeyEvent.SHIFT_DOWN_MASK) != 0 51 | } 52 | 53 | def 'KeyStrokes.resolveAcceleratorKeyStroke(...) with invalid input returns null.'() { 54 | expect: 55 | KeyStrokes.resolveAcceleratorKeyStroke('foo') == null 56 | } 57 | 58 | def 'KeyStrokes.resolveAcceleratorKeyStroke(null) returns null.'() { 59 | expect: 60 | KeyStrokes.resolveAcceleratorKeyStroke(null) == null 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /sulky-tasks/src/main/java/de/huxhorn/sulky/tasks/Task.java: -------------------------------------------------------------------------------- 1 | /* 2 | * sulky-modules - several general-purpose modules. 3 | * Copyright (C) 2007-2017 Joern Huxhorn 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Lesser General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | /* 20 | * Copyright 2007-2017 Joern Huxhorn 21 | * 22 | * Licensed under the Apache License, Version 2.0 (the "License"); 23 | * you may not use this file except in compliance with the License. 24 | * You may obtain a copy of the License at 25 | * 26 | * http://www.apache.org/licenses/LICENSE-2.0 27 | * 28 | * Unless required by applicable law or agreed to in writing, software 29 | * distributed under the License is distributed on an "AS IS" BASIS, 30 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 31 | * See the License for the specific language governing permissions and 32 | * limitations under the License. 33 | */ 34 | 35 | package de.huxhorn.sulky.tasks; 36 | 37 | import java.util.Map; 38 | import java.util.concurrent.Callable; 39 | import java.util.concurrent.Future; 40 | 41 | /** 42 | *

A Task is created by a TaskManager and encapsulates both Callable and Future as well as additional information.

43 | * 44 | * @param the type of the result. 45 | * @see java.util.concurrent.Callable 46 | * @see java.util.concurrent.Future 47 | * @see de.huxhorn.sulky.tasks.TaskManager#startTask(java.util.concurrent.Callable, String, String, java.util.Map) 48 | */ 49 | @SuppressWarnings("PMD.ShortClassName") 50 | public interface Task 51 | { 52 | /** 53 | * Returns the ID of this task. Task IDs are unique in relation to the TaskManager that started the task. 54 | * 55 | * @return the ID of the task. 56 | */ 57 | long getId(); 58 | 59 | /** 60 | * Returns the TaskManager that started this task. 61 | * 62 | * @return the TaskManager that started this Task. 63 | */ 64 | TaskManager getTaskManager(); 65 | 66 | String getName(); 67 | 68 | String getDescription(); 69 | 70 | int getProgress(); 71 | 72 | Map getMetaData(); 73 | 74 | Future getFuture(); 75 | 76 | Callable getCallable(); 77 | } 78 | -------------------------------------------------------------------------------- /sulky-tasks/src/main/java/de/huxhorn/sulky/tasks/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * This package contains the sulky Task API, a wrapper for Executor, Callable and Future, 3 | * that also supports handling on the event dispatch thread. It's an alternative to 4 | * the SwingWorker that has been added to Java in the 1.6 release. 5 | * 6 | *

In contrast to SwingWorker, it contains the definition of a generified 7 | * TaskManager, Task and TaskListener.

8 | * 9 | *

The TaskManager is used to keep track of all running (or scheduled) Tasks and sends 10 | * events to registered TaskListeners, optionally using the event dispatch thread for event 11 | * delivery.

12 | * 13 | *

A Task contains, in addition to a Callable and the related Future, additional information 14 | * like a TaskManager-related unique Task ID, a name, a description and a map of Strings that can 15 | * be used for arbitrary additional meta data.

16 | */ 17 | package de.huxhorn.sulky.tasks; 18 | -------------------------------------------------------------------------------- /sulky-tasks/src/test/resources/logback-test.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | %-5level - %d{HH:mm:ss.SSS} [%thread] - %file:%line - %msg%n%ex{full} 7 | 8 | 9 | 10 | 18 | 19 | 20 | 21 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /sulky-version/src/main/java/de/huxhorn/sulky/version/ClassStatisticMapper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * sulky-modules - several general-purpose modules. 3 | * Copyright (C) 2007-2015 Joern Huxhorn 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Lesser General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | /* 20 | * Copyright 2007-2015 Joern Huxhorn 21 | * 22 | * Licensed under the Apache License, Version 2.0 (the "License"); 23 | * you may not use this file except in compliance with the License. 24 | * You may obtain a copy of the License at 25 | * 26 | * http://www.apache.org/licenses/LICENSE-2.0 27 | * 28 | * Unless required by applicable law or agreed to in writing, software 29 | * distributed under the License is distributed on an "AS IS" BASIS, 30 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 31 | * See the License for the specific language governing permissions and 32 | * limitations under the License. 33 | */ 34 | 35 | package de.huxhorn.sulky.version; 36 | 37 | public interface ClassStatisticMapper 38 | { 39 | void evaluate(String source, String packageName, String className, char majorVersion); 40 | void reset(); 41 | } 42 | -------------------------------------------------------------------------------- /sulky-version/src/main/java/de/huxhorn/sulky/version/mappers/HighestVersionMapper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * sulky-modules - several general-purpose modules. 3 | * Copyright (C) 2007-2018 Joern Huxhorn 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Lesser General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | /* 20 | * Copyright 2007-2018 Joern Huxhorn 21 | * 22 | * Licensed under the Apache License, Version 2.0 (the "License"); 23 | * you may not use this file except in compliance with the License. 24 | * You may obtain a copy of the License at 25 | * 26 | * http://www.apache.org/licenses/LICENSE-2.0 27 | * 28 | * Unless required by applicable law or agreed to in writing, software 29 | * distributed under the License is distributed on an "AS IS" BASIS, 30 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 31 | * See the License for the specific language governing permissions and 32 | * limitations under the License. 33 | */ 34 | 35 | package de.huxhorn.sulky.version.mappers; 36 | 37 | import de.huxhorn.sulky.version.ClassFileVersion; 38 | import de.huxhorn.sulky.version.ClassStatisticMapper; 39 | 40 | @SuppressWarnings("PMD.AvoidThrowingNullPointerException") // target is Java 1.6 41 | public class HighestVersionMapper 42 | implements ClassStatisticMapper 43 | { 44 | private char highestVersionChar =0; 45 | 46 | public char getHighestVersionChar() 47 | { 48 | return highestVersionChar; 49 | } 50 | 51 | public ClassFileVersion getHighestVersion() 52 | { 53 | return ClassFileVersion.getByMajorVersionChar(highestVersionChar); 54 | } 55 | 56 | @Override 57 | public void evaluate(String source, String packageName, String className, char majorVersion) 58 | { 59 | if(source == null) 60 | { 61 | throw new NullPointerException("'source' must not be null!"); 62 | } 63 | if(packageName == null) 64 | { 65 | throw new NullPointerException("'packageName' must not be null!"); 66 | } 67 | if(className == null) 68 | { 69 | throw new NullPointerException("'className' must not be null!"); 70 | } 71 | 72 | if(majorVersion > highestVersionChar) 73 | { 74 | highestVersionChar = majorVersion; 75 | } 76 | } 77 | 78 | @Override 79 | public void reset() 80 | { 81 | highestVersionChar = 0; 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /sulky-version/src/main/java/de/huxhorn/sulky/version/mappers/PackageVersionMapper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * sulky-modules - several general-purpose modules. 3 | * Copyright (C) 2007-2018 Joern Huxhorn 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Lesser General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | /* 20 | * Copyright 2007-2018 Joern Huxhorn 21 | * 22 | * Licensed under the Apache License, Version 2.0 (the "License"); 23 | * you may not use this file except in compliance with the License. 24 | * You may obtain a copy of the License at 25 | * 26 | * http://www.apache.org/licenses/LICENSE-2.0 27 | * 28 | * Unless required by applicable law or agreed to in writing, software 29 | * distributed under the License is distributed on an "AS IS" BASIS, 30 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 31 | * See the License for the specific language governing permissions and 32 | * limitations under the License. 33 | */ 34 | 35 | package de.huxhorn.sulky.version.mappers; 36 | 37 | import de.huxhorn.sulky.version.ClassStatisticMapper; 38 | import java.util.HashMap; 39 | import java.util.Map; 40 | import java.util.Set; 41 | import java.util.TreeSet; 42 | 43 | @SuppressWarnings("PMD.AvoidThrowingNullPointerException") // target is Java 1.6 44 | public class PackageVersionMapper 45 | implements ClassStatisticMapper 46 | { 47 | @SuppressWarnings("PMD.UseDiamondOperator") // target is Java 1.6 48 | private final Map> packageVersions=new HashMap>(); 49 | 50 | public Map> getPackageVersions() 51 | { 52 | return packageVersions; 53 | } 54 | 55 | @Override 56 | @SuppressWarnings("PMD.UseDiamondOperator") // target is Java 1.6 57 | public void evaluate(String source, String packageName, String className, char majorVersion) 58 | { 59 | if(source == null) 60 | { 61 | throw new NullPointerException("'source' must not be null!"); 62 | } 63 | if(packageName == null) 64 | { 65 | throw new NullPointerException("'packageName' must not be null!"); 66 | } 67 | if(className == null) 68 | { 69 | throw new NullPointerException("'className' must not be null!"); 70 | } 71 | 72 | Set versions = packageVersions.get(packageName); 73 | if(versions == null) 74 | { 75 | versions = new TreeSet(); 76 | packageVersions.put(packageName, versions); 77 | } 78 | versions.add(majorVersion); 79 | } 80 | 81 | @Override 82 | public void reset() 83 | { 84 | packageVersions.clear(); 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /sulky-version/src/main/java/de/huxhorn/sulky/version/mappers/SourceVersionMapper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * sulky-modules - several general-purpose modules. 3 | * Copyright (C) 2007-2018 Joern Huxhorn 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Lesser General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | /* 20 | * Copyright 2007-2018 Joern Huxhorn 21 | * 22 | * Licensed under the Apache License, Version 2.0 (the "License"); 23 | * you may not use this file except in compliance with the License. 24 | * You may obtain a copy of the License at 25 | * 26 | * http://www.apache.org/licenses/LICENSE-2.0 27 | * 28 | * Unless required by applicable law or agreed to in writing, software 29 | * distributed under the License is distributed on an "AS IS" BASIS, 30 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 31 | * See the License for the specific language governing permissions and 32 | * limitations under the License. 33 | */ 34 | 35 | package de.huxhorn.sulky.version.mappers; 36 | 37 | import de.huxhorn.sulky.version.ClassStatisticMapper; 38 | import java.util.HashMap; 39 | import java.util.Map; 40 | import java.util.Set; 41 | import java.util.TreeSet; 42 | 43 | @SuppressWarnings("PMD.AvoidThrowingNullPointerException") // target is Java 1.6 44 | public class SourceVersionMapper 45 | implements ClassStatisticMapper 46 | { 47 | @SuppressWarnings("PMD.UseDiamondOperator") // target is Java 1.6 48 | private final Map> sourceVersions = new HashMap>(); 49 | 50 | public Map> getSourceVersions() 51 | { 52 | return sourceVersions; 53 | } 54 | 55 | @Override 56 | @SuppressWarnings("PMD.UseDiamondOperator") // target is Java 1.6 57 | public void evaluate(String source, String packageName, String className, char majorVersion) 58 | { 59 | if(source == null) 60 | { 61 | throw new NullPointerException("'source' must not be null!"); 62 | } 63 | if(packageName == null) 64 | { 65 | throw new NullPointerException("'packageName' must not be null!"); 66 | } 67 | if(className == null) 68 | { 69 | throw new NullPointerException("'className' must not be null!"); 70 | } 71 | 72 | Set versions = sourceVersions.get(source); 73 | if(versions == null) 74 | { 75 | versions = new TreeSet(); 76 | sourceVersions.put(source, versions); 77 | } 78 | versions.add(majorVersion); 79 | } 80 | 81 | @Override 82 | public void reset() 83 | { 84 | sourceVersions.clear(); 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /sulky-version/src/test/groovy/de/huxhorn/sulky/version/ExceptionMainClass.java: -------------------------------------------------------------------------------- 1 | /* 2 | * sulky-modules - several general-purpose modules. 3 | * Copyright (C) 2007-2017 Joern Huxhorn 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Lesser General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | /* 20 | * Copyright 2007-2017 Joern Huxhorn 21 | * 22 | * Licensed under the Apache License, Version 2.0 (the "License"); 23 | * you may not use this file except in compliance with the License. 24 | * You may obtain a copy of the License at 25 | * 26 | * http://www.apache.org/licenses/LICENSE-2.0 27 | * 28 | * Unless required by applicable law or agreed to in writing, software 29 | * distributed under the License is distributed on an "AS IS" BASIS, 30 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 31 | * See the License for the specific language governing permissions and 32 | * limitations under the License. 33 | */ 34 | 35 | package de.huxhorn.sulky.version; 36 | 37 | @SuppressWarnings("PMD.AvoidThrowingRawExceptionTypes") 38 | public final class ExceptionMainClass 39 | { 40 | private ExceptionMainClass() {} 41 | public static void main(String[] args) 42 | { 43 | throw new RuntimeException("Nope."); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /sulky-version/src/test/groovy/de/huxhorn/sulky/version/MissingMainClass.java: -------------------------------------------------------------------------------- 1 | /* 2 | * sulky-modules - several general-purpose modules. 3 | * Copyright (C) 2007-2015 Joern Huxhorn 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Lesser General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | /* 20 | * Copyright 2007-2015 Joern Huxhorn 21 | * 22 | * Licensed under the Apache License, Version 2.0 (the "License"); 23 | * you may not use this file except in compliance with the License. 24 | * You may obtain a copy of the License at 25 | * 26 | * http://www.apache.org/licenses/LICENSE-2.0 27 | * 28 | * Unless required by applicable law or agreed to in writing, software 29 | * distributed under the License is distributed on an "AS IS" BASIS, 30 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 31 | * See the License for the specific language governing permissions and 32 | * limitations under the License. 33 | */ 34 | 35 | package de.huxhorn.sulky.version; 36 | 37 | public class MissingMainClass 38 | { 39 | } 40 | -------------------------------------------------------------------------------- /sulky-version/src/test/groovy/de/huxhorn/sulky/version/NonPublicMainClass.java: -------------------------------------------------------------------------------- 1 | /* 2 | * sulky-modules - several general-purpose modules. 3 | * Copyright (C) 2007-2017 Joern Huxhorn 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Lesser General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | /* 20 | * Copyright 2007-2017 Joern Huxhorn 21 | * 22 | * Licensed under the Apache License, Version 2.0 (the "License"); 23 | * you may not use this file except in compliance with the License. 24 | * You may obtain a copy of the License at 25 | * 26 | * http://www.apache.org/licenses/LICENSE-2.0 27 | * 28 | * Unless required by applicable law or agreed to in writing, software 29 | * distributed under the License is distributed on an "AS IS" BASIS, 30 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 31 | * See the License for the specific language governing permissions and 32 | * limitations under the License. 33 | */ 34 | 35 | package de.huxhorn.sulky.version; 36 | 37 | public class NonPublicMainClass 38 | { 39 | void main(String[] args) 40 | { 41 | // just testing 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /sulky-version/src/test/groovy/de/huxhorn/sulky/version/TestMainClass.java: -------------------------------------------------------------------------------- 1 | /* 2 | * sulky-modules - several general-purpose modules. 3 | * Copyright (C) 2007-2017 Joern Huxhorn 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Lesser General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | /* 20 | * Copyright 2007-2017 Joern Huxhorn 21 | * 22 | * Licensed under the Apache License, Version 2.0 (the "License"); 23 | * you may not use this file except in compliance with the License. 24 | * You may obtain a copy of the License at 25 | * 26 | * http://www.apache.org/licenses/LICENSE-2.0 27 | * 28 | * Unless required by applicable law or agreed to in writing, software 29 | * distributed under the License is distributed on an "AS IS" BASIS, 30 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 31 | * See the License for the specific language governing permissions and 32 | * limitations under the License. 33 | */ 34 | 35 | package de.huxhorn.sulky.version; 36 | 37 | public final class TestMainClass 38 | { 39 | private TestMainClass() {} 40 | public static void main(String[] args) 41 | { 42 | // just testing 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /sulky-version/src/test/groovy/de/huxhorn/sulky/version/mappers/AbstractMapperSpec.groovy: -------------------------------------------------------------------------------- 1 | /* 2 | * sulky-modules - several general-purpose modules. 3 | * Copyright (C) 2007-2015 Joern Huxhorn 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Lesser General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | /* 20 | * Copyright 2007-2015 Joern Huxhorn 21 | * 22 | * Licensed under the Apache License, Version 2.0 (the "License"); 23 | * you may not use this file except in compliance with the License. 24 | * You may obtain a copy of the License at 25 | * 26 | * http://www.apache.org/licenses/LICENSE-2.0 27 | * 28 | * Unless required by applicable law or agreed to in writing, software 29 | * distributed under the License is distributed on an "AS IS" BASIS, 30 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 31 | * See the License for the specific language governing permissions and 32 | * limitations under the License. 33 | */ 34 | 35 | package de.huxhorn.sulky.version.mappers 36 | 37 | import de.huxhorn.sulky.version.ClassStatisticMapper 38 | import spock.lang.Specification 39 | 40 | abstract class AbstractMapperSpec extends Specification { 41 | abstract ClassStatisticMapper createInstance() 42 | 43 | def "null source throws correct exception."() { 44 | when: 45 | ClassStatisticMapper instance = createInstance() 46 | instance.evaluate(null, 'packageName', 'className', 0x31 as char) 47 | 48 | then: 49 | NullPointerException ex = thrown() 50 | ex.message == "'source' must not be null!" 51 | } 52 | 53 | def "null packageName throws correct exception."() { 54 | when: 55 | ClassStatisticMapper instance = createInstance() 56 | instance.evaluate('source', null, 'className', 0x31 as char) 57 | 58 | then: 59 | NullPointerException ex = thrown() 60 | ex.message == "'packageName' must not be null!" 61 | } 62 | 63 | def "null className throws correct exception."() { 64 | when: 65 | ClassStatisticMapper instance = createInstance() 66 | instance.evaluate('source', 'packageName', null, 0x31 as char) 67 | 68 | then: 69 | NullPointerException ex = thrown() 70 | ex.message == "'className' must not be null!" 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /sulky-version/src/test/resources/classNotFound.properties: -------------------------------------------------------------------------------- 1 | main.class=de.huxhorn.sulky.version.ClassNotFound 2 | java.version=1.8 3 | system.exit=false 4 | show.error.dialog=false 5 | # unknown.version.fail=false 6 | -------------------------------------------------------------------------------- /sulky-version/src/test/resources/exceptionMain.properties: -------------------------------------------------------------------------------- 1 | main.class=de.huxhorn.sulky.version.ExceptionMainClass 2 | java.version=1.8 3 | system.exit=false 4 | show.error.dialog=false 5 | # unknown.version.fail=false 6 | -------------------------------------------------------------------------------- /sulky-version/src/test/resources/foo.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huxi/sulky/27c8d809f2e3af6eafa9c7324f158cd9b482b351/sulky-version/src/test/resources/foo.jar -------------------------------------------------------------------------------- /sulky-version/src/test/resources/invalidJavaVersion.properties: -------------------------------------------------------------------------------- 1 | main.class=de.huxhorn.sulky.version.TestMainClass 2 | java.version=1.foo 3 | system.exit=false 4 | show.error.dialog=false 5 | # unknown.version.fail=false 6 | -------------------------------------------------------------------------------- /sulky-version/src/test/resources/main.properties: -------------------------------------------------------------------------------- 1 | main.class=de.huxhorn.sulky.version.TestMainClass 2 | java.version=1.8 3 | system.exit=false 4 | show.error.dialog=false 5 | # unknown.version.fail=false 6 | -------------------------------------------------------------------------------- /sulky-version/src/test/resources/malformed.properties: -------------------------------------------------------------------------------- 1 | main.class=de.huxhorn.sulky.version.NonPublicMainClass 2 | java.version=1.8 3 | system.exit=false 4 | show.error.dialog=false 5 | malformed=\uxyz 6 | # unknown.version.fail=false 7 | -------------------------------------------------------------------------------- /sulky-version/src/test/resources/missingJavaVersion.properties: -------------------------------------------------------------------------------- 1 | main.class=de.huxhorn.sulky.version.TestMainClass 2 | system.exit=false 3 | show.error.dialog=false 4 | # unknown.version.fail=false 5 | -------------------------------------------------------------------------------- /sulky-version/src/test/resources/missingMain.properties: -------------------------------------------------------------------------------- 1 | main.class=de.huxhorn.sulky.version.MissingMainClass 2 | java.version=1.8 3 | system.exit=false 4 | show.error.dialog=false 5 | # unknown.version.fail=false 6 | -------------------------------------------------------------------------------- /sulky-version/src/test/resources/missingMainClass.properties: -------------------------------------------------------------------------------- 1 | java.version=1.8 2 | system.exit=false 3 | show.error.dialog=false 4 | # unknown.version.fail=false 5 | -------------------------------------------------------------------------------- /sulky-version/src/test/resources/nonPublicMain.properties: -------------------------------------------------------------------------------- 1 | main.class=de.huxhorn.sulky.version.NonPublicMainClass 2 | java.version=1.8 3 | system.exit=false 4 | show.error.dialog=false 5 | # unknown.version.fail=false 6 | -------------------------------------------------------------------------------- /sulky-version/src/test/resources/slf4j-api-1.7.10.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huxi/sulky/27c8d809f2e3af6eafa9c7324f158cd9b482b351/sulky-version/src/test/resources/slf4j-api-1.7.10.jar -------------------------------------------------------------------------------- /sulky-version/src/test/resources/slf4j-api-1.7.9.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huxi/sulky/27c8d809f2e3af6eafa9c7324f158cd9b482b351/sulky-version/src/test/resources/slf4j-api-1.7.9.jar -------------------------------------------------------------------------------- /sulky-version/src/test/resources/versionMismatch.properties: -------------------------------------------------------------------------------- 1 | main.class=de.huxhorn.sulky.version.TestMainClass 2 | java.version=99.8 3 | system.exit=false 4 | show.error.dialog=false 5 | # unknown.version.fail=false 6 | --------------------------------------------------------------------------------