wirispluginengine 3.62.0.1322
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/Rakefile +34 -0
- data/app/assets/javascripts/wirispluginengine/WIRISplugins.js +2833 -0
- data/app/controllers/wirispluginengine/application_controller.rb +75 -0
- data/app/helpers/wirispluginengine/application_helper.rb +4 -0
- data/config/routes.rb +4 -0
- data/configuration.ini.dist +104 -0
- data/lib/com/wiris/common/WInteger.rb +57 -0
- data/lib/com/wiris/plugin/api/Cas.rb +8 -0
- data/lib/com/wiris/plugin/api/CleanCache.rb +8 -0
- data/lib/com/wiris/plugin/api/Configuration.rb +8 -0
- data/lib/com/wiris/plugin/api/ConfigurationKeys.rb +96 -0
- data/lib/com/wiris/plugin/api/Editor.rb +8 -0
- data/lib/com/wiris/plugin/api/Filter.rb +8 -0
- data/lib/com/wiris/plugin/api/ImageFormatController.rb +8 -0
- data/lib/com/wiris/plugin/api/ParamsProvider.rb +8 -0
- data/lib/com/wiris/plugin/api/PluginBuilder.rb +79 -0
- data/lib/com/wiris/plugin/api/Render.rb +8 -0
- data/lib/com/wiris/plugin/api/ServiceResourceLoader.rb +8 -0
- data/lib/com/wiris/plugin/api/Test.rb +8 -0
- data/lib/com/wiris/plugin/api/TextService.rb +8 -0
- data/lib/com/wiris/plugin/configuration/ConfigurationUpdater.rb +8 -0
- data/lib/com/wiris/plugin/impl/CasImpl.rb +146 -0
- data/lib/com/wiris/plugin/impl/CleanCacheImpl.rb +111 -0
- data/lib/com/wiris/plugin/impl/ConfigurationImpl.rb +176 -0
- data/lib/com/wiris/plugin/impl/CustomConfigurationUpdater.rb +38 -0
- data/lib/com/wiris/plugin/impl/DefaultConfigurationUpdater.rb +29 -0
- data/lib/com/wiris/plugin/impl/EditorImpl.rb +86 -0
- data/lib/com/wiris/plugin/impl/FileConfigurationUpdater.rb +34 -0
- data/lib/com/wiris/plugin/impl/FileStorageAndCache.rb +59 -0
- data/lib/com/wiris/plugin/impl/FolderTreeStorageAndCache.rb +144 -0
- data/lib/com/wiris/plugin/impl/GenericParamsProviderImpl.rb +56 -0
- data/lib/com/wiris/plugin/impl/HttpImpl.rb +53 -0
- data/lib/com/wiris/plugin/impl/HttpListener.rb +8 -0
- data/lib/com/wiris/plugin/impl/ImageFormatControllerPng.rb +73 -0
- data/lib/com/wiris/plugin/impl/ImageFormatControllerSvg.rb +34 -0
- data/lib/com/wiris/plugin/impl/PluginBuilderImpl.rb +253 -0
- data/lib/com/wiris/plugin/impl/RenderImpl.rb +280 -0
- data/lib/com/wiris/plugin/impl/ServiceResourceLoaderImpl.rb +52 -0
- data/lib/com/wiris/plugin/impl/TestImpl.rb +166 -0
- data/lib/com/wiris/plugin/impl/TextFilter.rb +211 -0
- data/lib/com/wiris/plugin/impl/TextFilterTags.rb +55 -0
- data/lib/com/wiris/plugin/impl/TextServiceImpl.rb +118 -0
- data/lib/com/wiris/plugin/storage/StorageAndCache.rb +8 -0
- data/lib/com/wiris/util/json/JSon.rb +536 -0
- data/lib/com/wiris/util/json/JSonIntegerFormat.rb +21 -0
- data/lib/com/wiris/util/json/StringParser.rb +61 -0
- data/lib/com/wiris/util/sys/HttpConnection.rb +18 -0
- data/lib/com/wiris/util/sys/HttpConnectionListener.rb +8 -0
- data/lib/com/wiris/util/sys/IniFile.rb +143 -0
- data/lib/com/wiris/util/sys/Store.rb +109 -0
- data/lib/com/wiris/util/xml/SerializableImpl.rb +20 -0
- data/lib/com/wiris/util/xml/WCharacterBase.rb +634 -0
- data/lib/com/wiris/util/xml/WEntities.rb +14 -0
- data/lib/com/wiris/util/xml/WXmlUtils.rb +515 -0
- data/lib/com/wiris/util/xml/XmlSerializer.rb +485 -0
- data/lib/com/wiris/util/xml/XmlWriter.rb +279 -0
- data/lib/loader.rb +12 -0
- data/lib/src-generic/Array.rb +23 -0
- data/lib/src-generic/ArrayInt.rb +32 -0
- data/lib/src-generic/Base64.rb +15 -0
- data/lib/src-generic/BaseCode.rb +94 -0
- data/lib/src-generic/Bytes.rb +50 -0
- data/lib/src-generic/BytesInput.rb +38 -0
- data/lib/src-generic/EReg.rb +56 -0
- data/lib/src-generic/File.rb +36 -0
- data/lib/src-generic/FileLock.rb +27 -0
- data/lib/src-generic/FileSystem.rb +37 -0
- data/lib/src-generic/Hash.rb +43 -0
- data/lib/src-generic/Http.rb +107 -0
- data/lib/src-generic/HttpRequest.rb +25 -0
- data/lib/src-generic/HttpResponse.rb +71 -0
- data/lib/src-generic/Iterator.rb +20 -0
- data/lib/src-generic/Math.rb +15 -0
- data/lib/src-generic/Md5.rb +8 -0
- data/lib/src-generic/Md5Tools.rb +12 -0
- data/lib/src-generic/PropertiesTools.rb +33 -0
- data/lib/src-generic/Reflect.rb +17 -0
- data/lib/src-generic/RubyConfigurationUpdater.rb +45 -0
- data/lib/src-generic/Serializer.rb +85 -0
- data/lib/src-generic/Std.rb +74 -0
- data/lib/src-generic/Storage.rb +153 -0
- data/lib/src-generic/StringBuf.rb +41 -0
- data/lib/src-generic/StringTools.rb +46 -0
- data/lib/src-generic/Timer.rb +7 -0
- data/lib/src-generic/Type.rb +19 -0
- data/lib/src-generic/TypeTools.rb +32 -0
- data/lib/src-generic/Unserializer.rb +73 -0
- data/lib/src-generic/Utf8.rb +27 -0
- data/lib/src-generic/Xml.rb +199 -0
- data/lib/src-generic/extended/Integer.rb +5 -0
- data/lib/src-generic/extended/Math.rb +7 -0
- data/lib/src-generic/extended/Properties.rb +12 -0
- data/lib/src-generic/extended/String.rb +39 -0
- data/lib/src-generic/settings/PlatformSettings.rb +19 -0
- data/lib/wirispluginengine.rb +5 -0
- data/lib/wirispluginengine/engine.rb +5 -0
- data/lib/wirispluginengine/integration/cleancache.rb +8 -0
- data/lib/wirispluginengine/integration/configurationjs.rb +16 -0
- data/lib/wirispluginengine/integration/configurationjson.rb +7 -0
- data/lib/wirispluginengine/integration/createimage.rb +8 -0
- data/lib/wirispluginengine/integration/getmathml.rb +18 -0
- data/lib/wirispluginengine/integration/resource.rb +8 -0
- data/lib/wirispluginengine/integration/service.rb +6 -0
- data/lib/wirispluginengine/integration/showimage.rb +21 -0
- data/lib/wirispluginengine/integration/test.rb +6 -0
- data/lib/wirispluginengine/version.rb +3 -0
- data/resources/VERSION +1 -0
- data/resources/default-configuration.ini +45 -0
- data/resources/tech.txt +1 -0
- data/resources/wirisplugin.css +43 -0
- metadata +182 -0
|
@@ -0,0 +1,279 @@
|
|
|
1
|
+
module WirisPlugin
|
|
2
|
+
include Wiris
|
|
3
|
+
require('com/wiris/util/xml/WXmlUtils.rb')
|
|
4
|
+
class XmlWriter
|
|
5
|
+
include Wiris
|
|
6
|
+
|
|
7
|
+
INDENT_STRING = " "
|
|
8
|
+
ECHO_FILTER = 2
|
|
9
|
+
AUTO_IGNORING_SPACE_FILTER = 1
|
|
10
|
+
PRETTY_PRINT_FILTER = 0
|
|
11
|
+
@prettyPrint = true
|
|
12
|
+
attr_accessor :prettyPrint
|
|
13
|
+
@xmlDeclaration = false
|
|
14
|
+
attr_accessor :xmlDeclaration
|
|
15
|
+
@autoIgnoringWhitespace = true
|
|
16
|
+
attr_accessor :autoIgnoringWhitespace
|
|
17
|
+
attr_accessor :inlineElements
|
|
18
|
+
attr_accessor :filter
|
|
19
|
+
attr_accessor :tagOpen
|
|
20
|
+
attr_accessor :firstLine
|
|
21
|
+
attr_accessor :inline
|
|
22
|
+
attr_accessor :inlineMark
|
|
23
|
+
attr_accessor :depth
|
|
24
|
+
attr_accessor :cdataSection
|
|
25
|
+
attr_accessor :currentPrefixes
|
|
26
|
+
attr_accessor :hasWhiteSpace
|
|
27
|
+
attr_accessor :nameSpace
|
|
28
|
+
attr_accessor :whiteSpace
|
|
29
|
+
attr_accessor :sb
|
|
30
|
+
def initialize()
|
|
31
|
+
super()
|
|
32
|
+
@filter = PRETTY_PRINT_FILTER
|
|
33
|
+
@xmlDeclaration = false
|
|
34
|
+
@inlineElements = Array.new()
|
|
35
|
+
@firstLine = generateFirstLine("UTF-8")
|
|
36
|
+
reset()
|
|
37
|
+
end
|
|
38
|
+
def setFilter(filterType)
|
|
39
|
+
@filter = filterType
|
|
40
|
+
end
|
|
41
|
+
def getFilter()
|
|
42
|
+
return @filter
|
|
43
|
+
end
|
|
44
|
+
def setXmlDeclaration(xmlFragment)
|
|
45
|
+
@xmlDeclaration = xmlFragment
|
|
46
|
+
end
|
|
47
|
+
def isXmlDeclaration()
|
|
48
|
+
return @xmlDeclaration
|
|
49
|
+
end
|
|
50
|
+
def setInlineElements(inlineElements)
|
|
51
|
+
if inlineElements!=nil
|
|
52
|
+
@inlineElements = inlineElements
|
|
53
|
+
else
|
|
54
|
+
@inlineElements = Array.new()
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
def getInlineElements()
|
|
58
|
+
return @inlineElements
|
|
59
|
+
end
|
|
60
|
+
def startDocument()
|
|
61
|
+
reset()
|
|
62
|
+
if @xmlDeclaration
|
|
63
|
+
write(@firstLine)
|
|
64
|
+
end
|
|
65
|
+
if !@prettyPrint
|
|
66
|
+
write("\n")
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
def endDocument()
|
|
70
|
+
closeOpenTag(false)
|
|
71
|
+
end
|
|
72
|
+
def startPrefixMapping(prefix,uri)
|
|
73
|
+
if (uri==@currentPrefixes::get(prefix))
|
|
74
|
+
return
|
|
75
|
+
end
|
|
76
|
+
if uri::length()==0
|
|
77
|
+
return
|
|
78
|
+
end
|
|
79
|
+
pref = prefix
|
|
80
|
+
if prefix::length()>0
|
|
81
|
+
pref = ":"+prefix
|
|
82
|
+
end
|
|
83
|
+
ns = (((" xmlns"+pref)+"=\"")+uri)+"\""
|
|
84
|
+
@nameSpace::add(ns)
|
|
85
|
+
@currentPrefixes::set(prefix,uri)
|
|
86
|
+
end
|
|
87
|
+
def endPrefixMapping(prefix)
|
|
88
|
+
@currentPrefixes::remove(prefix)
|
|
89
|
+
end
|
|
90
|
+
def startElement(uri,localName,qName,atts)
|
|
91
|
+
closeOpenTag(false)
|
|
92
|
+
processWhiteSpace(@inline||!(@autoIgnoringWhitespace||@prettyPrint))
|
|
93
|
+
if @prettyPrint&&!@inline
|
|
94
|
+
writeIndent()
|
|
95
|
+
end
|
|
96
|
+
name = qName
|
|
97
|
+
if (name==nil)||(name::length()==0)
|
|
98
|
+
name = localName
|
|
99
|
+
end
|
|
100
|
+
write("<"+name)
|
|
101
|
+
writeAttributes(atts)
|
|
102
|
+
if @nameSpace!=nil
|
|
103
|
+
write(@nameSpace::toString())
|
|
104
|
+
@nameSpace = nil
|
|
105
|
+
end
|
|
106
|
+
@tagOpen = true
|
|
107
|
+
if !@inline&&@inlineElements::contains_(name)
|
|
108
|
+
@inlineMark = @depth
|
|
109
|
+
@inline = true
|
|
110
|
+
end
|
|
111
|
+
@depth+=1
|
|
112
|
+
end
|
|
113
|
+
def endElement(uri,localName,qName)
|
|
114
|
+
name = qName
|
|
115
|
+
if (name==nil)||(name::length()==0)
|
|
116
|
+
name = localName
|
|
117
|
+
end
|
|
118
|
+
writeSpace = (@tagOpen||@inline)||!(@autoIgnoringWhitespace||@prettyPrint)
|
|
119
|
+
processWhiteSpace(writeSpace)
|
|
120
|
+
@depth-=1
|
|
121
|
+
if @tagOpen
|
|
122
|
+
closeOpenTag(true)
|
|
123
|
+
else
|
|
124
|
+
if (!@inline&&@prettyPrint)&&!writeSpace
|
|
125
|
+
writeIndent()
|
|
126
|
+
end
|
|
127
|
+
write(("</"+name)+">")
|
|
128
|
+
end
|
|
129
|
+
if @inline&&(@inlineMark==@depth)
|
|
130
|
+
@inline = false
|
|
131
|
+
@inlineMark = -1
|
|
132
|
+
end
|
|
133
|
+
end
|
|
134
|
+
def startCDATA()
|
|
135
|
+
closeOpenTag(false)
|
|
136
|
+
write("<![CDATA[")
|
|
137
|
+
@cdataSection = true
|
|
138
|
+
end
|
|
139
|
+
def endCDATA()
|
|
140
|
+
@cdataSection = false
|
|
141
|
+
write("]]>")
|
|
142
|
+
end
|
|
143
|
+
def characters(ch,start,length)
|
|
144
|
+
if @cdataSection
|
|
145
|
+
writeChars(ch,start,length)
|
|
146
|
+
else
|
|
147
|
+
if !@inline
|
|
148
|
+
if self.class.isWhiteSpace(ch,start,length)
|
|
149
|
+
@hasWhiteSpace = true
|
|
150
|
+
for i in start..start+length-1
|
|
151
|
+
@whiteSpace::addChar(ch[i])
|
|
152
|
+
i+=1
|
|
153
|
+
end
|
|
154
|
+
return
|
|
155
|
+
else
|
|
156
|
+
processWhiteSpace(true)
|
|
157
|
+
@inlineMark = @depth-1
|
|
158
|
+
@inline = true
|
|
159
|
+
end
|
|
160
|
+
end
|
|
161
|
+
closeOpenTag(false)
|
|
162
|
+
writeTextChars(ch,start,length)
|
|
163
|
+
end
|
|
164
|
+
end
|
|
165
|
+
def writeChars(ch,start,length)
|
|
166
|
+
for i in start..start+length-1
|
|
167
|
+
@sb::addChar(ch[i])
|
|
168
|
+
i+=1
|
|
169
|
+
end
|
|
170
|
+
end
|
|
171
|
+
def write(s)
|
|
172
|
+
@sb::add(s)
|
|
173
|
+
end
|
|
174
|
+
def writeText(s)
|
|
175
|
+
@sb::add(WXmlUtils::htmlEscape(s))
|
|
176
|
+
end
|
|
177
|
+
def writeTextChars(ch,start,length)
|
|
178
|
+
s = StringBuf.new()
|
|
179
|
+
for i in start..start+length-1
|
|
180
|
+
s::addChar(ch[i])
|
|
181
|
+
i+=1
|
|
182
|
+
end
|
|
183
|
+
@sb::add(WXmlUtils::htmlEscape(s::toString()))
|
|
184
|
+
end
|
|
185
|
+
def self.isWhiteSpace(chars,start,length)
|
|
186
|
+
for i in start..start+length-1
|
|
187
|
+
c = chars[i]
|
|
188
|
+
if !((((c==' ')||(c=="\n"))||(c=="\r"))||(c=="\t"))
|
|
189
|
+
return false
|
|
190
|
+
end
|
|
191
|
+
i+=1
|
|
192
|
+
end
|
|
193
|
+
return true
|
|
194
|
+
end
|
|
195
|
+
def closeOpenTag(endElement)
|
|
196
|
+
if @tagOpen
|
|
197
|
+
if endElement
|
|
198
|
+
write("/")
|
|
199
|
+
end
|
|
200
|
+
write(">")
|
|
201
|
+
@tagOpen = false
|
|
202
|
+
end
|
|
203
|
+
end
|
|
204
|
+
def writeAttributes(atts)
|
|
205
|
+
if atts==nil
|
|
206
|
+
return
|
|
207
|
+
end
|
|
208
|
+
for i in 0..atts::getLength()-1
|
|
209
|
+
name = atts::getName(i)
|
|
210
|
+
value = atts::getValue(i)
|
|
211
|
+
if name::startsWith("xmlns")
|
|
212
|
+
prefix = nil
|
|
213
|
+
uri = value
|
|
214
|
+
if name::length()>5
|
|
215
|
+
if name::charAt(6)==':'
|
|
216
|
+
prefix = name::substring(6)
|
|
217
|
+
end
|
|
218
|
+
else
|
|
219
|
+
prefix = ""
|
|
220
|
+
end
|
|
221
|
+
if (prefix!=nil)&&(uri==@currentPrefixes::get(prefix))
|
|
222
|
+
next
|
|
223
|
+
end
|
|
224
|
+
end
|
|
225
|
+
write(" ")
|
|
226
|
+
write(name)
|
|
227
|
+
write("=\"")
|
|
228
|
+
writeText(value)
|
|
229
|
+
write("\"")
|
|
230
|
+
i+=1
|
|
231
|
+
end
|
|
232
|
+
end
|
|
233
|
+
def processWhiteSpace(write)
|
|
234
|
+
if @hasWhiteSpace&&write
|
|
235
|
+
closeOpenTag(false)
|
|
236
|
+
writeText(@whiteSpace::toString())
|
|
237
|
+
end
|
|
238
|
+
@whiteSpace = StringBuf.new()
|
|
239
|
+
@hasWhiteSpace = false
|
|
240
|
+
end
|
|
241
|
+
def writeIndent()
|
|
242
|
+
write("\n")
|
|
243
|
+
for i in 0..@depth-1
|
|
244
|
+
write(INDENT_STRING)
|
|
245
|
+
i+=1
|
|
246
|
+
end
|
|
247
|
+
end
|
|
248
|
+
def generateFirstLine(encoding)
|
|
249
|
+
return ("<?xml version=\"1.0\" encoding=\""+encoding)+"\"?>"
|
|
250
|
+
end
|
|
251
|
+
def reset()
|
|
252
|
+
@tagOpen = false
|
|
253
|
+
@inline = false
|
|
254
|
+
@inlineMark = -1
|
|
255
|
+
@depth = 0
|
|
256
|
+
@cdataSection = false
|
|
257
|
+
@hasWhiteSpace = false
|
|
258
|
+
@currentPrefixes = Hash.new()
|
|
259
|
+
@whiteSpace = StringBuf.new()
|
|
260
|
+
@nameSpace = StringBuf.new()
|
|
261
|
+
@sb = StringBuf.new()
|
|
262
|
+
if @filter==PRETTY_PRINT_FILTER
|
|
263
|
+
@autoIgnoringWhitespace = true
|
|
264
|
+
@prettyPrint = true
|
|
265
|
+
else
|
|
266
|
+
if @filter==AUTO_IGNORING_SPACE_FILTER
|
|
267
|
+
@autoIgnoringWhitespace = true
|
|
268
|
+
@prettyPrint = false
|
|
269
|
+
else
|
|
270
|
+
@autoIgnoringWhitespace = false
|
|
271
|
+
@prettyPrint = false
|
|
272
|
+
end
|
|
273
|
+
end
|
|
274
|
+
end
|
|
275
|
+
def toString()
|
|
276
|
+
return sb::toString()
|
|
277
|
+
end
|
|
278
|
+
end
|
|
279
|
+
end
|
data/lib/loader.rb
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
module Wiris
|
|
2
|
+
p "Loadin WirisPlugin..."
|
|
3
|
+
if !defined?(Quizzesproxy)
|
|
4
|
+
Dir[File.dirname(__FILE__) + '/src-generic/**/*.rb'].each {|file| require file}
|
|
5
|
+
Dir[File.dirname(__FILE__) + '/src-generic/**/*/*.rb'].each {|file| require file}
|
|
6
|
+
else
|
|
7
|
+
require 'src-generic/RubyConfigurationUpdater.rb'
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
p "WirisPlugin loaded."
|
|
11
|
+
|
|
12
|
+
end
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
module Wiris
|
|
2
|
+
class Array < Array
|
|
3
|
+
def iterator
|
|
4
|
+
return Iterator.new(self)
|
|
5
|
+
end
|
|
6
|
+
|
|
7
|
+
def get(i)
|
|
8
|
+
return self[i]
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def _(i, e=nil)
|
|
12
|
+
if e.nil?
|
|
13
|
+
return get(i)
|
|
14
|
+
else
|
|
15
|
+
self[i] = e
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def contains_(key)
|
|
20
|
+
return self.include? key
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
module Wiris
|
|
2
|
+
class ArrayInt < ::Array
|
|
3
|
+
def sort()
|
|
4
|
+
for i in 1..length()
|
|
5
|
+
j = i
|
|
6
|
+
b = get(i)
|
|
7
|
+
while ((j>0) && get(j-1) > b)
|
|
8
|
+
insert(j,get(j-1))
|
|
9
|
+
j -=1
|
|
10
|
+
end
|
|
11
|
+
insert(j, b)
|
|
12
|
+
i += 1
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def splice(i, len)
|
|
17
|
+
na = slice!(i, len)
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def get(i)
|
|
21
|
+
return self[i]
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def _(i, e=nil)
|
|
25
|
+
if e.nil?
|
|
26
|
+
return get(i)
|
|
27
|
+
else
|
|
28
|
+
self[i] = e
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
require 'base64'
|
|
2
|
+
|
|
3
|
+
module Wiris
|
|
4
|
+
class Base64
|
|
5
|
+
def initialize()
|
|
6
|
+
end
|
|
7
|
+
def encodeBytes(b)
|
|
8
|
+
#Using '::' to call Base64 module out of the Wiris module scope.
|
|
9
|
+
return Bytes.ofString(::Base64::strict_encode64(b.toString()))
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def decodeBytes(b)
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
module Wiris
|
|
2
|
+
class BaseCode
|
|
3
|
+
@bytes
|
|
4
|
+
@nbits
|
|
5
|
+
@tbl = nil
|
|
6
|
+
@charSet
|
|
7
|
+
@base
|
|
8
|
+
|
|
9
|
+
def initialize(base)
|
|
10
|
+
@base = base
|
|
11
|
+
@charSet = base.toString()
|
|
12
|
+
n = base.length()
|
|
13
|
+
@nbits = 0
|
|
14
|
+
while(n>1)
|
|
15
|
+
@nbits+=1
|
|
16
|
+
n = n / 2
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def initTable()
|
|
21
|
+
@tbl = []
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
for i in 0..255
|
|
25
|
+
@tbl[i] = -1
|
|
26
|
+
i+=1
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
i = 0
|
|
30
|
+
for i in 0..@base.length()
|
|
31
|
+
if !@base.get(i).nil?
|
|
32
|
+
@tbl[@base.get(i)] = i
|
|
33
|
+
end
|
|
34
|
+
i+=1
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def decodeBytes(b)
|
|
40
|
+
if @tbl.nil?
|
|
41
|
+
initTable()
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
bitsize = b.length() * @nbits
|
|
45
|
+
size = bitsize/8
|
|
46
|
+
o = []
|
|
47
|
+
buf = 0
|
|
48
|
+
curbits = 0
|
|
49
|
+
pin = 0
|
|
50
|
+
pout = 0
|
|
51
|
+
while (pout < size)
|
|
52
|
+
while (curbits < 8)
|
|
53
|
+
curbits += @nbits
|
|
54
|
+
buf <<= @nbits
|
|
55
|
+
i = @tbl[b.get(pin)]
|
|
56
|
+
pin+=1
|
|
57
|
+
buf |= i
|
|
58
|
+
end
|
|
59
|
+
curbits -= 8
|
|
60
|
+
o[pout] = ((buf >> curbits) & 0xFF)
|
|
61
|
+
pout += 1;
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
return Bytes.ofData(o)
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
def encodeBytes(b)
|
|
68
|
+
bas = @base
|
|
69
|
+
size = (b.length()*8)/@nbits
|
|
70
|
+
o = []
|
|
71
|
+
buf = 0
|
|
72
|
+
curbits = 0
|
|
73
|
+
mask = (1 << @nbits) -1
|
|
74
|
+
pin = 0
|
|
75
|
+
pout = 0
|
|
76
|
+
while (pout < size)
|
|
77
|
+
while (curbits < @nbits)
|
|
78
|
+
curbits += 8
|
|
79
|
+
buf <<= 8
|
|
80
|
+
buf |= b.get(pin)
|
|
81
|
+
pin +=1
|
|
82
|
+
end
|
|
83
|
+
curbits -= @nbits
|
|
84
|
+
o[pout] = bas.get((buf >> curbits) & mask)
|
|
85
|
+
pout+=1
|
|
86
|
+
end
|
|
87
|
+
if (curbits > 0)
|
|
88
|
+
o[pout] = bas.get((buf << (@nbits - curbits)) & mask)
|
|
89
|
+
pout +=1
|
|
90
|
+
end
|
|
91
|
+
return Bytes.ofData(o)
|
|
92
|
+
end
|
|
93
|
+
end
|
|
94
|
+
end
|