java_to_base64 0.0.1-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: eea44ec290c12573d17a0cc27bfb23313bec8f57
4
+ data.tar.gz: 7a3b95256647b6083576d8e9f8550635ac288131
5
+ SHA512:
6
+ metadata.gz: 14968c00cd3493a4509601354c6f66a2b5e81a5da4bfc7b957264cd7bf807520d61b7e999d3135d9d933b8db80cf8ac7a26f1f3dc880ccf94a6e1532f61bde03
7
+ data.tar.gz: 2245596941fba656e5419dcb5e6d8436520cafb467ce539b023c9c2ab6c28ab7390080270b3c203d01225219a773158aa8b77943a24c13d8eb52ad422d144186
data/.gitignore ADDED
@@ -0,0 +1,19 @@
1
+ *.gem
2
+ *.rbc
3
+ *.ruby-*
4
+ *.swp
5
+ .bundle
6
+ .config
7
+ .yardoc
8
+ Gemfile.lock
9
+ InstalledFiles
10
+ _yardoc
11
+ coverage
12
+ doc/
13
+ lib/bundler/man
14
+ pkg
15
+ rdoc
16
+ spec/reports
17
+ test/tmp
18
+ test/version_tmp
19
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in java_to_base64.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Brandon Dewitt
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # JavaToBase64
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'java_to_base64'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install java_to_base64
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rake/testtask'
3
+
4
+ Rake::TestTask.new do |t|
5
+ t.libs.push "lib"
6
+ t.libs.push "spec"
7
+ t.pattern = "spec/**/*_spec.rb"
8
+ t.verbose = true
9
+ end
10
+
11
+ task :spec => :test
12
+ task :default => :spec
@@ -0,0 +1,27 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'java_to_base64/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "java_to_base64"
8
+ gem.version = JavaToBase64::VERSION
9
+ gem.authors = ["Brandon Dewitt"]
10
+ gem.email = ["brandonsdewitt@gmail.com"]
11
+ gem.description = %q{ simple utility module to provide to_base64 and from_base64 for java objects }
12
+ gem.summary = %q{ simple utility module to provide to_base64 and from_base64 for java objects }
13
+ gem.homepage = ""
14
+ gem.platform = "java"
15
+
16
+ gem.files = `git ls-files`.split($/)
17
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
18
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
19
+ gem.require_paths = ["lib"]
20
+
21
+ gem.add_dependency 'i_can_has_java_class'
22
+
23
+ gem.add_development_dependency "bundler"
24
+ gem.add_development_dependency "mocha"
25
+ gem.add_development_dependency "pry"
26
+ gem.add_development_dependency "rake"
27
+ end
@@ -0,0 +1,3 @@
1
+ module JavaToBase64
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,45 @@
1
+ require 'java'
2
+ require "java_to_base64/version"
3
+ require 'i_can_has_java_class'
4
+
5
+ unless ::ICanHasJavaClass.java_class_defined?("org.apache.commons.codec.binary.Base64.encodeBase64URLSafeString")
6
+ require 'java_to_base64/jars/commons-codec-1.9.jar'
7
+ end
8
+
9
+ module JavaToBase64
10
+ def self.included(klass)
11
+ unless klass.java_kind_of?(::Java::JavaIo::Serializable)
12
+ warn <<-SERIALIZABLE
13
+ To include JavaToBase64 in a Java class you must implement java.io.Serializable
14
+ SERIALIZABLE
15
+ end
16
+
17
+ klass.class_eval do
18
+ include ::JavaToBase64::InstanceMethods
19
+ extend ::JavaToBase64::ClassMethods
20
+ end
21
+ end
22
+
23
+ module InstanceMethods
24
+ def to_base64
25
+ byte_array_output_stream = java.io.ByteArrayOutputStream.new
26
+ object_output_stream = java.io.ObjectOutputStream.new(byte_array_output_stream)
27
+ object_output_stream.write_object(self)
28
+ bytes = byte_array_output_stream.to_byte_array
29
+
30
+ return org.apache.commons.codec.binary.Base64.encodeBase64URLSafeString(bytes)
31
+ end
32
+ end
33
+
34
+ module ClassMethods
35
+ def from_base64(base64_string)
36
+ decoded_form = org.apache.commons.codec.binary.Base64.decodeBase64(base64_string)
37
+ byte_array_input_stream = java.io.ByteArrayInputStream.new(decoded_form)
38
+ # NOTE: JRuby ObjectInputStream https://github.com/ribrdb/jruby/commit/8ab064f4fffc86f89d5ceca1cbf29a6783b83802
39
+ # Overrides the class loader to allow for JRuby objects to be deserialized correctly
40
+ jruby_input_stream = org.jruby.util.JRubyObjectInputStream.new(::JRuby.runtime, byte_array_input_stream)
41
+
42
+ return jruby_input_stream.read_object
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,24 @@
1
+ require 'spec_helper'
2
+
3
+ class Java::JavaLang::String
4
+ include JavaToBase64
5
+ end
6
+
7
+ describe JavaToBase64 do
8
+
9
+ it "adds to_base64 to an isntance" do
10
+ Java::JavaLang::String.new().must_respond_to :to_base64
11
+ end
12
+
13
+ it "adds from_base64 to the class" do
14
+ Java::JavaLang::String.must_respond_to :from_base64
15
+ end
16
+
17
+ it "serializes and deserializes back to the original" do
18
+ string = ::Java::JavaLang::String.new("derp")
19
+ new_string = ::Java::JavaLang::String.from_base64(string.to_base64)
20
+
21
+ string.to_s.must_equal(new_string.to_s)
22
+ end
23
+
24
+ end
@@ -0,0 +1,9 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ Bundler.require(:default, :development, :test)
4
+
5
+ require 'minitest/mock'
6
+ require 'minitest/spec'
7
+ require 'minitest/autorun'
8
+ require 'minitest/pride'
9
+ require 'mocha/api'
metadata ADDED
@@ -0,0 +1,127 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: java_to_base64
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: java
6
+ authors:
7
+ - Brandon Dewitt
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-06-19 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: i_can_has_java_class
15
+ version_requirements: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ requirement: !ruby/object:Gem::Requirement
21
+ requirements:
22
+ - - '>='
23
+ - !ruby/object:Gem::Version
24
+ version: '0'
25
+ prerelease: false
26
+ type: :runtime
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ requirement: !ruby/object:Gem::Requirement
35
+ requirements:
36
+ - - '>='
37
+ - !ruby/object:Gem::Version
38
+ version: '0'
39
+ prerelease: false
40
+ type: :development
41
+ - !ruby/object:Gem::Dependency
42
+ name: mocha
43
+ version_requirements: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ requirement: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - '>='
51
+ - !ruby/object:Gem::Version
52
+ version: '0'
53
+ prerelease: false
54
+ type: :development
55
+ - !ruby/object:Gem::Dependency
56
+ name: pry
57
+ version_requirements: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ requirement: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - '>='
65
+ - !ruby/object:Gem::Version
66
+ version: '0'
67
+ prerelease: false
68
+ type: :development
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ version_requirements: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ requirement: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - '>='
79
+ - !ruby/object:Gem::Version
80
+ version: '0'
81
+ prerelease: false
82
+ type: :development
83
+ description: ' simple utility module to provide to_base64 and from_base64 for java
84
+ objects '
85
+ email:
86
+ - brandonsdewitt@gmail.com
87
+ executables: []
88
+ extensions: []
89
+ extra_rdoc_files: []
90
+ files:
91
+ - .gitignore
92
+ - Gemfile
93
+ - LICENSE.txt
94
+ - README.md
95
+ - Rakefile
96
+ - java_to_base64.gemspec
97
+ - lib/java_to_base64.rb
98
+ - lib/java_to_base64/jars/commons-codec-1.9.jar
99
+ - lib/java_to_base64/version.rb
100
+ - spec/java_to_base64_spec.rb
101
+ - spec/spec_helper.rb
102
+ homepage: ''
103
+ licenses: []
104
+ metadata: {}
105
+ post_install_message:
106
+ rdoc_options: []
107
+ require_paths:
108
+ - lib
109
+ required_ruby_version: !ruby/object:Gem::Requirement
110
+ requirements:
111
+ - - '>='
112
+ - !ruby/object:Gem::Version
113
+ version: '0'
114
+ required_rubygems_version: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - '>='
117
+ - !ruby/object:Gem::Version
118
+ version: '0'
119
+ requirements: []
120
+ rubyforge_project:
121
+ rubygems_version: 2.2.2
122
+ signing_key:
123
+ specification_version: 4
124
+ summary: simple utility module to provide to_base64 and from_base64 for java objects
125
+ test_files:
126
+ - spec/java_to_base64_spec.rb
127
+ - spec/spec_helper.rb