Merge branch 'develop'

This commit is contained in:
Taro L. Saito 2014-07-04 14:11:54 +09:00
commit 08fbe52c23
58 changed files with 1229 additions and 494 deletions

2
.gitignore vendored
View File

@ -20,4 +20,6 @@ project/plugins/project/
# Scala-IDE specific
.scala_dependencies
atlassian-ide-plugin.xml

15
.travis.yml Normal file
View File

@ -0,0 +1,15 @@
language: scala
scala:
- 2.11.1
jdk:
- openjdk6
- openjdk7
- oraclejdk7
branches:
only:
- master
- develop
script: ./sbt test

View File

@ -2,6 +2,7 @@
include Makefile.common
MVN:=mvn
SBT:=./sbt
all: snappy
@ -13,6 +14,16 @@ SNAPPY_SRC:=$(addprefix $(SNAPPY_SRC_DIR)/,$(SNAPPY_CC))
SNAPPY_OBJ:=$(addprefix $(SNAPPY_OUT)/,$(patsubst %.cc,%.o,$(SNAPPY_CC)) SnappyNative.o)
SNAPPY_UNPACKED:=$(TARGET)/snappy-extracted.log
SNAPPY_GIT_UNPACKED:=$(TARGET)/snappy-git-extracted.log
ifdef USE_GIT
ifndef GIT_REPO_URL
$(warning GIT_REPO_URL is not set when using git)
endif
ifndef GIT_SNAPPY_BRANCH
$(warning GIT_SNAPPY_BRANCH is not set when using git)
endif
endif
CXXFLAGS:=$(CXXFLAGS) -I$(SNAPPY_SRC_DIR)
@ -29,24 +40,29 @@ $(SNAPPY_ARCHIVE):
$(SNAPPY_UNPACKED): $(SNAPPY_ARCHIVE)
$(TAR) xvfz $< -C $(TARGET)
touch $@
cd $(SNAPPY_SRC_DIR) && ./configure
$(SNAPPY_GIT_UNPACKED):
@mkdir -p $(SNAPPY_SRC_DIR)
git clone $(GIT_REPO_URL) $(SNAPPY_SRC_DIR)
git --git-dir=$(SNAPPY_SRC_DIR)/.git --work-tree=$(SNAPPY_SRC_DIR) checkout -b local/snappy-$(GIT_SNAPPY_BRANCH) $(GIT_SNAPPY_BRANCH)
touch $@
cd $(SNAPPY_SRC_DIR) && ./configure
jni-header: $(SRC)/org/xerial/snappy/SnappyNative.h
$(TARGET)/classes/org/xerial/snappy/SnappyNative.class : $(SRC)/org/xerial/snappy/SnappyNative.java
@mkdir -p $(TARGET)/classes
$(JAVAC) -source 1.6 -target 1.6 -d $(TARGET)/classes -sourcepath $(SRC) $<
$(TARGET)/jni-classes/org/xerial/snappy/SnappyNative.class : $(SRC)/org/xerial/snappy/SnappyNative.java
@mkdir -p $(TARGET)/jni-classes
$(JAVAC) -source 1.6 -target 1.6 -d $(TARGET)/jni-classes -sourcepath $(SRC) $<
$(SRC)/org/xerial/snappy/SnappyNative.h: $(TARGET)/classes/org/xerial/snappy/SnappyNative.class
$(JAVAH) -classpath $(TARGET)/classes -o $@ org.xerial.snappy.SnappyNative
$(SRC)/org/xerial/snappy/SnappyNative.h: $(TARGET)/jni-classes/org/xerial/snappy/SnappyNative.class
$(JAVAH) -force -classpath $(TARGET)/classes -o $@ org.xerial.snappy.SnappyNative
bytecode: src/main/resources/org/xerial/snappy/SnappyNativeLoader.bytecode
src/main/resources/org/xerial/snappy/SnappyNativeLoader.bytecode: src/main/resources/org/xerial/snappy/SnappyNativeLoader.java
@mkdir -p $(TARGET)/temp
$(JAVAC) -source 1.5 -target 1.5 -d $(TARGET)/temp $<
cp $(TARGET)/temp/org/xerial/snappy/SnappyNativeLoader.class $@
$(SNAPPY_SRC): $(SNAPPY_UNPACKED)
ifndef USE_GIT
$(SNAPPY_SRC): $(SNAPPY_UNPACKED)
else
$(SNAPPY_SRC): $(SNAPPY_GIT_UNPACKED)
endif
$(SNAPPY_OUT)/%.o : $(SNAPPY_SRC_DIR)/%.cc
@mkdir -p $(@D)
@ -71,9 +87,13 @@ NATIVE_DIR:=src/main/resources/org/xerial/snappy/native/$(OS_NAME)/$(OS_ARCH)
NATIVE_TARGET_DIR:=$(TARGET)/classes/org/xerial/snappy/native/$(OS_NAME)/$(OS_ARCH)
NATIVE_DLL:=$(NATIVE_DIR)/$(LIBNAME)
snappy-jar-version:=snappy-java-$(shell $(JAVA) -jar lib/silk-weaver.jar find 'project(artifactId, version)' pom.xml | grep snappy-java | awk '{ print $$2; }')
snappy-jar-version:=snappy-java-$(shell perl -npe "s/version in ThisBuild\s+:=\s+\"(.*)\"/\1/" version.sbt | sed -e "/^$$/d")
native: $(SNAPPY_UNPACKED) $(NATIVE_DLL)
ifndef USE_GIT
native: $(SNAPPY_UNPACKED) $(NATIVE_DLL)
else
native: $(SNAPPY_GIT_UNPACKED) $(NATIVE_DLL)
endif
snappy: native $(TARGET)/$(snappy-jar-version).jar
$(NATIVE_DLL): $(SNAPPY_OUT)/$(LIBNAME)
@ -83,11 +103,13 @@ $(NATIVE_DLL): $(SNAPPY_OUT)/$(LIBNAME)
cp $< $(NATIVE_TARGET_DIR)/$(LIBNAME)
$(TARGET)/$(snappy-jar-version).jar: native $(NATIVE_DLL)
$(MVN) package -Dmaven.test.skip=true
package: $(TARGET)/$(snappy-jar-version).jar
$(TARGET)/$(snappy-jar-version).jar:
$(SBT) package
test: $(NATIVE_DLL)
$(MVN) test
$(SBT) test
win32:
$(MAKE) native CROSS_PREFIX=i686-w64-mingw32- OS_NAME=Windows OS_ARCH=x86
@ -120,8 +142,10 @@ clean-native-win32:
$(MAKE) clean-native OS_NAME=Windows OS_ARCH=x86
javadoc:
$(MVN) javadoc:javadoc -DreportOutputDirectory=wiki/apidocs
$(SBT) doc
install-m2:
$(SBT) publishM2
googlecode-upload: googlecode-lib-upload googlecode-src-upload

View File

@ -22,6 +22,7 @@ OSINFO_PROG := lib/org/xerial/snappy/OSInfo.class
OS_NAME := $(shell $(JAVA) -cp lib $(OSINFO_CLASS) --os)
OS_ARCH := $(shell $(JAVA) -cp lib $(OSINFO_CLASS) --arch)
LIB_FOLDER := $(shell $(JAVA) -cp lib $(OSINFO_CLASS))
IBM_JDK_LIB := lib/inc_ibm
# Windows uses different path separators
ifeq ($(OS_NAME),Windows)
@ -41,13 +42,24 @@ endif
# os=Default is meant to be generic unix/linux
known_os_archs := Linux-x86 Linux-x86_64 Linux-arm Linux-armhf Mac-x86 Mac-x86_64 FreeBSD-x86_64 Windows-x86 Windows-x86_64 SunOS-x86 SunOS-sparc
known_os_archs := Linux-x86 Linux-x86_64 Linux-arm Linux-armhf Linux-ppc64 Mac-x86 Mac-x86_64 FreeBSD-x86_64 Windows-x86 Windows-x86_64 SunOS-x86 SunOS-sparc SunOS-x86_64
os_arch := $(OS_NAME)-$(OS_ARCH)
IBM_JDK_7 := $(findstring IBM, $(shell $(JAVA) -version 2>&1 | grep IBM | grep "JRE 1.7"))
ifeq (,$(findstring $(strip $(os_arch)),$(known_os_archs)))
os_arch := Default
endif
ifneq ($(IBM_JDK_7),)
$(shell mkdir -p $(IBM_JDK_LIB))
$(shell cp $(JAVA_HOME)/include/jniport.h $(IBM_JDK_LIB))
$(shell sed -i "s|#define JNIEXPORT *$$|#define JNIEXPORT __attribute__((__visibility__(\"default\")))|" $(IBM_JDK_LIB)/jniport.h)
$(shell sed -i "s|typedef long long jlong;.*|/*typedef long long jlong;*/|" $(IBM_JDK_LIB)/jniport.h)
$(shell cp $(JAVA_HOME)/include/linux/jni_md.h $(IBM_JDK_LIB))
$(shell sed -i "s|#define JNIEXPORT|#define JNIEXPORT __attribute__((__visibility__(\"default\")))|" $(IBM_JDK_LIB)/jni_md.h)
$(shell sed -i "s|typedef long long jlong;.*|/*typedef long long jlong;*/|" $(IBM_JDK_LIB)/jni_md.h)
endif
# cross-compilation toolchain prefix (e.g. "arm-linux-gnueabi-")
CROSS_PREFIX :=
@ -60,18 +72,37 @@ Default_SNAPPY_FLAGS :=
Linux-x86_CXX := $(CROSS_PREFIX)g++
Linux-x86_STRIP := $(CROSS_PREFIX)strip
Linux-x86_CXXFLAGS := -include lib/inc_linux/jni_md.h -I$(JAVA_HOME)/include -O2 -fPIC -fvisibility=hidden -m32
ifeq ($(IBM_JDK_7),)
Linux-x86_CXXFLAGS := -include lib/inc_linux/jni_md.h -I$(JAVA_HOME)/include -O2 -fPIC -fvisibility=hidden -m32
else
Linux-x86_CXXFLAGS := -include $(IBM_JDK_LIB)/jni_md.h -include $(IBM_JDK_LIB)/jniport.h -I$(JAVA_HOME)/include -O2 -fPIC -fvisibility=hidden -m32
endif
Linux-x86_LINKFLAGS := -shared -static-libgcc -static-libstdc++
Linux-x86_LIBNAME := libsnappyjava.so
Linux-x86_SNAPPY_FLAGS:=
Linux-x86_64_CXX := $(CROSS_PREFIX)g++
Linux-x86_64_STRIP := $(CROSS_PREFIX)strip
Linux-x86_64_CXXFLAGS := -include lib/inc_linux/jni_md.h -I$(JAVA_HOME)/include -O2 -fPIC -fvisibility=hidden -m64
ifeq ($(IBM_JDK_7),)
Linux-x86_64_CXXFLAGS := -Ilib/inc_linux -I$(JAVA_HOME)/include -Ilib/inc_mac -O2 -fPIC -fvisibility=hidden -m64
else
Linux-x86_64_CXXFLAGS := -include $(IBM_JDK_LIB)/jni_md.h -include $(IBM_JDK_LIB)/jniport.h -I$(JAVA_HOME)/include -Ilib/inc_mac -O2 -fPIC -fvisibility=hidden -m64
endif
Linux-x86_64_LINKFLAGS := -shared -static-libgcc -static-libstdc++
Linux-x86_64_LIBNAME := libsnappyjava.so
Linux-x86_64_SNAPPY_FLAGS :=
Linux-ppc64_CXX := g++
Linux-ppc64_STRIP := strip
ifeq ($(IBM_JDK_7),)
Linux-ppc64_CXXFLAGS := -DHAVE_CONFIG_H -Ilib/inc_linux -I$(JAVA_HOME)/include -Ilib/inc_mac -O2 -fPIC -fvisibility=hidden -m64
else
Linux-ppc64_CXXFLAGS := -DHAVE_CONFIG_H -include $(IBM_JDK_LIB)/jni_md.h -include $(IBM_JDK_LIB)/jniport.h -I$(JAVA_HOME)/include -I$(JAVA_HOME)/include/linux -O2 -fPIC
endif
Linux-ppc64_LINKFLAGS := -shared -static-libgcc -static-libstdc++
Linux-ppc64_LIBNAME := libsnappyjava.so
Linux-ppc64_SNAPPY_FLAGS :=
SunOS-x86_CXX := g++
SunOS-x86_STRIP := strip
SunOS-x86_CXXFLAGS := -include lib/inc_linux/jni_md.h -I$(JAVA_HOME)/include -O2 -fPIC -fvisibility=hidden
@ -86,6 +117,13 @@ SunOS-sparc_LINKFLAGS := -shared -static-libgcc -static-libstdc++
SunOS-sparc_LIBNAME := libsnappyjava.so
SunOS-sparc_SNAPPY_FLAGS :=
SunOS-x86_64_CXX := g++
SunOS-x86_64_STRIP := strip
SunOS-x86_64_CXXFLAGS := -include lib/inc_linux/jni_md.h -I$(JAVA_HOME)/include -O2 -fPIC -fvisibility=hidden -m64
SunOS-x86_64_LINKFLAGS := -shared -static-libgcc -static-libstdc++
SunOS-x86_64_LIBNAME := libsnappyjava.so
SunOS-x86_64_SNAPPY_FLAGS :=
# '-include lib/inc_linux/jni_md.h' is used to force the use of our version,
# which defines JNIEXPORT differently; otherwise, since OpenJDK includes
# jni_md.h in same directory as jni.h, the include path is ignored when
@ -115,7 +153,7 @@ Mac-x86_SNAPPY_FLAGS :=
Mac-x86_64_CXX := g++ -arch $(OS_ARCH)
Mac-x86_64_STRIP := strip -x
Mac-x86_64_CXXFLAGS := -Ilib/inc_mac -I$(JAVA_HOME)/include -O2 -fPIC -mmacosx-version-min=10.5 -fvisibility=hidden
Mac-x86_64_LINKFLAGS := -dynamiclib -static-libgcc
Mac-x86_64_LINKFLAGS := -dynamiclib
Mac-x86_64_LIBNAME := libsnappyjava.jnilib
Mac-x86_64_SNAPPY_FLAGS :=

View File

@ -2,6 +2,37 @@
* `SnappyIndexer` for parallel compression/decompression
* CUI commands (snap/unsnap)
Since vesion 1.1.0.x, Java 6 (1.6) or higher is required.
## snappy-java-1.1.1 (4 July 2014)
* Added Snappy framing format support: SnappyFramedInput/OutputStream
* Added native libraries for PowerPC, IBM-AIX 6.4, SunOS.
# snappy-java-1.1.1-M4 (4 July 2014)
* Add linux-x86_64 native library, embedding libstdc++
* IBM AIX 6.1 support
* A fix for loading in OSGi in Mac OS X (#76)
# snappy-java-1.1.1-M3 (26 June 2014)
* Add PowerPC support (ppc64, ppc64le)
* Building with sbt
# snappy-java-1.0.5.2 (25 June 2014)
* Maintanance release
* Add PowerPC support ppc64le, ppc64 (big-endian)
# snappy-java-1.1.1-M2 (12 June 2014)
* Bug fixes and some optimization of SnappyFramedFormat
* Added a native library for ppc64le
* Preview build (without libstdc++ embedded for Linux/x86_64)
## snappy-java-1.1.1-M1
* Preview build (without libstdc++ embedded for Linux/x86_64)
## snappy-java-1.1.0.1 (8 November 2013)
* Add SunOS/x86_64 support
## snappy-java-1.1.0 (17 October 2013)
* Add Snappy framed format support (SnappyFramedInputStream, SnappyFramedOutputStream)
* Add SunOS support
@ -83,4 +114,4 @@
* Adding `SnappyOutputStream` `SnappyInputStream` issue 3
* March 29th. Started snappy-java project
* March 29th. Started snappy-java project

View File

@ -2,13 +2,14 @@ The snappy-java is a Java port of the snappy
<http://code.google.com/p/snappy/>, a fast C++ compresser/decompresser developed by Google.
## Features
* [Apache License Version 2.0](http://www.apache.org/licenses/LICENSE-2.0). Free for both commercial and non-commercial use.
* Fast compression/decompression tailored to 64-bit CPU architecture.
* JNI-based implementation to achieve comparable performance to the native C++ version.
* Although snappy-java uses JNI, it can be used safely with multiple class loaders (e.g. Tomcat, etc.).
* Portable across various operating systems; Snappy-java contains native libraries built for Window/Mac/Linux (64-bit). At runtime, snappy-java loads one of these libraries according to your machine environment (It looks system properties, `os.name` and `os.arch`).
* Simple usage. Add the snappy-java-(version).jar file to your classpath. Then call compression/decompression methods in org.xerial.snappy.Snappy.
* [Framing-format support](http://snappy.googlecode.com/svn/trunk/framing_format.txt) (Since 1.1.0-SNAPSHOT version)
* Portable across various operating systems; Snappy-java contains native libraries built for Window/Mac/Linux (64-bit). snappy-java loads one of these libraries according to your machine environment (It looks system properties, `os.name` and `os.arch`).
* Simple usage. Add the snappy-java-(version).jar file to your classpath. Then call compression/decompression methods in `org.xerial.snappy.Snappy`.
* [Framing-format support](http://snappy.googlecode.com/svn/trunk/framing_format.txt) (Since 1.1.0 version)
* OSGi support
* [Apache License Version 2.0](http://www.apache.org/licenses/LICENSE-2.0). Free for both commercial and non-commercial use.
## Performance
* Snappy's main target is very high-speed compression/decompression with reasonable compression size. So the compression ratio of snappy-java is modest and about the same as `LZF` (ranging 20%-100% according to the dataset).
@ -16,18 +17,22 @@ The snappy-java is a Java port of the snappy
* Here are some [benchmark results](https://github.com/ning/jvm-compressor-benchmark/wiki), comparing
snappy-java and the other compressors
`LZO-java`/`LZF`/`QuickLZ`/`Gzip`/`Bzip2`. Thanks [Tatu Saloranta @cotowncoder](http://twitter.com/#!/cowtowncoder) for providing the benchmark suite.
* The benchmark result indicates snappy-java is the fastest compreesor/decompressor in Java:
* The benchmark result indicates snappy-java is the fastest compreesor/decompressor in Java
* <http://ning.github.com/jvm-compressor-benchmark/results/canterbury-roundtrip-2011-07-28/index.html>
* The decompression speed is twice as fast as the others:
* <http://ning.github.com/jvm-compressor-benchmark/results/canterbury-uncompress-2011-07-28/index.html>
## Download
* [Release Notes](Milestone.md)
The current stable version is available from here:
* Release version: http://code.google.com/p/snappy-java/downloads/list
* [Release plans](Milestone.md)
* Release version: http://central.maven.org/maven2/org/xerial/snappy/snappy-java/
* (Old archives are here: http://code.google.com/p/snappy-java/downloads/list)
* Snapshot version (the latest beta version): https://oss.sonatype.org/content/repositories/snapshots/org/xerial/snappy/snappy-java/
If you are a Maven user, see [pom.xml example](#using-with-maven).
For Maven user, see [pom.xml example](#using-with-maven).
## Usage
First, import `org.xerial.snapy.Snappy` in your Java code:
@ -48,13 +53,12 @@ String result = new String(uncompressed, "UTF-8");
System.out.println(result);
```
In addition, high-level methods (`Snappy.compress(String)`, `Snappy.compress(float[] ..)` etc. ) and low-level ones (e.g. `Snappy.rawCompress(.. )`, `Snappy.rawUncompress(..)`, etc.), which minimize memory copies, can be used. See also
[Snappy.java](https://github.com/xerial/snappy-java/blob/master/src/main/java/org/xerial/snappy/Snappy.java)
In addition, high-level methods (`Snappy.compress(String)`, `Snappy.compress(float[] ..)` etc. ) and low-level ones (e.g. `Snappy.rawCompress(.. )`, `Snappy.rawUncompress(..)`, etc.), which minimize memory copies, can be used.
### Stream-based API
Stream-based compressor/decompressor `SnappyOutputStream`/`SnappyInputStream` are also available for reading/writing large data sets.
Stream-based compressor/decompressor `SnappyFramedOutputStream`/`SnappyFramedInputStream` are also available for reading/writing large data sets.
* [Javadoc API](https://oss.sonatype.org/service/local/repositories/releases/archive/org/xerial/snappy/snappy-java/1.1.0/snappy-java-1.1.0-javadoc.jar/!/index.html)
* See also [Javadoc API](https://oss.sonatype.org/service/local/repositories/releases/archive/org/xerial/snappy/snappy-java/1.1.0/snappy-java-1.1.0-javadoc.jar/!/index.html)
### Setting classpath
If you have snappy-java-(VERSION).jar in the current directory, use `-classpath` option as follows:
@ -77,6 +81,12 @@ Add the following dependency to your pom.xml:
<scope>compile</scope>
</dependency>
### Using with sbt
```
libraryDependencies += "org.xerial.snappy" % "snappy-java" % "(version)"
```
## Public discussion group
Post bug reports or feature request to the Issue Tracker: <https://github.com/xerial/snappy-java/issues>
@ -85,7 +95,7 @@ Public discussion forum is here: <http://groups.google.com/group/xerial?hl=en Xe
## Building from the source code
See the [installation instruction](https://github.com/xerial/snappy-java/blob/develop/INSTALL). Building from the source code is an option when your OS platform and CPU architecture is not supported. To build snappy-java, you need Git, JDK (1.6 or higher), Maven (3.x or higher is required), g++ compiler (mingw in Windows) etc.
See the [installation instruction](https://github.com/xerial/snappy-java/blob/develop/INSTALL). Building from the source code is an option when your OS platform and CPU architecture is not supported. To build snappy-java, you need Git, JDK (1.6 or higher), g++ compiler (mingw in Windows) etc.
$ git clone https://github.com/xerial/snappy-java.git
$ cd snappy-java
@ -97,11 +107,23 @@ When building on Solaris use
A file `target/snappy-java-$(version).jar` is the product additionally containing the native library built for your platform.
## Building linux amd64 binary
## Building linux x86_64 binary
snappy-java tries to static link libstdc++ to increase the availability for various Linux versions. However, standard distributions of 64-bit Linux OS rarely provide libstdc++ compiled with `-fPIC` option. I currently uses custom g++ compiled with the following options:
snappy-java tries to static link libstdc++ to increase the availability for various Linux versions. However, standard distributions of 64-bit Linux OS rarely provide libstdc++ compiled with `-fPIC` option. I currently uses custom g++, compiled as follows:
$ ./configure --prefix=$HOME/local --with-gmp=$HOME/local --with-mpfr=$HOME/local --with-mpc=$HOME/local --with-ppl=$HOME/local --with-cloog=$HOME/local CXXFLAGS=-fPIC CFLAGS=-fPIC
```
$ cd work
$ wget (gcc-4.8.3 source)
$ tar xvfz (gcc-4.8.3.tar.gz)
$ cd gcc-4.8.3
$ ./contrib/download_prerequisites
$ cd ..
$ mkdir objdir
$ cd objdir
$ ../gcc-4.8.3/configure --prefix=$HOME/local/gcc-4.8.3 CXXFLAGS=-fPIC CFLAGS=-fPIC --enable-languages=c,c++
$ make
$ make install
```
This g++ build enables static linking of libstdc++. For more infomation on building GCC, see GCC's home page.
@ -126,6 +148,18 @@ If you are using Mac and openjdk7 (or higher), use the following option:
$ make native LIBNAME=libsnappyjava.dylib
## For developers
snappy-java uses sbt (simple build tool for Scala) as a build tool. Here is a simple usage
$ ./sbt # enter sbt console
> ~test # run tests upon source code change
> ~test-only * # run tests that matches a given name pattern
> publishM2 # publish jar to $HOME/.m2/repository
> package # create jar file
For the details of sbt usage, see my blog post: [Building Java Projects with sbt](http://xerial.org/blog/2014/03/24/sbt/)
## Miscellaneous Notes
### Using snappy-java with Tomcat 6 (or higher) Web Server

102
build.sbt Normal file
View File

@ -0,0 +1,102 @@
import SonatypeKeys._
sonatypeSettings
name := "snappy-java"
organization := "org.xerial.snappy"
organizationName := "xerial.org"
description := "snappy-java: A fast compression/decompression library"
profileName := "org.xerial"
pomExtra := {
<url>https://github.comm/xerial/snappy-java</url>
<licenses>
<license>
<name>The Apache Software License, Version 2.0</name>
<url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
<distribution>repo</distribution>
</license>
</licenses>
<developers>
<developer>
<id>leo</id>
<name>Taro L. Saito</name>
<email>leo@xerial.org</email>
<organization>Xerial Project</organization>
<roles>
<role>Architect</role>
<role>Project Manager</role>
<role>Chief Developer</role>
</roles>
<timezone>+9</timezone>
</developer>
</developers>
<issueManagement>
<system>GitHub</system>
<url>http://github.com/xerial/snappy-java/issues/list</url>
</issueManagement>
<inceptionYear>2011</inceptionYear>
<scm>
<connection>scm:git@github.com:xerial/snappy-java.git</connection>
<developerConnection>scm:git:git@github.com:xerial/snappy-java.git</developerConnection>
<url>git@github.com:xerial/snappy-java.git</url>
</scm>
}
javacOptions in (Compile, compile) ++= Seq("-encoding", "UTF-8", "-Xlint:unchecked", "-Xlint:deprecation", "-source", "1.6", "-target", "1.6")
testOptions += Tests.Argument(TestFrameworks.JUnit, "-q", "-v")
//concurrentRestrictions in Global := Seq(Tags.limit(Tags.Test, 1))
autoScalaLibrary := false
crossPaths := false
logBuffered in Test := false
incOptions := incOptions.value.withNameHashing(true)
libraryDependencies ++= Seq(
"junit" % "junit" % "4.8.2" % "test",
"org.codehaus.plexus" % "plexus-classworlds" % "2.4" % "test",
"org.xerial" % "xerial-core" % "1.0.21" % "test",
"org.osgi" % "org.osgi.core" % "4.3.0" % "provided",
"com.novocode" % "junit-interface" % "0.10" % "test"
)
osgiSettings
OsgiKeys.exportPackage := Seq("org.xerial.snappy")
OsgiKeys.bundleSymbolicName := "org.xerial.snappy.snappy-java"
OsgiKeys.bundleActivator := Option("org.xerial.snappy.SnappyBundleActivator")
OsgiKeys.importPackage := Seq("""org.osgi.framework;version="[1.5,2)"""")
OsgiKeys.additionalHeaders := Map(
"Bundle-NativeCode" -> Seq(
"org/xerial/snappy/native/Windows/x86_64/snappyjava.dll;osname=win32;processor=x86-64",
"org/xerial/snappy/native/Windows/x86/snappyjava.dll;osname=win32;processor=x86",
"org/xerial/snappy/native/Mac/x86/libsnappyjava.jnilib;osname=macosx;processor=x86",
"org/xerial/snappy/native/Mac/x86_64/libsnappyjava.jnilib;osname=macosx;processor=x86-64",
"org/xerial/snappy/native/Linux/x86_64/libsnappyjava.so;osname=linux;processor=x86-64",
"org/xerial/snappy/native/Linux/x86/libsnappyjava.so;osname=linux;processor=x86",
"org/xerial/snappy/native/Linux/arm/libsnappyjava.so;osname=linux;processor=arm",
"org/xerial/snappy/native/Linux/ppc64/libsnappyjava.so;osname=linux;processor=ppc64",
"org/xerial/snappy/native/Linux/ppc64le/libsnappyjava.so;osname=linux;processor=ppc64le",
"org/xerial/snappy/native/SunOS/x86/libsnappyjava.so;osname=sunos;processor=x86",
"org/xerial/snappy/native/SunOS/x86_64/libsnappyjava.so;osname=sunos;processor=x86-64",
"org/xerial/snappy/native/SunOS/sparc/libsnappyjava.so;osname=sunos;processor=sparc"
).mkString(","),
"Bundle-DocURL" -> "http://www.xerial.org/",
"Bundle-License" -> "http://www.apache.org/licenses/LICENSE-2.0.txt",
"Bundle-ActivationPolicy" -> "lazy",
"Bundle-Name" -> "snappy-java: A fast compression/decompression library"
)

Binary file not shown.

Binary file not shown.

317
pom.xml
View File

@ -1,317 +0,0 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.xerial.snappy</groupId>
<artifactId>snappy-java</artifactId>
<version>1.1.0</version>
<name>Snappy for Java</name>
<description>snappy-java: A fast compression/decompression library</description>
<packaging>bundle</packaging>
<parent>
<groupId>org.sonatype.oss</groupId>
<artifactId>oss-parent</artifactId>
<version>7</version>
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<licenses>
<license>
<name>The Apache Software License, Version 2.0</name>
<url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
<distribution>repo</distribution>
</license>
</licenses>
<developers>
<developer>
<id>leo</id>
<name>Taro L. Saito</name>
<email>leo@xerial.org</email>
<organization>Xerial Project</organization>
<roles>
<role>Architect</role>
<role>Project Manager</role>
<role>Chief Developer</role>
</roles>
<timezone>+9</timezone>
</developer>
</developers>
<organization>
<name>xerial.org</name>
<url>http://www.xerial.org/</url>
</organization>
<build>
<resources>
<resource>
<directory>src/main/java</directory>
<includes>
<include>org/xerial/snappy/VERSION</include>
</includes>
</resource>
<resource>
<directory>src/main/resources</directory>
<includes>
<include>org/xerial/snappy/*.bytecode</include>
<include>org/xerial/snappy/native/**</include>
</includes>
</resource>
<resource>
<directory>${basedir}</directory>
<targetPath>META-INF/maven/${project.groupId}/${project.artifactId}</targetPath>
<includes>
<include>LICENSE*</include>
</includes>
</resource>
</resources>
<testResources>
<testResource>
<directory>src/test/java</directory>
<excludes>
<exclude>**/*.java</exclude>
</excludes>
</testResource>
<testResource>
<directory>src/test/resources</directory>
</testResource>
</testResources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.5</version>
<configuration>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.7</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.0.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-release-plugin</artifactId>
<version>2.1</version>
<configuration>
<!-- do not run site-deploy goal, included in the default settings -->
<goals>deploy</goals>
<pushChanges>false</pushChanges>
<localCheckout>true</localCheckout>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>
<version>1.4</version>
<configuration>
<useAgent>true</useAgent>
</configuration>
<executions>
<execution>
<id>sign-artifacts</id>
<phase>verify</phase>
<goals>
<goal>sign</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.8</version>
<configuration>
<charset>UTF-8</charset>
<locale>en_US</locale>
<show>public</show>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>2.1.2</version>
<configuration>
<excludeResources>true</excludeResources>
</configuration>
<executions>
<execution>
<id>attach-sources</id>
<phase>verify</phase>
<goals>
<goal>jar-no-fork</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<version>2.3.7</version>
<extensions>true</extensions>
<configuration>
<manifestLocation>${project.build.directory}/META-INF</manifestLocation>
<instructions>
<Bundle-SymbolicName>${project.groupId}.${project.artifactId}</Bundle-SymbolicName>
<Bundle-Name>${project.name}</Bundle-Name>
<Bundle-Version>${project.version}</Bundle-Version>
<Bundle-Activator>org.xerial.snappy.SnappyBundleActivator</Bundle-Activator>
<Export-Package>org.xerial.snappy</Export-Package>
<Import-Package>org.osgi.framework;version="[1.5,2)"</Import-Package>
<Bundle-ActivationPolicy>lazy</Bundle-ActivationPolicy>
<Bundle-NativeCode>
org/xerial/snappy/native/Windows/x86_64/snappyjava.dll;osname=win32;processor=x86-64,
org/xerial/snappy/native/Windows/x86/snappyjava.dll;osname=win32;processor=x86,
org/xerial/snappy/native/Mac/x86/libsnappyjava.jnilib;osname=macosx;processor=x86,
org/xerial/snappy/native/Mac/x86_64/libsnappyjava.jnilib;osname=macosx;processor=x86-64,
org/xerial/snappy/native/Linux/x86_64/libsnappyjava.so;osname=linux;processor=x86-64,
org/xerial/snappy/native/Linux/x86/libsnappyjava.so;osname=linux;processor=x86,
org/xerial/snappy/native/SunOS/x86/libsnappyjava.so;osname=sunos;processor=x86,
org/xerial/snappy/native/SunOS/sparc/libsnappyjava.so;osname=sunos;processor=sparc,
org/xerial/snappy/native/Linux/arm/libsnappyjava.so;osname=linux;processor=arm
</Bundle-NativeCode>
<!-- TODO: unsure about ARMHF -->
</instructions>
</configuration>
<executions>
<execution>
<id>bundle-manifest</id>
<phase>process-classes</phase>
<goals>
<goal>manifest</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
<configuration>
<archive>
<index>true</index>
<manifestFile>${project.build.directory}/META-INF/MANIFEST.MF</manifestFile>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-clean-plugin</artifactId>
<version>2.4.1</version>
<configuration>
<followSymLinks>false</followSymLinks>
<filesets>
<fileset>
<directory>META-INF</directory>
<includes>
<include>MANIFEST.MF</include>
</includes>
</fileset>
</filesets>
</configuration>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.2.1</version>
<configuration>
<descriptors>
<descriptor>src/assembly/project.xml</descriptor>
</descriptors>
<appendAssemblyId>false</appendAssemblyId>
<attach>false</attach>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
<extensions>
<extension>
<groupId>org.apache.maven.wagon</groupId>
<artifactId>wagon-ssh-external</artifactId>
<version>1.0-beta-7</version>
</extension>
</extensions>
</build>
<url>http://github.com/xerial/snappy-java/</url>
<issueManagement>
<system>GitHub</system>
<url>http://github.com/xerial/snappy-java/issues/list</url>
</issueManagement>
<inceptionYear>2011</inceptionYear>
<scm>
<connection>scm:git@github.com:xerial/snappy-java.git</connection>
<developerConnection>scm:git:git@github.com:xerial/snappy-java.git</developerConnection>
<url>git@github.com:xerial/snappy-java.git</url>
</scm>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.8.2</version>
<type>jar</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-classworlds</artifactId>
<version>2.4</version>
<type>jar</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.osgi</groupId>
<artifactId>core</artifactId>
<version>4.3.0</version>
<type>jar</type>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.xerial</groupId>
<artifactId>xerial-core</artifactId>
<version>1.0.21</version>
<type>jar</type>
<scope>test</scope>
</dependency>
</dependencies>
</project>

2
project/build.properties Executable file
View File

@ -0,0 +1,2 @@
sbt.version=0.13.5

12
project/plugins.sbt Executable file
View File

@ -0,0 +1,12 @@
addSbtPlugin("com.github.gseitz" % "sbt-release" % "0.7.1")
addSbtPlugin("org.xerial.sbt" % "sbt-sonatype" % "0.2.1")
addSbtPlugin("com.typesafe.sbt" % "sbt-pgp" % "0.8.3")
addSbtPlugin("de.johoop" % "findbugs4sbt" % "1.3.0")
addSbtPlugin("de.johoop" % "jacoco4sbt" % "2.1.5")
addSbtPlugin("com.typesafe.sbt" % "sbt-osgi" % "0.7.0")

481
sbt Executable file
View File

@ -0,0 +1,481 @@
#!/usr/bin/env bash
#
# A more capable sbt runner, coincidentally also called sbt.
# Author: Paul Phillips <paulp@typesafe.com>
# todo - make this dynamic
declare -r sbt_release_version="0.13.1"
declare -r sbt_unreleased_version="0.13.2-SNAPSHOT" # -sbt-dev doesn't work at present
declare -r buildProps="project/build.properties"
declare sbt_jar sbt_dir sbt_create sbt_launch_dir
declare scala_version java_home sbt_explicit_version
declare verbose debug quiet noshare batch trace_level log_level
declare sbt_saved_stty
echoerr () { [[ -z "$quiet" ]] && echo "$@" >&2; }
vlog () { [[ -n "$verbose$debug" ]] && echoerr "$@"; }
dlog () { [[ -n "$debug" ]] && echoerr "$@"; }
# we'd like these set before we get around to properly processing arguments
for arg in "$@"; do
case "$arg" in
-q|-quiet) quiet=true ;;
-d|-debug) debug=true ;;
-v|-verbose) verbose=true ;;
*) ;;
esac
done
# spaces are possible, e.g. sbt.version = 0.13.0
build_props_sbt () {
[[ -r "$buildProps" ]] && \
grep '^sbt\.version' "$buildProps" | tr '=' ' ' | awk '{ print $2; }'
}
update_build_props_sbt () {
local ver="$1"
local old="$(build_props_sbt)"
[[ -r "$buildProps" ]] && [[ "$ver" != "$old" ]] && {
perl -pi -e "s/^sbt\.version\b.*\$/sbt.version=${ver}/" "$buildProps"
grep -q '^sbt.version[ =]' "$buildProps" || printf "\nsbt.version=%s\n" "$ver" >> "$buildProps"
echoerr "!!!"
echoerr "!!! Updated file $buildProps setting sbt.version to: $ver"
echoerr "!!! Previous value was: $old"
echoerr "!!!"
}
}
sbt_version () {
if [[ -n "$sbt_explicit_version" ]]; then
echo "$sbt_explicit_version"
else
local v="$(build_props_sbt)"
if [[ -n "$v" ]]; then
echo "$v"
else
echo "$sbt_release_version"
fi
fi
}
# restore stty settings (echo in particular)
onSbtRunnerExit() {
[[ -n "$sbt_saved_stty" ]] || return
dlog ""
dlog "restoring stty: $sbt_saved_stty"
stty "$sbt_saved_stty"
unset sbt_saved_stty
}
# save stty and trap exit, to ensure echo is reenabled if we are interrupted.
trap onSbtRunnerExit EXIT
sbt_saved_stty="$(stty -g 2>/dev/null)"
dlog "Saved stty: $sbt_saved_stty"
# this seems to cover the bases on OSX, and someone will
# have to tell me about the others.
get_script_path () {
local path="$1"
[[ -L "$path" ]] || { echo "$path" ; return; }
local target="$(readlink "$path")"
if [[ "${target:0:1}" == "/" ]]; then
echo "$target"
else
echo "${path%/*}/$target"
fi
}
die() {
echo "Aborting: $@"
exit 1
}
make_url () {
version="$1"
case "$version" in
0.7.*) echo "http://simple-build-tool.googlecode.com/files/sbt-launch-0.7.7.jar" ;;
0.10.* ) echo "$sbt_launch_repo/org.scala-tools.sbt/sbt-launch/$version/sbt-launch.jar" ;;
0.11.[12]) echo "$sbt_launch_repo/org.scala-tools.sbt/sbt-launch/$version/sbt-launch.jar" ;;
*) echo "$sbt_launch_repo/org.scala-sbt/sbt-launch/$version/sbt-launch.jar" ;;
esac
}
init_default_option_file () {
local overriding_var="${!1}"
local default_file="$2"
if [[ ! -r "$default_file" && "$overriding_var" =~ ^@(.*)$ ]]; then
local envvar_file="${BASH_REMATCH[1]}"
if [[ -r "$envvar_file" ]]; then
default_file="$envvar_file"
fi
fi
echo "$default_file"
}
declare -r cms_opts="-XX:+CMSClassUnloadingEnabled -XX:+UseConcMarkSweepGC"
declare -r jit_opts="-XX:ReservedCodeCacheSize=256m -XX:+TieredCompilation"
declare -r default_jvm_opts="-Dfile.encoding=UTF8 -XX:MaxPermSize=384m -Xms512m -Xmx1536m -Xss2m $jit_opts $cms_opts"
declare -r noshare_opts="-Dsbt.global.base=project/.sbtboot -Dsbt.boot.directory=project/.boot -Dsbt.ivy.home=project/.ivy"
declare -r latest_28="2.8.2"
declare -r latest_29="2.9.3"
declare -r latest_210="2.10.3"
declare -r latest_211="2.11.0-M5"
declare -r script_path="$(get_script_path "$BASH_SOURCE")"
declare -r script_name="${script_path##*/}"
# some non-read-onlies set with defaults
declare java_cmd="java"
declare sbt_opts_file="$(init_default_option_file SBT_OPTS .sbtopts)"
declare jvm_opts_file="$(init_default_option_file JVM_OPTS .jvmopts)"
declare sbt_launch_repo="http://typesafe.artifactoryonline.com/typesafe/ivy-releases"
# pull -J and -D options to give to java.
declare -a residual_args
declare -a java_args
declare -a scalac_args
declare -a sbt_commands
# args to jvm/sbt via files or environment variables
declare -a extra_jvm_opts extra_sbt_opts
# if set, use JAVA_HOME over java found in path
[[ -e "$JAVA_HOME/bin/java" ]] && java_cmd="$JAVA_HOME/bin/java"
# directory to store sbt launchers
declare sbt_launch_dir="$HOME/.sbt/launchers"
[[ -d "$sbt_launch_dir" ]] || mkdir -p "$sbt_launch_dir"
[[ -w "$sbt_launch_dir" ]] || sbt_launch_dir="$(mktemp -d -t sbt_extras_launchers.XXXXXX)"
build_props_scala () {
if [[ -r "$buildProps" ]]; then
versionLine="$(grep '^build.scala.versions' "$buildProps")"
versionString="${versionLine##build.scala.versions=}"
echo "${versionString%% .*}"
fi
}
execRunner () {
# print the arguments one to a line, quoting any containing spaces
[[ "$verbose" || "$debug" ]] && echo "# Executing command line:" && {
for arg; do
if [[ -n "$arg" ]]; then
if printf "%s\n" "$arg" | grep -q ' '; then
printf "\"%s\"\n" "$arg"
else
printf "%s\n" "$arg"
fi
fi
done
echo ""
}
if [[ -n "$batch" ]]; then
exec </dev/null
fi
exec "$@"
}
jar_url () {
make_url "$1"
}
jar_file () {
echo "$sbt_launch_dir/$1/sbt-launch.jar"
}
download_url () {
local url="$1"
local jar="$2"
echo "Downloading sbt launcher for $(sbt_version):"
echo " From $url"
echo " To $jar"
mkdir -p "${jar%/*}" && {
if which curl >/dev/null; then
curl --fail --silent "$url" --output "$jar"
elif which wget >/dev/null; then
wget --quiet -O "$jar" "$url"
fi
} && [[ -r "$jar" ]]
}
acquire_sbt_jar () {
for_sbt_version="$(sbt_version)"
sbt_url="$(jar_url "$for_sbt_version")"
sbt_jar="$(jar_file "$for_sbt_version")"
[[ -r "$sbt_jar" ]] || download_url "$sbt_url" "$sbt_jar"
}
usage () {
cat <<EOM
Usage: $script_name [options]
-h | -help print this message
-v | -verbose this runner is chattier
-d | -debug set sbt log level to Debug
-q | -quiet set sbt log level to Error
-trace <level> display stack traces with a max of <level> frames (default: -1, traces suppressed)
-no-colors disable ANSI color codes
-sbt-create start sbt even if current directory contains no sbt project
-sbt-dir <path> path to global settings/plugins directory (default: ~/.sbt/<version>)
-sbt-boot <path> path to shared boot directory (default: ~/.sbt/boot in 0.11+)
-ivy <path> path to local Ivy repository (default: ~/.ivy2)
-no-share use all local caches; no sharing
-offline put sbt in offline mode
-jvm-debug <port> Turn on JVM debugging, open at the given port.
-batch Disable interactive mode
-prompt <expr> Set the sbt prompt; in expr, 's' is the State and 'e' is Extracted
# sbt version (default: from $buildProps if present, else latest release)
!!! The only way to accomplish this pre-0.12.0 if there is a build.properties file which
!!! contains an sbt.version property is to update the file on disk. That's what this does.
-sbt-version <version> use the specified version of sbt (default: $sbt_release_version)
-sbt-jar <path> use the specified jar as the sbt launcher
-sbt-launch-dir <path> directory to hold sbt launchers (default: $sbt_launch_dir)
-sbt-launch-repo <url> repo url for downloading sbt launcher jar (default: $sbt_launch_repo)
# scala version (default: as chosen by sbt)
-28 use $latest_28
-29 use $latest_29
-210 use $latest_210
-211 use $latest_211
-scala-home <path> use the scala build at the specified directory
-scala-version <version> use the specified version of scala
-binary-version <version> use the specified scala version when searching for dependencies
# java version (default: java from PATH, currently $(java -version 2>&1 | grep version))
-java-home <path> alternate JAVA_HOME
# passing options to the jvm - note it does NOT use JAVA_OPTS due to pollution
# The default set is used if JVM_OPTS is unset and no -jvm-opts file is found
<default> $default_jvm_opts
JVM_OPTS environment variable holding either the jvm args directly, or
the reference to a file containing jvm args if given path is prepended by '@' (e.g. '@/etc/jvmopts')
Note: "@"-file is overridden by local '.jvmopts' or '-jvm-opts' argument.
-jvm-opts <path> file containing jvm args (if not given, .jvmopts in project root is used if present)
-Dkey=val pass -Dkey=val directly to the jvm
-J-X pass option -X directly to the jvm (-J is stripped)
# passing options to sbt, OR to this runner
SBT_OPTS environment variable holding either the sbt args directly, or
the reference to a file containing sbt args if given path is prepended by '@' (e.g. '@/etc/sbtopts')
Note: "@"-file is overridden by local '.sbtopts' or '-sbt-opts' argument.
-sbt-opts <path> file containing sbt args (if not given, .sbtopts in project root is used if present)
-S-X add -X to sbt's scalacOptions (-S is stripped)
EOM
}
addJava () {
dlog "[addJava] arg = '$1'"
java_args=( "${java_args[@]}" "$1" )
}
addSbt () {
dlog "[addSbt] arg = '$1'"
sbt_commands=( "${sbt_commands[@]}" "$1" )
}
addScalac () {
dlog "[addScalac] arg = '$1'"
scalac_args=( "${scalac_args[@]}" "$1" )
}
addResidual () {
dlog "[residual] arg = '$1'"
residual_args=( "${residual_args[@]}" "$1" )
}
addResolver () {
addSbt "set resolvers += $1"
}
addDebugger () {
addJava "-Xdebug"
addJava "-Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=$1"
}
setScalaVersion () {
[[ "$1" == *"-SNAPSHOT" ]] && addResolver 'Resolver.sonatypeRepo("snapshots")'
addSbt "++ $1"
}
process_args ()
{
require_arg () {
local type="$1"
local opt="$2"
local arg="$3"
if [[ -z "$arg" ]] || [[ "${arg:0:1}" == "-" ]]; then
die "$opt requires <$type> argument"
fi
}
while [[ $# -gt 0 ]]; do
case "$1" in
-h|-help) usage; exit 1 ;;
-v|-verbose) verbose=true && log_level=Info && shift ;;
-d|-debug) debug=true && log_level=Debug && shift ;;
-q|-quiet) quiet=true && log_level=Error && shift ;;
-trace) require_arg integer "$1" "$2" && trace_level="$2" && shift 2 ;;
-ivy) require_arg path "$1" "$2" && addJava "-Dsbt.ivy.home=$2" && shift 2 ;;
-no-colors) addJava "-Dsbt.log.noformat=true" && shift ;;
-no-share) noshare=true && shift ;;
-sbt-boot) require_arg path "$1" "$2" && addJava "-Dsbt.boot.directory=$2" && shift 2 ;;
-sbt-dir) require_arg path "$1" "$2" && sbt_dir="$2" && shift 2 ;;
-debug-inc) addJava "-Dxsbt.inc.debug=true" && shift ;;
-offline) addSbt "set offline := true" && shift ;;
-jvm-debug) require_arg port "$1" "$2" && addDebugger "$2" && shift 2 ;;
-batch) batch=true && shift ;;
-prompt) require_arg "expr" "$1" "$2" && addSbt "set shellPrompt in ThisBuild := (s => { val e = Project.extract(s) ; $2 })" && shift 2 ;;
-sbt-create) sbt_create=true && shift ;;
-sbt-jar) require_arg path "$1" "$2" && sbt_jar="$2" && shift 2 ;;
-sbt-version) require_arg version "$1" "$2" && sbt_explicit_version="$2" && shift 2 ;;
-sbt-dev) sbt_explicit_version="$sbt_unreleased_version" && shift ;;
-sbt-launch-dir) require_arg path "$1" "$2" && sbt_launch_dir="$2" && shift 2 ;;
-sbt-launch-repo) require_arg path "$1" "$2" && sbt_launch_repo="$2" && shift 2 ;;
-scala-version) require_arg version "$1" "$2" && setScalaVersion "$2" && shift 2 ;;
-binary-version) require_arg version "$1" "$2" && addSbt "set scalaBinaryVersion in ThisBuild := \"$2\"" && shift 2 ;;
-scala-home) require_arg path "$1" "$2" && addSbt "set every scalaHome := Some(file(\"$2\"))" && shift 2 ;;
-java-home) require_arg path "$1" "$2" && java_cmd="$2/bin/java" && shift 2 ;;
-sbt-opts) require_arg path "$1" "$2" && sbt_opts_file="$2" && shift 2 ;;
-jvm-opts) require_arg path "$1" "$2" && jvm_opts_file="$2" && shift 2 ;;
-D*) addJava "$1" && shift ;;
-J*) addJava "${1:2}" && shift ;;
-S*) addScalac "${1:2}" && shift ;;
-28) setScalaVersion "$latest_28" && shift ;;
-29) setScalaVersion "$latest_29" && shift ;;
-210) setScalaVersion "$latest_210" && shift ;;
-211) setScalaVersion "$latest_211" && shift ;;
*) addResidual "$1" && shift ;;
esac
done
}
# process the direct command line arguments
process_args "$@"
# skip #-styled comments and blank lines
readConfigFile() {
while read line; do
[[ $line =~ ^# ]] || [[ -z $line ]] || echo "$line"
done < "$1"
}
# if there are file/environment sbt_opts, process again so we
# can supply args to this runner
if [[ -r "$sbt_opts_file" ]]; then
vlog "Using sbt options defined in file $sbt_opts_file"
while read opt; do extra_sbt_opts+=("$opt"); done < <(readConfigFile "$sbt_opts_file")
elif [[ -n "$SBT_OPTS" && ! ("$SBT_OPTS" =~ ^@.*) ]]; then
vlog "Using sbt options defined in variable \$SBT_OPTS"
extra_sbt_opts=( $SBT_OPTS )
else
vlog "No extra sbt options have been defined"
fi
[[ -n "$extra_sbt_opts" ]] && process_args "${extra_sbt_opts[@]}"
# reset "$@" to the residual args
set -- "${residual_args[@]}"
argumentCount=$#
# only exists in 0.12+
setTraceLevel() {
case "$(sbt_version)" in
"0.7."* | "0.10."* | "0.11."* )
echoerr "Cannot set trace level in sbt version $(sbt_version)"
;;
*)
addSbt "set every traceLevel := $trace_level"
;;
esac
}
# set scalacOptions if we were given any -S opts
[[ ${#scalac_args[@]} -eq 0 ]] || addSbt "set scalacOptions in ThisBuild += \"${scalac_args[@]}\""
# Update build.properties on disk to set explicit version - sbt gives us no choice
[[ -n "$sbt_explicit_version" ]] && update_build_props_sbt "$sbt_explicit_version"
vlog "Detected sbt version $(sbt_version)"
[[ -n "$scala_version" ]] && echoerr "Overriding scala version to $scala_version"
# no args - alert them there's stuff in here
(( argumentCount > 0 )) || {
vlog "Starting $script_name: invoke with -help for other options"
residual_args=( shell )
}
# verify this is an sbt dir or -create was given
[[ -r ./build.sbt || -d ./project || -n "$sbt_create" ]] || {
cat <<EOM
$(pwd) doesn't appear to be an sbt project.
If you want to start sbt anyway, run:
$0 -sbt-create
EOM
exit 1
}
# pick up completion if present; todo
[[ -r .sbt_completion.sh ]] && source .sbt_completion.sh
# no jar? download it.
[[ -r "$sbt_jar" ]] || acquire_sbt_jar || {
# still no jar? uh-oh.
echo "Download failed. Obtain the jar manually and place it at $sbt_jar"
exit 1
}
if [[ -n "$noshare" ]]; then
for opt in ${noshare_opts}; do
addJava "$opt"
done
else
case "$(sbt_version)" in
"0.7."* | "0.10."* | "0.11."* | "0.12."* )
[[ -n "$sbt_dir" ]] || {
sbt_dir="$HOME/.sbt/$(sbt_version)"
vlog "Using $sbt_dir as sbt dir, -sbt-dir to override."
}
;;
esac
if [[ -n "$sbt_dir" ]]; then
addJava "-Dsbt.global.base=$sbt_dir"
fi
fi
if [[ -r "$jvm_opts_file" ]]; then
vlog "Using jvm options defined in file $jvm_opts_file"
while read opt; do extra_jvm_opts+=("$opt"); done < <(readConfigFile "$jvm_opts_file")
elif [[ -n "$JVM_OPTS" && ! ("$JVM_OPTS" =~ ^@.*) ]]; then
vlog "Using jvm options defined in \$JVM_OPTS variable"
extra_jvm_opts=( $JVM_OPTS )
else
vlog "Using default jvm options"
extra_jvm_opts=( $default_jvm_opts )
fi
# traceLevel is 0.12+
[[ -n "$trace_level" ]] && setTraceLevel
if [[ -n "$log_level" ]] && [[ "$log_level" != Info ]]; then
sbt_commands=("set logLevel in Global := Level.$log_level" "${sbt_commands[@]}")
fi
# run sbt
execRunner "$java_cmd" \
"${extra_jvm_opts[@]}" \
"${java_args[@]}" \
-jar "$sbt_jar" \
"${sbt_commands[@]}" \
"${residual_args[@]}"

View File

@ -69,7 +69,7 @@ public class OSInfo
// PowerPC mappings
archMapping.put(PPC, PPC);
archMapping.put("pwoer", PPC);
archMapping.put("power", PPC);
archMapping.put("powerpc", PPC);
archMapping.put("power_pc", PPC);
archMapping.put("power_rs", PPC);

View File

@ -37,7 +37,7 @@ import java.util.Properties;
* Note: if the native libraries cannot be loaded, an ExceptionInInitializerError
* will be thrown at first use of this class.
*
* @author leo
* @author Taro L. Saito
*
*/
public class Snappy

View File

@ -48,8 +48,14 @@ public class SnappyBundleActivator implements BundleActivator
* that the library is available on the path based on this {@link Bundle}'s {@link Manifest}.
*/
public void start(BundleContext context) throws Exception
{
System.loadLibrary(System.mapLibraryName(LIBRARY_NAME));
{
String library = System.mapLibraryName(LIBRARY_NAME);
if (library.toLowerCase().endsWith(".dylib"))
{
// some MacOS JDK7+ vendors map to dylib instead of jnilib
library = library.replace(".dylib", ".jnilib");
}
System.loadLibrary(library);
SnappyLoader.setApi(new SnappyNative());
}

View File

@ -4,8 +4,11 @@
package org.xerial.snappy;
import java.io.IOException;
import java.lang.reflect.Method;
import java.nio.ByteBuffer;
import java.nio.channels.ReadableByteChannel;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
* Constants and utilities for implementing x-snappy-framed.
@ -21,6 +24,33 @@ final class SnappyFramed {
public static final int STREAM_IDENTIFIER_FLAG = 0xff;
private static final int MASK_DELTA = 0xa282ead8;
/**
* Sun specific mechanisms to clean up resources associated with direct byte buffers.
*/
@SuppressWarnings("unchecked")
private static final Class<? extends ByteBuffer> SUN_DIRECT_BUFFER = (Class<? extends ByteBuffer>) lookupClassQuietly("sun.nio.ch.DirectBuffer");
private static final Method SUN_BUFFER_CLEANER;
private static final Method SUN_CLEANER_CLEAN;
static
{
Method bufferCleaner = null;
Method cleanerClean = null;
try {
//operate under the assumption that if the sun direct buffer class exists,
//all of the sun classes exist
if (SUN_DIRECT_BUFFER != null) {
bufferCleaner = SUN_DIRECT_BUFFER.getMethod("cleaner", (Class[])null);
Class<?> cleanClazz = lookupClassQuietly("sun.misc.Cleaner");
cleanerClean = cleanClazz.getMethod("clean", (Class[])null);
}
} catch(Throwable t) {
Logger.getLogger(SnappyFramed.class.getName()).log(Level.FINE, "Exception occurred attempting to lookup Sun specific DirectByteBuffer cleaner classes.", t);
}
SUN_BUFFER_CLEANER = bufferCleaner;
SUN_CLEANER_CLEAN = cleanerClean;
}
/**
* The header consists of the stream identifier flag, 3 bytes indicating a
@ -125,4 +155,32 @@ final class SnappyFramed {
buffer.clear();
return skip - toSkip;
}
private static Class<?> lookupClassQuietly(String name) {
try {
return SnappyFramed.class.getClassLoader().loadClass(name);
} catch (Throwable t) {
Logger.getLogger(SnappyFramed.class.getName()).log(Level.FINE, "Did not find requested class: " + name, t);
}
return null;
}
/**
* Provides jvm implementation specific operation to aggressively release resources associated with <i>buffer</i>.
* @param buffer The {@code ByteBuffer} to release. Must not be {@code null}. Must be {@link ByteBuffer#isDirect() direct}.
*/
static void releaseDirectByteBuffer(ByteBuffer buffer)
{
assert buffer != null && buffer.isDirect();
if (SUN_DIRECT_BUFFER != null && SUN_DIRECT_BUFFER.isAssignableFrom(buffer.getClass())) {
try {
Object cleaner = SUN_BUFFER_CLEANER.invoke(buffer, (Object[]) null);
SUN_CLEANER_CLEAN.invoke(cleaner, (Object[]) null);
} catch (Throwable t) {
Logger.getLogger(SnappyFramed.class.getName()).log(Level.FINE, "Exception occurred attempting to clean up Sun specific DirectByteBuffer.", t);
}
}
}
}

View File

@ -4,16 +4,23 @@
package org.xerial.snappy;
import static java.lang.Math.min;
import static org.xerial.snappy.SnappyFramed.*;
import static org.xerial.snappy.SnappyFramedOutputStream.*;
import static org.xerial.snappy.SnappyFramed.COMPRESSED_DATA_FLAG;
import static org.xerial.snappy.SnappyFramed.HEADER_BYTES;
import static org.xerial.snappy.SnappyFramed.STREAM_IDENTIFIER_FLAG;
import static org.xerial.snappy.SnappyFramed.UNCOMPRESSED_DATA_FLAG;
import static org.xerial.snappy.SnappyFramed.readBytes;
import static org.xerial.snappy.SnappyFramed.releaseDirectByteBuffer;
import static org.xerial.snappy.SnappyFramedOutputStream.MAX_BLOCK_SIZE;
import java.io.EOFException;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.nio.ByteBuffer;
import java.nio.channels.Channels;
import java.nio.channels.ClosedChannelException;
import java.nio.channels.ReadableByteChannel;
import java.nio.channels.WritableByteChannel;
import java.util.Arrays;
/**
@ -48,12 +55,12 @@ public final class SnappyFramedInputStream extends InputStream implements
private boolean closed;
/**
* Indicates if we have reached the EOF on {@link #in}.
* Indicates if we have reached the EOF on {@link #input}.
*/
private boolean eof;
/**
* The position in {@link buffer} to read to.
* The position in {@link #input} buffer to read to.
*/
private int valid;
@ -130,9 +137,7 @@ public final class SnappyFramedInputStream extends InputStream implements
final byte[] actualHeader = new byte[expectedHeader.length];
final ByteBuffer actualBuffer = ByteBuffer.wrap(actualHeader);
// assume that if the input cannot read 4 bytes that something is
// wrong.
final int read = in.read(actualBuffer);
final int read = SnappyFramed.readBytes(in, actualBuffer);
if (read < expectedHeader.length) {
throw new EOFException(
"encountered EOF while reading stream header");
@ -147,6 +152,14 @@ public final class SnappyFramedInputStream extends InputStream implements
*/
private void allocateBuffersBasedOnSize(int size) {
if (input != null) {
releaseDirectByteBuffer(input);
}
if (uncompressedDirect != null) {
releaseDirectByteBuffer(uncompressedDirect);
}
input = ByteBuffer.allocateDirect(size);
final int maxCompressedLength = Snappy.maxCompressedLength(size);
uncompressedDirect = ByteBuffer.allocateDirect(maxCompressedLength);
@ -236,6 +249,91 @@ public final class SnappyFramedInputStream extends InputStream implements
return size;
}
/**
* Transfers the entire content of this {@link InputStream} to <i>os</i>.
* This potentially limits the amount of buffering required to decompress
* content.
* <p>
* Unlike {@link #read(byte[], int, int)}, this method does not need to be
* called multiple times. A single call will transfer all available content.
* Any calls after the source has been exhausted will result in a return
* value of {@code 0}.
* </p>
*
* @param os
* The destination to write decompressed content to.
* @return The number of bytes transferred.
* @throws IOException
* @since 1.1.1
*/
public long transferTo(OutputStream os) throws IOException {
if (os == null) {
throw new IllegalArgumentException("os is null");
}
if (closed) {
throw new ClosedChannelException();
}
long totTransfered = 0;
while (ensureBuffer()) {
final int available = available();
os.write(buffer, position, available);
position += available;
totTransfered += available;
}
return totTransfered;
}
/**
* Transfers the entire content of this {@link ReadableByteChannel} to
* <i>wbc</i>. This potentially limits the amount of buffering required to
* decompress content.
*
* <p>
* Unlike {@link #read(ByteBuffer)}, this method does not need to be called
* multiple times. A single call will transfer all available content. Any
* calls after the source has been exhausted will result in a return value
* of {@code 0}.
* </p>
*
* @param wbc
* The destination to write decompressed content to.
* @return The number of bytes transferred.
* @throws IOException
* @since 1.1.1
*/
public long transferTo(WritableByteChannel wbc) throws IOException {
if (wbc == null) {
throw new IllegalArgumentException("wbc is null");
}
if (closed) {
throw new ClosedChannelException();
}
final ByteBuffer bb = ByteBuffer.wrap(buffer);
long totTransfered = 0;
while (ensureBuffer()) {
bb.clear();
bb.position(position);
bb.limit(position + available());
wbc.write(bb);
final int written = bb.position() - position;
position += written;
totTransfered += written;
}
return totTransfered;
}
@Override
public void close() throws IOException {
try {
@ -244,6 +342,14 @@ public final class SnappyFramedInputStream extends InputStream implements
if (!closed) {
closed = true;
}
if (input != null) {
releaseDirectByteBuffer(input);
}
if (uncompressedDirect != null) {
releaseDirectByteBuffer(uncompressedDirect);
}
}
}

View File

@ -7,11 +7,16 @@ import static org.xerial.snappy.SnappyFramed.COMPRESSED_DATA_FLAG;
import static org.xerial.snappy.SnappyFramed.HEADER_BYTES;
import static org.xerial.snappy.SnappyFramed.UNCOMPRESSED_DATA_FLAG;
import static org.xerial.snappy.SnappyFramed.maskedCrc32c;
import static org.xerial.snappy.SnappyFramed.releaseDirectByteBuffer;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.channels.Channels;
import java.nio.channels.ClosedChannelException;
import java.nio.channels.ReadableByteChannel;
import java.nio.channels.WritableByteChannel;
/**
@ -49,12 +54,14 @@ public final class SnappyFramedOutputStream extends OutputStream implements
*/
public static final double DEFAULT_MIN_COMPRESSION_RATIO = 0.85d;
// private final int blockSize;
private final ByteBuffer headerBuffer = ByteBuffer.allocate(8).order(
ByteOrder.LITTLE_ENDIAN);
private final ByteBuffer buffer;
private final byte[] outputBuffer;
private final ByteBuffer directInputBuffer;
private final ByteBuffer outputBuffer;
private final double minCompressionRatio;
private final OutputStream out;
private final WritableByteChannel out;
// private int position;
private boolean closed;
@ -88,6 +95,41 @@ public final class SnappyFramedOutputStream extends OutputStream implements
*/
public SnappyFramedOutputStream(OutputStream out, int blockSize,
double minCompressionRatio) throws IOException {
this(Channels.newChannel(out), blockSize, minCompressionRatio);
}
/**
* Creates a new {@link SnappyFramedOutputStream} using the
* {@link #DEFAULT_BLOCK_SIZE} and {@link #DEFAULT_MIN_COMPRESSION_RATIO}.
*
* @param out
* The underlying {@link WritableByteChannel} to write to. Must
* not be {@code null}.
* @since 1.1.1
* @throws IOException
*/
public SnappyFramedOutputStream(WritableByteChannel out) throws IOException {
this(out, DEFAULT_BLOCK_SIZE, DEFAULT_MIN_COMPRESSION_RATIO);
}
/**
* Creates a new {@link SnappyFramedOutputStream} instance.
*
* @param out
* The underlying {@link WritableByteChannel} to write to. Must
* not be {@code null}.
* @param blockSize
* The block size (of raw data) to compress before writing frames
* to <i>out</i>. Must be in (0, 65536].
* @param minCompressionRatio
* Defines the minimum compression ratio (
* {@code compressedLength / rawLength}) that must be achieved to
* write the compressed data. This must be in (0, 1.0].
* @since 1.1.1
* @throws IOException
*/
public SnappyFramedOutputStream(WritableByteChannel out, int blockSize,
double minCompressionRatio) throws IOException {
if (out == null) {
throw new NullPointerException();
}
@ -105,7 +147,9 @@ public final class SnappyFramedOutputStream extends OutputStream implements
this.out = out;
this.minCompressionRatio = minCompressionRatio;
buffer = ByteBuffer.allocate(blockSize);
outputBuffer = new byte[Snappy.maxCompressedLength(blockSize)];
directInputBuffer = ByteBuffer.allocateDirect(blockSize);
outputBuffer = ByteBuffer.allocateDirect(Snappy
.maxCompressedLength(blockSize));
writeHeader(out);
}
@ -118,8 +162,8 @@ public final class SnappyFramedOutputStream extends OutputStream implements
* The underlying {@link OutputStream}.
* @throws IOException
*/
private void writeHeader(OutputStream out) throws IOException {
out.write(HEADER_BYTES);
private void writeHeader(WritableByteChannel out) throws IOException {
out.write(ByteBuffer.wrap(HEADER_BYTES));
}
/**
@ -147,7 +191,24 @@ public final class SnappyFramedOutputStream extends OutputStream implements
throw new IOException("Stream is closed");
}
write(ByteBuffer.wrap(input, offset, length));
if (input == null) {
throw new NullPointerException();
} else if ((offset < 0) || (offset > input.length) || (length < 0)
|| ((offset + length) > input.length)
|| ((offset + length) < 0)) {
throw new IndexOutOfBoundsException();
}
while (length > 0) {
if (buffer.remaining() <= 0) {
flushBuffer();
}
final int toPut = Math.min(length, buffer.remaining());
buffer.put(input, offset, toPut);
offset += toPut;
length -= toPut;
}
}
/**
@ -190,13 +251,93 @@ public final class SnappyFramedOutputStream extends OutputStream implements
return srcLength;
}
/**
* Transfers all the content from <i>is</i> to this {@link OutputStream}.
* This potentially limits the amount of buffering required to compress
* content.
*
* @param is
* The source of data to compress.
* @return The number of bytes read from <i>is</i>.
* @throws IOException
* @since 1.1.1
*/
public long transferFrom(InputStream is) throws IOException {
if (closed) {
throw new ClosedChannelException();
}
if (is == null) {
throw new NullPointerException();
}
if (buffer.remaining() == 0) {
flushBuffer();
}
assert buffer.hasArray();
final byte[] bytes = buffer.array();
final int arrayOffset = buffer.arrayOffset();
long totTransfered = 0;
int read;
while ((read = is.read(bytes, arrayOffset + buffer.position(),
buffer.remaining())) != -1) {
buffer.position(buffer.position() + read);
if (buffer.remaining() == 0) {
flushBuffer();
}
totTransfered += read;
}
return totTransfered;
}
/**
* Transfers all the content from <i>rbc</i> to this
* {@link WritableByteChannel}. This potentially limits the amount of
* buffering required to compress content.
*
* @param rbc
* The source of data to compress.
* @return The number of bytes read from <i>rbc</i>.
* @throws IOException
* @since 1.1.1
*/
public long transferFrom(ReadableByteChannel rbc) throws IOException {
if (closed) {
throw new ClosedChannelException();
}
if (rbc == null) {
throw new NullPointerException();
}
if (buffer.remaining() == 0) {
flushBuffer();
}
long totTransfered = 0;
int read;
while ((read = rbc.read(buffer)) != -1) {
if (buffer.remaining() == 0) {
flushBuffer();
}
totTransfered += read;
}
return totTransfered;
}
@Override
public final void flush() throws IOException {
if (closed) {
throw new IOException("Stream is closed");
}
flushBuffer();
out.flush();
}
@Override
@ -209,6 +350,9 @@ public final class SnappyFramedOutputStream extends OutputStream implements
out.close();
} finally {
closed = true;
releaseDirectByteBuffer(directInputBuffer);
releaseDirectByteBuffer(outputBuffer);
}
}
@ -227,17 +371,13 @@ public final class SnappyFramedOutputStream extends OutputStream implements
}
/**
* {@link #calculateCRC32C(byte[], int, int) Calculates} the crc, compresses
* {@link SnappyFramed#maskedCrc32c(byte[], int, int)} the crc, compresses
* the data, determines if the compression ratio is acceptable and calls
* {@link #writeBlock(OutputStream, byte[], int, int, boolean, int)} to
* {@link #writeBlock(java.nio.channels.WritableByteChannel, java.nio.ByteBuffer, boolean, int)} to
* actually write the frame.
*
* @param input
* The byte[] containing the raw data to be compressed.
* @param offset
* The offset into <i>input</i> where the data starts.
* @param length
* The amount of data in <i>input</i>.
* @param buffer
* @throws IOException
*/
private void writeCompressed(ByteBuffer buffer) throws IOException {
@ -246,33 +386,28 @@ public final class SnappyFramedOutputStream extends OutputStream implements
final int length = buffer.remaining();
// crc is based on the user supplied input data
final int crc32c = calculateCRC32C(input, 0, length);
final int crc32c = maskedCrc32c(input, 0, length);
final int compressedLength = Snappy.compress(input, 0, length,
outputBuffer, 0);
directInputBuffer.clear();
directInputBuffer.put(buffer);
directInputBuffer.flip();
// only use the compressed data if copmression ratio is <= the
outputBuffer.clear();
Snappy.compress(directInputBuffer, outputBuffer);
final int compressedLength = outputBuffer.remaining();
// only use the compressed data if compression ratio is <= the
// minCompressonRatio
if (((double) compressedLength / (double) length) <= minCompressionRatio) {
writeBlock(out, outputBuffer, 0, compressedLength, true, crc32c);
writeBlock(out, outputBuffer, true, crc32c);
} else {
// otherwise use the uncomprssed data.
writeBlock(out, input, 0, length, false, crc32c);
// otherwise use the uncompressed data.
buffer.flip();
writeBlock(out, buffer, false, crc32c);
}
}
/**
* Calculates a masked CRC32C checksum over the data.
*
* @param data
* @param offset
* @param length
* @return The CRC32 checksum.
*/
private int calculateCRC32C(byte[] data, int offset, int length) {
return maskedCrc32c(data, offset, length);
}
/**
* Write a frame (block) to <i>out</i>.
*
@ -280,10 +415,6 @@ public final class SnappyFramedOutputStream extends OutputStream implements
* The {@link OutputStream} to write to.
* @param data
* The data to write.
* @param offset
* The offset in <i>data</i> to start at.
* @param length
* The length of <i>data</i> to use.
* @param compressed
* Indicates if <i>data</i> is the compressed or raw content.
* This is based on whether the compression ratio desired is
@ -292,26 +423,30 @@ public final class SnappyFramedOutputStream extends OutputStream implements
* The calculated checksum.
* @throws IOException
*/
private void writeBlock(final OutputStream out, byte[] data, int offset,
int length, boolean compressed, int crc32c) throws IOException {
out.write(compressed ? COMPRESSED_DATA_FLAG : UNCOMPRESSED_DATA_FLAG);
private void writeBlock(final WritableByteChannel out, ByteBuffer data,
boolean compressed, int crc32c) throws IOException {
headerBuffer.clear();
headerBuffer.put((byte) (compressed ? COMPRESSED_DATA_FLAG
: UNCOMPRESSED_DATA_FLAG));
// the length written out to the header is both the checksum and the
// frame
final int headerLength = length + 4;
final int headerLength = data.remaining() + 4;
// write length
out.write(headerLength);
out.write(headerLength >>> 8);
out.write(headerLength >>> 16);
headerBuffer.put((byte) headerLength);
headerBuffer.put((byte) (headerLength >>> 8));
headerBuffer.put((byte) (headerLength >>> 16));
// write crc32c of user input data
out.write(crc32c);
out.write(crc32c >>> 8);
out.write(crc32c >>> 16);
out.write(crc32c >>> 24);
headerBuffer.putInt(crc32c);
// write data
out.write(data, offset, length);
headerBuffer.flip();
// write the header
out.write(headerBuffer);
// write the raw data
out.write(data);
}
}

View File

@ -228,18 +228,9 @@ public class SnappyLoader
}
// Set executable (x) flag to enable Java to load the native library
if (!System.getProperty("os.name").contains("Windows")) {
try {
Runtime.getRuntime().exec(new String[] { "chmod", "755", extractedLibFile.getAbsolutePath() })
.waitFor();
// Use following methods added since Java6 (If discarding Java5 is acceptable)
//extractedLibFile.setReadable(true);
//extractedLibFile.setWritable(true, true);
//extractedLibFile.setExecutable(true);
}
catch (Throwable e) {}
}
extractedLibFile.setReadable(true);
extractedLibFile.setWritable(true, true);
extractedLibFile.setExecutable(true);
// Check whether the contents are properly copied from the resource folder

View File

@ -1,2 +1,2 @@
VERSION=1.1.0
VERSION=1.1.1

View File

@ -1,59 +0,0 @@
/*--------------------------------------------------------------------------
* Copyright 2011 Taro L. Saito
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*--------------------------------------------------------------------------*/
//--------------------------------------
// XerialJ
//
// SnappyNativeLoader.java
// Since: 2011/07/04 12:10:28
//
// $URL$
// $Author$
//--------------------------------------
package org.xerial.snappy;
import java.util.HashMap;
public class SnappyNativeLoader
{
private static HashMap<String, Boolean> loadedLibFiles = new HashMap<String, Boolean>();
private static HashMap<String, Boolean> loadedLib = new HashMap<String, Boolean>();
public static synchronized void load(String lib) {
if (loadedLibFiles.containsKey(lib) && loadedLibFiles.get(lib) == true)
return;
try {
System.load(lib);
loadedLibFiles.put(lib, true);
}
catch (Exception e) {
e.printStackTrace();
}
}
public static synchronized void loadLibrary(String libname) {
if (loadedLib.containsKey(libname) && loadedLib.get(libname) == true)
return;
try {
System.loadLibrary(libname);
loadedLib.put(libname, true);
}
catch (Exception e) {
e.printStackTrace();
}
}
}

View File

@ -3,8 +3,13 @@
*/
package org.xerial.snappy;
import static org.xerial.snappy.SnappyFramed.*;
import static org.junit.Assert.*;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
import static org.xerial.snappy.SnappyFramed.COMPRESSED_DATA_FLAG;
import static org.xerial.snappy.SnappyFramed.HEADER_BYTES;
import static org.xerial.snappy.SnappyFramed.UNCOMPRESSED_DATA_FLAG;
import static org.xerial.snappy.SnappyFramed.maskedCrc32c;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
@ -12,6 +17,8 @@ import java.io.EOFException;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.nio.channels.Channels;
import java.nio.channels.WritableByteChannel;
import java.util.Arrays;
import org.junit.Test;
@ -159,6 +166,72 @@ public class SnappyFramedStreamTest {
new byte[] { 'a' });
}
@Test
public void testTransferFrom_InputStream() throws IOException {
final byte[] random = getRandom(0.5, 100000);
final ByteArrayOutputStream baos = new ByteArrayOutputStream(
random.length);
final SnappyFramedOutputStream sfos = new SnappyFramedOutputStream(baos);
sfos.transferFrom(new ByteArrayInputStream(random));
sfos.close();
final byte[] uncompressed = uncompress(baos.toByteArray());
assertArrayEquals(random, uncompressed);
}
@Test
public void testTransferFrom_ReadableByteChannel() throws IOException {
final byte[] random = getRandom(0.5, 100000);
final ByteArrayOutputStream baos = new ByteArrayOutputStream(
random.length);
final SnappyFramedOutputStream sfos = new SnappyFramedOutputStream(baos);
sfos.transferFrom(Channels.newChannel(new ByteArrayInputStream(random)));
sfos.close();
final byte[] uncompressed = uncompress(baos.toByteArray());
assertArrayEquals(random, uncompressed);
}
@Test
public void testTransferTo_OutputStream() throws IOException {
final byte[] random = getRandom(0.5, 100000);
final byte[] compressed = compress(random);
final SnappyFramedInputStream sfis = new SnappyFramedInputStream(
new ByteArrayInputStream(compressed));
final ByteArrayOutputStream baos = new ByteArrayOutputStream(
random.length);
sfis.transferTo(baos);
assertArrayEquals(random, baos.toByteArray());
}
@Test
public void testTransferTo_WritableByteChannel() throws IOException {
final byte[] random = getRandom(0.5, 100000);
final byte[] compressed = compress(random);
final SnappyFramedInputStream sfis = new SnappyFramedInputStream(
new ByteArrayInputStream(compressed));
final ByteArrayOutputStream baos = new ByteArrayOutputStream(
random.length);
final WritableByteChannel wbc = Channels.newChannel(baos);
sfis.transferTo(wbc);
wbc.close();
assertArrayEquals(random, baos.toByteArray());
}
@Test
public void testLargerFrames_raw_() throws IOException {
final byte[] random = getRandom(0.5, 100000);

View File

Before

Width:  |  Height:  |  Size: 241 KiB

After

Width:  |  Height:  |  Size: 241 KiB

1
version.sbt Normal file
View File

@ -0,0 +1 @@
version in ThisBuild := "1.1.1"