jruby-mmap 0.2.0-java

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 7c7bf167de5d4de80bf87ca85cc506dfeb8ef238
4
+ data.tar.gz: 0eb9ebd6fdfd47ca7c6cc6fb4e441a3088ddaa20
5
+ SHA512:
6
+ metadata.gz: 65e536cadfa5713e0e57bbeb2c43a329c53d0845567eee2834020e78a5b6689a334d25629116e5c831e83ea563291e25be7bfff5afa0d3332f06f5416c798111
7
+ data.tar.gz: 1f72791aba1c476c6f68190430d0e7231e16eaa197e7686f26570ab1dc1d6663db43c0759ead059b27a66b935e06e70e8898b7c4f5f9b7fb37bb34abae7205b7
data/LICENSE ADDED
@@ -0,0 +1,13 @@
1
+ Copyright (c) 2015–2016 Colin Surprenant colin.surprenant@gmail.com
2
+
3
+ Licensed under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License.
5
+ You may obtain a copy of the License at
6
+
7
+ http://www.apache.org/licenses/LICENSE-2.0
8
+
9
+ Unless required by applicable law or agreed to in writing, software
10
+ distributed under the License is distributed on an "AS IS" BASIS,
11
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ See the License for the specific language governing permissions and
13
+ limitations under the License.
data/README.md ADDED
@@ -0,0 +1,67 @@
1
+ # JRuby Mmap
2
+
3
+ This gem only supports [JRuby](http://jruby.org/).
4
+
5
+ JRuby Mmap is a Java JRuby extension wrapper over the Java NIO memory mapping.
6
+
7
+ See also
8
+ - [JRuby Mmap Queues](https://github.com/colinsurprenant/jruby-mmap-queues)
9
+ - [JRuby Mmap Benchmarks](https://github.com/colinsurprenant/jruby-mmap-benchmark)
10
+
11
+ ## Installation
12
+
13
+ This gem only supports [JRuby](http://jruby.org/).
14
+
15
+ Add this line to your application's Gemfile:
16
+
17
+ ```ruby
18
+ gem 'jruby-mmap'
19
+ ```
20
+
21
+ And then execute:
22
+
23
+ $ bundle
24
+
25
+ Or install it yourself as:
26
+
27
+ $ gem install jruby-mmap
28
+
29
+ ## Building
30
+
31
+ Building uses Gradle. The build process compiles the Java classes, produces a jar file and copies the jar file in the project `lib/jruby-mmap` dir.
32
+
33
+ ```sh
34
+ $ ./gradlew build
35
+ ```
36
+
37
+ ## Usage
38
+
39
+ ```ruby
40
+ require "jruby-mmap"
41
+
42
+ BYTE_SIZE = 2048
43
+ FILE_PATH = "mmap-file-path"
44
+
45
+ mmap = Mmap::ByteBuffer.new(FILE_PATH, BYTE_SIZE)
46
+ mmap.put_bytes("foobar")
47
+ mmap.close
48
+ ```
49
+
50
+ ## Tests
51
+
52
+ ```sh
53
+ $ bundle install
54
+ $ bundle exec rspec
55
+ ```
56
+
57
+ ## Author
58
+
59
+ **Colin Surprenant** on [GitHub](https://github.com/colinsurprenant) and [Twitter](https://twitter.com/colinsurprenant).
60
+
61
+ ## Contributing
62
+
63
+ Bug reports and pull requests are welcome on GitHub at https://github.com/colinsurprenant/jruby-mmap.
64
+
65
+ ## License and Copyright
66
+
67
+ *JRuby Mmap* is released under the Apache License, Version 2.0. See [LICENSE](https://github.com/colinsurprenant/jruby-mmap/blob/master/LICENSE).
@@ -0,0 +1,28 @@
1
+ # encoding: utf-8
2
+
3
+ lib = File.expand_path('../lib', __FILE__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require 'jruby-mmap/version'
6
+
7
+ raise("JRuby required") unless defined?(JRUBY_VERSION)
8
+
9
+ Gem::Specification.new do |s|
10
+ s.name = "jruby-mmap"
11
+ s.version = Mmap::VERSION
12
+
13
+ s.authors = ["Colin Surprenant"]
14
+ s.email = ["colin.surprenant@gmail.com"]
15
+
16
+ s.summary = "JRuby extension to Java NIO Mmap"
17
+ s.description = s.summary
18
+ s.homepage = "http://github.com/colinsurprenant/jruby-mmap"
19
+ s.licenses = ["Apache-2.0"]
20
+
21
+ s.require_paths = ["lib"]
22
+ s.files += Dir.glob(["jruby-mmap.gemspec", "lib/**/*.jar", "lib/**/*.rb", "spec/**/*.rb", "README.md", "LICENSE"])
23
+
24
+ s.platform = "java"
25
+
26
+ s.add_development_dependency "rspec", "~> 3"
27
+ s.add_development_dependency "rake", "~> 10"
28
+ end
data/lib/jruby-mmap.rb ADDED
@@ -0,0 +1,3 @@
1
+ # encoding: utf-8
2
+
3
+ require "jruby-mmap/jruby-mmap.rb"
Binary file
@@ -0,0 +1,17 @@
1
+ # encoding: utf-8
2
+
3
+ require "java"
4
+ require "jruby-mmap/version"
5
+
6
+ # local dev setup
7
+ classes_dir = File.expand_path("../../../build/classes/main", __FILE__)
8
+
9
+ if File.directory?(classes_dir)
10
+ # if in local dev setup, add target to classpath
11
+ $CLASSPATH << classes_dir unless $CLASSPATH.include?(classes_dir)
12
+ else
13
+ # otherwise use included jar
14
+ require "jruby-mmap/jruby-mmap-#{Mmap::VERSION}.jar"
15
+ end
16
+
17
+ require "mmap"
@@ -0,0 +1,4 @@
1
+ module Mmap
2
+ # sync with build.gradle
3
+ VERSION = "0.2.0"
4
+ end
@@ -0,0 +1,147 @@
1
+ require 'spec_helper'
2
+ # require "tempfile"
3
+
4
+ describe Mmap do
5
+ INT_BYTES = 4
6
+ LONG_BYTES = 8
7
+
8
+ before(:all) do
9
+ @path = "spec_mmap_file.dat"
10
+ @size = 2048
11
+ File.delete(@path) if File.exist?(@path)
12
+ end
13
+
14
+ after(:each) do
15
+ File.delete(@path) if File.exist?(@path)
16
+ end
17
+
18
+ it "should create a file with specified size" do
19
+ mmap = Mmap::ByteBuffer.new(@path, 2048)
20
+ expect(File.size(@path)).to eq(mmap.size)
21
+ mmap.close
22
+ end
23
+
24
+ it "should be at position 0 upon initialize" do
25
+ mmap = Mmap::ByteBuffer.new(@path, @size)
26
+ expect(mmap.position).to eq(0)
27
+ mmap.close
28
+ end
29
+
30
+ it "should relative put/get integer" do
31
+ mmap = Mmap::ByteBuffer.new(@path, 2048)
32
+ mmap.put_int(1967)
33
+ expect(mmap.position).to eq(INT_BYTES)
34
+ mmap.position = 0
35
+ expect(mmap.get_int).to eq(1967)
36
+ mmap.close
37
+ end
38
+
39
+ it "should absolute put/get integer" do
40
+ mmap = Mmap::ByteBuffer.new(@path, 2048)
41
+ mmap.put_int(1, 1 * INT_BYTES)
42
+ expect(mmap.position).to eq(0)
43
+ mmap.put_int(Java::java.lang.Integer::MAX_VALUE, 3 * INT_BYTES)
44
+ expect(mmap.position).to eq(0)
45
+ mmap.put_int(2, 2 * INT_BYTES)
46
+ expect(mmap.position).to eq(0)
47
+ mmap.put_int(0, 0 * INT_BYTES)
48
+ expect(mmap.position).to eq(0)
49
+
50
+ expect(mmap.get_int(3 * INT_BYTES)).to eq(Java::java.lang.Integer::MAX_VALUE)
51
+ expect(mmap.position).to eq(0)
52
+ expect(mmap.get_int(0 * INT_BYTES)).to eq(0)
53
+ expect(mmap.position).to eq(0)
54
+ expect(mmap.get_int(2 * INT_BYTES)).to eq(2)
55
+ expect(mmap.position).to eq(0)
56
+ expect(mmap.get_int(1 * INT_BYTES)).to eq(1)
57
+ expect(mmap.position).to eq(0)
58
+
59
+ expect{mmap.put_int(Java::java.lang.Integer::MAX_VALUE + 1, 0)}.to raise_error(RangeError)
60
+
61
+ mmap.close
62
+ end
63
+
64
+ it "should relative put/get long" do
65
+ mmap = Mmap::ByteBuffer.new(@path, 2048)
66
+ mmap.put_long(1967)
67
+ expect(mmap.position).to eq(LONG_BYTES)
68
+ mmap.position = 0
69
+ expect(mmap.get_long).to eq(1967)
70
+ mmap.close
71
+ end
72
+
73
+ it "should absolute put/get long" do
74
+ mmap = Mmap::ByteBuffer.new(@path, 2048)
75
+ mmap.put_long(1, 1 * LONG_BYTES)
76
+ expect(mmap.position).to eq(0)
77
+ mmap.put_long(Java::java.lang.Long::MAX_VALUE, 3 * LONG_BYTES)
78
+ expect(mmap.position).to eq(0)
79
+ mmap.put_long(2, 2 * LONG_BYTES)
80
+ expect(mmap.position).to eq(0)
81
+ mmap.put_long(0, 0 * LONG_BYTES)
82
+ expect(mmap.position).to eq(0)
83
+
84
+ expect(mmap.get_long(3 * LONG_BYTES)).to eq(Java::java.lang.Long::MAX_VALUE)
85
+ expect(mmap.position).to eq(0)
86
+ expect(mmap.get_long(0 * LONG_BYTES)).to eq(0)
87
+ expect(mmap.position).to eq(0)
88
+ expect(mmap.get_long(2 * LONG_BYTES)).to eq(2)
89
+ expect(mmap.position).to eq(0)
90
+ expect(mmap.get_long(1 * LONG_BYTES)).to eq(1)
91
+ expect(mmap.position).to eq(0)
92
+
93
+ expect{mmap.put_long(Java::java.lang.Long::MAX_VALUE + 1, 0)}.to raise_error(RangeError)
94
+
95
+ mmap.close
96
+ end
97
+
98
+ it "should relative put/get bytes" do
99
+ mmap = Mmap::ByteBuffer.new(@path, 2048)
100
+ s = "hello world"
101
+ expect(s.size).to eq(11)
102
+ expect(s.bytesize).to eq(11)
103
+ mmap.put_bytes(s)
104
+ expect(mmap.position).to eq(11)
105
+
106
+ s = "foobar"
107
+ expect(s.size).to eq(6)
108
+ expect(s.bytesize).to eq(6)
109
+ mmap.put_bytes(s)
110
+ expect(mmap.position).to eq(17)
111
+
112
+ mmap.position = 0
113
+ expect(mmap.get_bytes(11)).to eq("hello world")
114
+ expect(mmap.get_bytes(6)).to eq("foobar")
115
+ mmap.close
116
+ end
117
+
118
+ it "should relative put/get bytes copy" do
119
+ mmap = Mmap::ByteBuffer.new(@path, 2048)
120
+ s = "hello world"
121
+ expect(s.size).to eq(11)
122
+ expect(s.bytesize).to eq(11)
123
+ mmap.put_bytes_copy(s)
124
+ expect(mmap.position).to eq(11)
125
+
126
+ s = "foobar"
127
+ expect(s.size).to eq(6)
128
+ expect(s.bytesize).to eq(6)
129
+ mmap.put_bytes_copy(s)
130
+ expect(mmap.position).to eq(17)
131
+
132
+ mmap.position = 0
133
+ expect(mmap.get_bytes(11)).to eq("hello world")
134
+ expect(mmap.get_bytes(6)).to eq("foobar")
135
+ mmap.close
136
+ end
137
+
138
+ it "should mmap when opening existing file" do
139
+ mmap = Mmap::ByteBuffer.new(@path, 2048)
140
+ mmap.put_bytes("hello foo bar baz")
141
+ expect(mmap.position).to eq(17)
142
+ mmap.close
143
+ mmap = Mmap::ByteBuffer.new(@path, 2048)
144
+ expect(mmap.get_bytes(17)).to eq("hello foo bar baz")
145
+ mmap.close
146
+ end
147
+ end
@@ -0,0 +1,5 @@
1
+ $:.unshift File.expand_path("../../lib/", __FILE__)
2
+ $:.unshift File.expand_path("../../spec/", __FILE__)
3
+
4
+ require "rspec"
5
+ require "jruby-mmap"
metadata ADDED
@@ -0,0 +1,81 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jruby-mmap
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
+ platform: java
6
+ authors:
7
+ - Colin Surprenant
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-03-10 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - "~>"
17
+ - !ruby/object:Gem::Version
18
+ version: '3'
19
+ name: rspec
20
+ prerelease: false
21
+ type: :development
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '3'
27
+ - !ruby/object:Gem::Dependency
28
+ requirement: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - "~>"
31
+ - !ruby/object:Gem::Version
32
+ version: '10'
33
+ name: rake
34
+ prerelease: false
35
+ type: :development
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10'
41
+ description: JRuby extension to Java NIO Mmap
42
+ email:
43
+ - colin.surprenant@gmail.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - LICENSE
49
+ - README.md
50
+ - jruby-mmap.gemspec
51
+ - lib/jruby-mmap.rb
52
+ - lib/jruby-mmap/jruby-mmap-0.2.0.jar
53
+ - lib/jruby-mmap/jruby-mmap.rb
54
+ - lib/jruby-mmap/version.rb
55
+ - spec/jruby-mmap/mmap_spec.rb
56
+ - spec/spec_helper.rb
57
+ homepage: http://github.com/colinsurprenant/jruby-mmap
58
+ licenses:
59
+ - Apache-2.0
60
+ metadata: {}
61
+ post_install_message:
62
+ rdoc_options: []
63
+ require_paths:
64
+ - lib
65
+ required_ruby_version: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ required_rubygems_version: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ requirements: []
76
+ rubyforge_project:
77
+ rubygems_version: 2.4.8
78
+ signing_key:
79
+ specification_version: 4
80
+ summary: JRuby extension to Java NIO Mmap
81
+ test_files: []