jubilee 2.1.0.beta-java → 2.1.0.rc1-java
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 +4 -4
- data/Gemfile.lock +13 -1
- data/README.md +65 -54
- data/Rakefile +23 -21
- data/examples/chatapp/Gemfile +1 -2
- data/examples/chatapp/Gemfile.lock +2 -2
- data/examples/chatapp/README.md +14 -2
- data/examples/chatapp/app.rb +1 -0
- data/examples/chatapp/config.json +4 -0
- data/examples/chatapp/config.ru +0 -2
- data/jars/annotations-1.3.2.jar +0 -0
- data/jars/lang-jruby-2.1.0-final.jar +0 -0
- data/jars/log4j-1.2.16.jar +0 -0
- data/jars/slf4j-api-1.6.2.jar +0 -0
- data/jars/vertx-core-2.1.2.jar +0 -0
- data/jars/{vertx-hazelcast-2.1.1.jar → vertx-hazelcast-2.1.2.jar} +0 -0
- data/jars/{vertx-platform-2.1.1.jar → vertx-platform-2.1.2.jar} +0 -0
- data/lib/container.rb +117 -0
- data/lib/{vertx → core}/buffer.rb +1 -1
- data/lib/core/datagram.rb +280 -0
- data/lib/core/dns.rb +143 -0
- data/lib/{vertx → core}/event_bus.rb +79 -8
- data/lib/core/file_system.rb +479 -0
- data/lib/{vertx → core}/http.rb +635 -5
- data/lib/core/net.rb +251 -0
- data/lib/core/network_support.rb +77 -0
- data/lib/core/parsetools.rb +105 -0
- data/lib/{vertx → core}/shared_data.rb +2 -2
- data/lib/core/sock_js.rb +116 -0
- data/lib/{vertx → core}/ssl_support.rb +21 -1
- data/lib/{vertx → core}/streams.rb +32 -21
- data/lib/{vertx → core}/tcp_support.rb +22 -36
- data/lib/core/timers.rb +73 -0
- data/lib/core/vertx_require.rb +25 -0
- data/lib/{vertx → core}/wrapped_handler.rb +0 -0
- data/lib/jubilee.rb +5 -8
- data/lib/jubilee/cli.rb +1 -1
- data/lib/jubilee/jubilee.jar +0 -0
- data/lib/jubilee/jubilee_require.rb +24 -0
- data/lib/jubilee/version.rb +1 -1
- data/lib/test_utils.rb +66 -0
- data/lib/vertx.rb +13 -10
- data/lib/vertx_tests.rb +8 -0
- data/pom.xml +351 -0
- data/src/main/assembly/mod.xml +21 -0
- data/{java/src → src/main/java}/jubilee/JubileeService.java +0 -0
- data/{java/src → src/main/java}/org/jruby/jubilee/Const.java +0 -0
- data/{java/src → src/main/java}/org/jruby/jubilee/JubileeVerticle.java +12 -2
- data/src/main/java/org/jruby/jubilee/JubileeVerticleFactory.java +258 -0
- data/{java/src → src/main/java}/org/jruby/jubilee/RackApplication.java +3 -1
- data/{java/src → src/main/java}/org/jruby/jubilee/RackEnvironment.java +2 -2
- data/{java/src → src/main/java}/org/jruby/jubilee/RackEnvironmentHash.java +0 -0
- data/{java/src → src/main/java}/org/jruby/jubilee/RackInput.java +0 -0
- data/{java/src → src/main/java}/org/jruby/jubilee/RackResponse.java +0 -0
- data/{java/src → src/main/java}/org/jruby/jubilee/RubyCallable.java +0 -0
- data/{java/src → src/main/java}/org/jruby/jubilee/RubyHttpServerResponse.java +0 -0
- data/{java/src → src/main/java}/org/jruby/jubilee/RubyNetSocket.java +0 -0
- data/{java/src → src/main/java}/org/jruby/jubilee/RubyPlatformManager.java +0 -0
- data/{java/src → src/main/java}/org/jruby/jubilee/impl/RubyIORackInput.java +0 -0
- data/{java/src → src/main/java}/org/jruby/jubilee/impl/RubyNullIO.java +0 -0
- data/{java/src → src/main/java}/org/jruby/jubilee/utils/RubyHelper.java +0 -0
- data/{java/src → src/main/java}/org/jruby/jubilee/vertx/JubileeVertx.java +0 -0
- data/{java → src/main}/resources/META-INF/services/org.vertx.java.core.spi.cluster.ClusterManagerFactory +0 -0
- data/src/main/resources/META-INF/services/org.vertx.java.deploy.impl.jruby.JubileeVerticleFactory +1 -0
- data/{java → src/main}/resources/default-cluster.xml +0 -0
- data/src/main/resources/mod.json +11 -0
- data/test/jubilee/test_upload.rb +3 -1
- data/vertx_classpath.txt +12 -0
- metadata +69 -47
- data/Guardfile +0 -24
- data/jars/vertx-core-2.1.1.jar +0 -0
- data/java/src/org/jruby/jubilee/RubyChannel.java +0 -89
- data/lib/vertx/README.md +0 -7
@@ -0,0 +1,479 @@
|
|
1
|
+
# Copyright 2011 the original author or authors.
|
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.
|
14
|
+
|
15
|
+
require 'core/streams'
|
16
|
+
require 'core/wrapped_handler.rb'
|
17
|
+
|
18
|
+
module Vertx
|
19
|
+
|
20
|
+
# Represents the properties of a file on the file system
|
21
|
+
# @author {http://tfox.org Tim Fox}
|
22
|
+
class FileProps
|
23
|
+
|
24
|
+
# @private
|
25
|
+
def initialize(j_props)
|
26
|
+
@j_props = j_props
|
27
|
+
end
|
28
|
+
|
29
|
+
# @return [Time] The creation time of the file.
|
30
|
+
def creation_time
|
31
|
+
Time.at(@j_props.creationTime.getTime() / 1000)
|
32
|
+
end
|
33
|
+
|
34
|
+
# @return [Time] The last access time of the file.
|
35
|
+
def last_access_time
|
36
|
+
Time.at(@j_props.lastAccessTime.getTime() / 1000)
|
37
|
+
end
|
38
|
+
|
39
|
+
# @return [Time] The last modified time of the file.
|
40
|
+
def last_modified_time
|
41
|
+
Time.at(@j_props.lastModifiedTime.getTime() / 1000)
|
42
|
+
end
|
43
|
+
|
44
|
+
# @return [Boolean] Is the file a directory?
|
45
|
+
def directory?
|
46
|
+
@j_props.isDirectory
|
47
|
+
end
|
48
|
+
|
49
|
+
# @return [Boolean] Is the file some other file type?
|
50
|
+
def other?
|
51
|
+
@j_props.isOther
|
52
|
+
end
|
53
|
+
|
54
|
+
# @return [Boolean] Is it a regular file?
|
55
|
+
def regular_file?
|
56
|
+
@j_props.isRegularFile
|
57
|
+
end
|
58
|
+
|
59
|
+
# @return [Boolean] Is it a symbolic link?
|
60
|
+
def symbolic_link?
|
61
|
+
@j_props.isSymbolicLink
|
62
|
+
end
|
63
|
+
|
64
|
+
# @return [FixNum] The size of the file, in bytes.
|
65
|
+
def size
|
66
|
+
@j_props.size
|
67
|
+
end
|
68
|
+
|
69
|
+
end
|
70
|
+
|
71
|
+
# Represents the properties of a file system
|
72
|
+
# @author {http://tfox.org Tim Fox}
|
73
|
+
class FSProps
|
74
|
+
|
75
|
+
# @private
|
76
|
+
def initialize(j_props)
|
77
|
+
@j_props = j_props
|
78
|
+
end
|
79
|
+
|
80
|
+
# @return [FixNum] The total space on the file system, in bytes.
|
81
|
+
def total_space
|
82
|
+
@j_props.totalSpace
|
83
|
+
end
|
84
|
+
|
85
|
+
# @return [FixNum] Unallocated space on the file system, in bytes.
|
86
|
+
def unallocated_space
|
87
|
+
@j_props.unallocatedSpace
|
88
|
+
end
|
89
|
+
|
90
|
+
# @return [FixNum] Usable space on the file system, in bytes.
|
91
|
+
def usable_space
|
92
|
+
@j_props.usableSpace
|
93
|
+
end
|
94
|
+
|
95
|
+
end
|
96
|
+
|
97
|
+
# Represents a file on the file-system which can be read from, or written to asynchronously.
|
98
|
+
# The class also includes {ReadStream} and {WriteStream} - this allows the data to be pumped to and from
|
99
|
+
# other streams, e.g. an {HttpClientRequest} instance, using the {Pump} class
|
100
|
+
# @author {http://tfox.org Tim Fox}
|
101
|
+
class AsyncFile
|
102
|
+
|
103
|
+
include ReadStream, WriteStream
|
104
|
+
|
105
|
+
# @private
|
106
|
+
def initialize(j_file)
|
107
|
+
@j_del = j_file
|
108
|
+
end
|
109
|
+
|
110
|
+
# Close the file, asynchronously.
|
111
|
+
def close(&block)
|
112
|
+
@j_del.close(ARWrappedHandler.new(block))
|
113
|
+
end
|
114
|
+
|
115
|
+
# Write a {Buffer} to the file, asynchronously.
|
116
|
+
# When multiple writes are invoked on the same file
|
117
|
+
# there are no guarantees as to order in which those writes actually occur.
|
118
|
+
# @param [Buffer] buffer The buffer to write
|
119
|
+
# @param [FixNum] position The position in the file where to write the buffer. Position is measured in bytes and
|
120
|
+
# starts with zero at the beginning of the file.
|
121
|
+
def write_at_pos(buffer, position, &block)
|
122
|
+
@j_del.write(buffer._to_java_buffer, position, ARWrappedHandler.new(block))
|
123
|
+
self
|
124
|
+
end
|
125
|
+
|
126
|
+
# Reads some data from a file into a buffer, asynchronously.
|
127
|
+
# When multiple reads are invoked on the same file
|
128
|
+
# there are no guarantees as to order in which those reads actually occur.
|
129
|
+
# @param [Buffer] buffer The buffer into which the data which is read is written.
|
130
|
+
# @param [FixNum] offset The position in the buffer where to start writing the data.
|
131
|
+
# @param [FixNum] position The position in the file where to read the data.
|
132
|
+
# @param [FixNum] length The number of bytes to read.
|
133
|
+
def read_at_pos(buffer, offset, position, length, &block)
|
134
|
+
@j_del.read(buffer._to_java_buffer, offset, position, length, ARWrappedHandler.new(block) { |j_buff| Buffer.new(j_buff) })
|
135
|
+
self
|
136
|
+
end
|
137
|
+
|
138
|
+
# Flush any writes made to this file to underlying persistent storage, asynchronously.
|
139
|
+
# If the file was opened with flush set to true then calling this method will have no effect.
|
140
|
+
# @param [Block] hndlr a block representing the handler which is called on completion.
|
141
|
+
def flush
|
142
|
+
Future.new(@j_del.flush)
|
143
|
+
self
|
144
|
+
end
|
145
|
+
|
146
|
+
end
|
147
|
+
|
148
|
+
|
149
|
+
# Represents the file-system and contains a broad set of operations for manipulating files.
|
150
|
+
# An asynchronous and a synchronous version of each operation is provided.
|
151
|
+
# The asynchronous versions take a handler as a final argument which is
|
152
|
+
# called when the operation completes or an error occurs. The handler is called
|
153
|
+
# with two arguments; the first an exception, this will be nil if the operation has
|
154
|
+
# succeeded. The second is the result - this will be nil if the operation failed or
|
155
|
+
# there was no result to return.
|
156
|
+
# The synchronous versions return the results, or throw exceptions directly.
|
157
|
+
# @author {http://tfox.org Tim Fox}
|
158
|
+
class FileSystem
|
159
|
+
|
160
|
+
@@j_fs = org.vertx.java.platform.impl.JRubyVerticleFactory.vertx.fileSystem()
|
161
|
+
|
162
|
+
# Copy a file, asynchronously. The copy will fail if from does not exist, or if to already exists.
|
163
|
+
# @param [String] from Path of file to copy
|
164
|
+
# @param [String] to Path of file to copy to
|
165
|
+
# @param [Block] hndlr a block representing the handler which is called on completion.
|
166
|
+
def FileSystem.copy(from, to, &block)
|
167
|
+
@@j_fs.copy(from, to, ARWrappedHandler.new(block))
|
168
|
+
self
|
169
|
+
end
|
170
|
+
|
171
|
+
# Synchronous version of {#FileSystem.copy}
|
172
|
+
def FileSystem.copy_sync(from, to)
|
173
|
+
@@j_fs.copySync(from, to)
|
174
|
+
self
|
175
|
+
end
|
176
|
+
|
177
|
+
# Copy a file recursively, asynchronously. The copy will fail if from does not exist, or if to already exists and is not empty.
|
178
|
+
# If the source is a directory all contents of the directory will be copied recursively, i.e. the entire directory
|
179
|
+
# tree is copied.
|
180
|
+
# @param [String] from Path of file to copy
|
181
|
+
# @param [String] to Path of file to copy to
|
182
|
+
def FileSystem.copy_recursive(from, to, &block)
|
183
|
+
@@j_fs.copy(from, to, true, ARWrappedHandler.new(block))
|
184
|
+
self
|
185
|
+
end
|
186
|
+
|
187
|
+
# Synchronous version of {#FileSystem.copy_recursive}
|
188
|
+
def FileSystem.copy_recursive_sync(from, to)
|
189
|
+
@@j_fs.copySync(from, to, true)
|
190
|
+
self
|
191
|
+
end
|
192
|
+
|
193
|
+
# Move a file, asynchronously. The move will fail if from does not exist, or if to already exists.
|
194
|
+
# @param [String] from Path of file to move
|
195
|
+
# @param [String] to Path of file to move to
|
196
|
+
def FileSystem.move(from, to, &block)
|
197
|
+
@@j_fs.move(from, to, ARWrappedHandler.new(block))
|
198
|
+
self
|
199
|
+
end
|
200
|
+
|
201
|
+
# Synchronous version of {#FileSystem.move}
|
202
|
+
def FileSystem.move_sync(from, to)
|
203
|
+
@@j_fs.moveSync(from, to)
|
204
|
+
self
|
205
|
+
end
|
206
|
+
|
207
|
+
# Truncate a file, asynchronously. The move will fail if path does not exist.
|
208
|
+
# @param [String] path Path of file to truncate
|
209
|
+
# @param [FixNum] len Length to truncate file to. Will fail if len < 0. If len > file size then will do nothing.
|
210
|
+
def FileSystem.truncate(path, len, &block)
|
211
|
+
@@j_fs.truncate(path, len, ARWrappedHandler.new(block))
|
212
|
+
self
|
213
|
+
end
|
214
|
+
|
215
|
+
# Synchronous version of {#FileSystem.truncate}
|
216
|
+
def FileSystem.truncate_sync(path, len)
|
217
|
+
@@j_fs.truncateSync(path, len)
|
218
|
+
self
|
219
|
+
end
|
220
|
+
|
221
|
+
# Change the permissions on a file, asynchronously. If the file is directory then all contents will also have their permissions changed recursively.
|
222
|
+
# @param [String] path Path of file to change permissions
|
223
|
+
# @param [String] perms A permission string of the form rwxr-x--- as specified in
|
224
|
+
# {http://download.oracle.com/javase/7/docs/api/java/nio/file/attribute/PosixFilePermissions.html}. This is
|
225
|
+
# used to set the permissions for any regular files (not directories).
|
226
|
+
# @param [String] dir_perms A permission string of the form rwxr-x---. Used to set permissions for regular files.
|
227
|
+
def FileSystem.chmod(path, perms, dir_perms = nil, &block)
|
228
|
+
@@j_fs.chmod(path, perms, dir_perms, ARWrappedHandler.new(block))
|
229
|
+
self
|
230
|
+
end
|
231
|
+
|
232
|
+
|
233
|
+
# Synchronous version of {#FileSystem.chmod}
|
234
|
+
def FileSystem.chmod_sync(path, perms, dir_perms = nil)
|
235
|
+
@@j_fs.chmodSync(path, perms, dir_perms)
|
236
|
+
self
|
237
|
+
end
|
238
|
+
|
239
|
+
# Change the ownership of a file, asynchronously.
|
240
|
+
# @param [String] path Path of the file
|
241
|
+
# @param [String] user the user to set the ownership to
|
242
|
+
# @param [String] group the group to set the ownership to
|
243
|
+
def FileSystem.chown(path, user, group, &block)
|
244
|
+
@@j_fs.chown(path, user, group, ARWrappedHandler.new(block))
|
245
|
+
self
|
246
|
+
end
|
247
|
+
|
248
|
+
# Synchronous version of {#FileSystem.chown}
|
249
|
+
def FileSystem.chown_sync(path, user, group)
|
250
|
+
@@j_fs.chownSync(path, user, group)
|
251
|
+
self
|
252
|
+
end
|
253
|
+
|
254
|
+
# Get file properties for a file, asynchronously.
|
255
|
+
# @param [String] path Path to file
|
256
|
+
def FileSystem.props(path, &block)
|
257
|
+
@@j_fs.props(path, ARWrappedHandler.new(block) { |j_props| FileProps.new(j_props) })
|
258
|
+
self
|
259
|
+
end
|
260
|
+
|
261
|
+
# Synchronous version of {#FileSystem.props}
|
262
|
+
def FileSystem.props_sync(path)
|
263
|
+
j_props = @@j_fs.propsSync(path)
|
264
|
+
FileProps.new(j_props)
|
265
|
+
end
|
266
|
+
|
267
|
+
# Create a hard link, asynchronously..
|
268
|
+
# @param [String] link Path of the link to create.
|
269
|
+
# @param [String] existing Path of where the link points to.
|
270
|
+
def FileSystem.link(link, existing, &block)
|
271
|
+
@@j_fs.link(link, existing, ARWrappedHandler.new(block))
|
272
|
+
self
|
273
|
+
end
|
274
|
+
|
275
|
+
# Synchronous version of {#FileSystem.link}
|
276
|
+
def FileSystem.link_sync(link, existing)
|
277
|
+
@@j_fs.linkSync(link, existing)
|
278
|
+
self
|
279
|
+
end
|
280
|
+
|
281
|
+
# Create a symbolic link, asynchronously.
|
282
|
+
# @param [String] link Path of the link to create.
|
283
|
+
# @param [String] existing Path of where the link points to.
|
284
|
+
def FileSystem.symlink(link, existing, &block)
|
285
|
+
@@j_fs.symlink(link, existing, ARWrappedHandler.new(block))
|
286
|
+
self
|
287
|
+
end
|
288
|
+
|
289
|
+
# Synchronous version of {#FileSystem.symlink}
|
290
|
+
def FileSystem.symlink_sync(link, existing)
|
291
|
+
@@j_fs.symlinkSync(link, existing)
|
292
|
+
self
|
293
|
+
end
|
294
|
+
|
295
|
+
# Unlink a hard link.
|
296
|
+
# @param [String] link Path of the link to unlink.
|
297
|
+
def FileSystem.unlink(link, &block)
|
298
|
+
@@j_fs.unlink(link, ARWrappedHandler.new(block))
|
299
|
+
self
|
300
|
+
end
|
301
|
+
|
302
|
+
# Synchronous version of {#FileSystem.unlink}
|
303
|
+
def FileSystem.unlinkSync(link)
|
304
|
+
@@j_fs.unlinkSync(link)
|
305
|
+
self
|
306
|
+
end
|
307
|
+
|
308
|
+
# Read a symbolic link, asynchronously. I.e. tells you where the symbolic link points.
|
309
|
+
# @param [String] link Path of the link to read.
|
310
|
+
def FileSystem.read_symlink(link, &block)
|
311
|
+
@@j_fs.readSymlink(link, ARWrappedHandler.new(block))
|
312
|
+
self
|
313
|
+
end
|
314
|
+
|
315
|
+
# Synchronous version of {#FileSystem.read_symlink}
|
316
|
+
def FileSystem.read_symlink_sync(link)
|
317
|
+
@@j_fs.readSymlinkSync(link)
|
318
|
+
end
|
319
|
+
|
320
|
+
# Delete a file on the file system, asynchronously.
|
321
|
+
# The delete will fail if the file does not exist, or is a directory and is not empty.
|
322
|
+
# @param [String] path Path of the file to delete.
|
323
|
+
def FileSystem.delete(path, &block)
|
324
|
+
@@j_fs.delete(path, ARWrappedHandler.new(block))
|
325
|
+
self
|
326
|
+
end
|
327
|
+
|
328
|
+
# Synchronous version of {#FileSystem.delete}
|
329
|
+
def FileSystem.delete_sync(path)
|
330
|
+
@@j_fs.deleteSync(path)
|
331
|
+
self
|
332
|
+
end
|
333
|
+
|
334
|
+
# Delete a file on the file system recursively, asynchronously.
|
335
|
+
# The delete will fail if the file does not exist. If the file is a directory the entire directory contents
|
336
|
+
# will be deleted recursively.
|
337
|
+
# @param [String] path Path of the file to delete.
|
338
|
+
def FileSystem.delete_recursive(path, &block)
|
339
|
+
@@j_fs.delete(path, true, ARWrappedHandler.new(block))
|
340
|
+
self
|
341
|
+
end
|
342
|
+
|
343
|
+
# Synchronous version of {#FileSystem.delete_recursive}
|
344
|
+
def FileSystem.delete_recursive_sync(path)
|
345
|
+
@@j_fs.deleteSync(path, true)
|
346
|
+
self
|
347
|
+
end
|
348
|
+
|
349
|
+
# Create a directory, asynchronously.
|
350
|
+
# The create will fail if the directory already exists, or if it contains parent directories which do not already
|
351
|
+
# exist.
|
352
|
+
# @param [String] path Path of the directory to create.
|
353
|
+
# @param [String] perms. A permission string of the form rwxr-x--- to give directory.
|
354
|
+
def FileSystem.mkdir(path, perms = nil, &block)
|
355
|
+
@@j_fs.mkdir(path, perms, ARWrappedHandler.new(block))
|
356
|
+
self
|
357
|
+
end
|
358
|
+
|
359
|
+
# Synchronous version of {#FileSystem.mkdir}
|
360
|
+
def FileSystem.mkdir_sync(path, perms = nil)
|
361
|
+
@@j_fs.mkdirSync(path, perms)
|
362
|
+
self
|
363
|
+
end
|
364
|
+
|
365
|
+
# Create a directory, and create all it's parent directories if they do not already exist, asynchronously.
|
366
|
+
# The create will fail if the directory already exists.
|
367
|
+
# @param [String] path Path of the directory to create.
|
368
|
+
# @param [String] perms. A permission string of the form rwxr-x--- to give the created directory(ies).
|
369
|
+
def FileSystem.mkdir_with_parents(path, perms = nil, &block)
|
370
|
+
@@j_fs.mkdir(path, perms, true, ARWrappedHandler.new(block))
|
371
|
+
self
|
372
|
+
end
|
373
|
+
|
374
|
+
# Synchronous version of {#FileSystem.mkdir_with_parents}
|
375
|
+
def FileSystem.mkdir_with_parents_sync(path, perms = nil)
|
376
|
+
@@j_fs.mkdirSync(path, perms, true)
|
377
|
+
self
|
378
|
+
end
|
379
|
+
|
380
|
+
# Read a directory, i.e. list it's contents, asynchronously.
|
381
|
+
# The read will fail if the directory does not exist.
|
382
|
+
# @param [String] path Path of the directory to read.
|
383
|
+
# @param [String] filter A regular expression to filter out the contents of the directory. If the filter is not nil
|
384
|
+
# then only files which match the filter will be returned.
|
385
|
+
def FileSystem.read_dir(path, filter = nil, &block)
|
386
|
+
@@j_fs.readDir(path, filter, ARWrappedHandler.new(block))
|
387
|
+
self
|
388
|
+
end
|
389
|
+
|
390
|
+
# Synchronous version of {#FileSystem.read_dir}
|
391
|
+
def FileSystem.read_dir_sync(path, filter = nil)
|
392
|
+
@@j_fs.readDirSync(path, filter)
|
393
|
+
end
|
394
|
+
|
395
|
+
# Read the contents of an entire file as a {Buffer}, asynchronously.
|
396
|
+
# @param [String] path Path of the file to read.
|
397
|
+
def FileSystem.read_file_as_buffer(path, &block)
|
398
|
+
@@j_fs.readFile(path, ARWrappedHandler.new(block) { |j_buff| Buffer.new(j_buff)})
|
399
|
+
self
|
400
|
+
end
|
401
|
+
|
402
|
+
# Synchronous version of {#FileSystem.read_file_as_buffer}
|
403
|
+
def FileSystem.read_file_as_buffer_sync(path)
|
404
|
+
@@j_fs.readFileSync(path)
|
405
|
+
end
|
406
|
+
|
407
|
+
# Write a [Buffer] as the entire contents of a file, asynchronously.
|
408
|
+
# @param [String] path Path of the file to write.
|
409
|
+
# @param [String] buffer The Buffer to write
|
410
|
+
def FileSystem.write_buffer_to_file(path, buffer, &block)
|
411
|
+
@@j_fs.writeFile(path, buffer, ARWrappedHandler.new(block))
|
412
|
+
self
|
413
|
+
end
|
414
|
+
|
415
|
+
# Synchronous version of {#FileSystem.write_buffer_to_file}
|
416
|
+
def FileSystem.write_buffer_to_file_sync(path, buffer)
|
417
|
+
@@j_fs.writeFileSync(path, buffer)
|
418
|
+
self
|
419
|
+
end
|
420
|
+
|
421
|
+
# Open a file on the file system, asynchronously.
|
422
|
+
# @param [String] path Path of the file to open.
|
423
|
+
# @param [String] perms If the file does not exist and create_new is true, then the file will be created with these permissions.
|
424
|
+
# @param [Boolean] read Open the file for reading?
|
425
|
+
# @param [Boolean] write Open the file for writing?
|
426
|
+
# @param [Boolean] create_new Create the file if it doesn't already exist?
|
427
|
+
# @param [Boolean] flush Whenever any data is written to the file, flush all changes to permanent storage immediately?
|
428
|
+
def FileSystem.open(path, perms = nil, read = true, write = true, create_new = true, flush = false, &block)
|
429
|
+
@@j_fs.open(path, perms, read, write, create_new, flush, ARWrappedHandler.new(block){ |j_file| AsyncFile.new(j_file)})
|
430
|
+
self
|
431
|
+
end
|
432
|
+
|
433
|
+
# Synchronous version of {#FileSystem.open}
|
434
|
+
def FileSystem.open_sync(path, perms = nil, read = true, write = true, create_new = true, flush = false)
|
435
|
+
j_af = @@j_fs.open(path, perms, read, write, create_new, flush)
|
436
|
+
AsyncFile.new(j_af)
|
437
|
+
end
|
438
|
+
|
439
|
+
# Create a new empty file, asynchronously.
|
440
|
+
# @param [String] path Path of the file to create.
|
441
|
+
# @param [String] perms The file will be created with these permissions.
|
442
|
+
def FileSystem.create_file(path, perms = nil, &block)
|
443
|
+
@@j_fs.createFile(path, perms, ARWrappedHandler.new(block))
|
444
|
+
self
|
445
|
+
end
|
446
|
+
|
447
|
+
# Synchronous version of {#FileSystem.create_file}
|
448
|
+
def FileSystem.create_file_sync(path, perms = nil)
|
449
|
+
@@j_fs.createFileSync(path, perms)
|
450
|
+
self
|
451
|
+
end
|
452
|
+
|
453
|
+
# Check if a file exists, asynchronously.
|
454
|
+
# @param [String] path Path of the file to check.
|
455
|
+
def FileSystem.exists?(path, &block)
|
456
|
+
@@j_fs.exists(path, ARWrappedHandler.new(block))
|
457
|
+
self
|
458
|
+
end
|
459
|
+
|
460
|
+
# Synchronous version of {#FileSystem.exists?}
|
461
|
+
def FileSystem.exists_sync?(path)
|
462
|
+
@@j_fs.existsSync(path)
|
463
|
+
end
|
464
|
+
|
465
|
+
# Get properties for the file system, asynchronously.
|
466
|
+
# @param [String] path Path in the file system.
|
467
|
+
def FileSystem.fs_props(path, &block)
|
468
|
+
@@j_fs.fsProps(path, ARWrappedHandler.new(block) { |j_props| FSProps.new(j_props)})
|
469
|
+
self
|
470
|
+
end
|
471
|
+
|
472
|
+
# Synchronous version of {#FileSystem.fs_props}
|
473
|
+
def FileSystem.fs_props_sync(path)
|
474
|
+
j_fsprops = @@j_fs.fsPropsSync(path)
|
475
|
+
FSProps.new(j_fsprops)
|
476
|
+
end
|
477
|
+
|
478
|
+
end
|
479
|
+
end
|