Class: Vertx::FileSystem

Inherits:
Object
  • Object
show all
Defined in:
src/main/api_shim/core/file_system.rb

Overview

Represents the file-system and contains a broad set of operations for manipulating files. An asynchronous and a synchronous version of each operation is provided. The asynchronous versions take a handler as a final argument which is called when the operation completes or an error occurs. The handler is called with two arguments; the first an exception, this will be nil if the operation has succeeded. The second is the result - this will be nil if the operation failed or there was no result to return. The synchronous versions return the results, or throw exceptions directly.

Author:

Constant Summary

@@j_fs =
org.vertx.java.platform.impl.JRubyVerticleFactory.vertx.fileSystem()

Class Method Summary (collapse)

Class Method Details

+ (Object) chmod(path, perms, dir_perms = nil, &block)

Change the permissions on a file, asynchronously. If the file is directory then all contents will also have their permissions changed recursively. http://download.oracle.com/javase/7/docs/api/java/nio/file/attribute/PosixFilePermissions.html. This is used to set the permissions for any regular files (not directories).

Parameters:

  • path (String)
    Path of file to change permissions
  • perms (String)
    A permission string of the form rwxr-x--- as specified in
  • dir_perms (String) (defaults to: nil)
    A permission string of the form rwxr-x---. Used to set permissions for regular files.


227
228
229
230
# File 'src/main/api_shim/core/file_system.rb', line 227

def FileSystem.chmod(path, perms, dir_perms = nil, &block)
  @@j_fs.chmod(path, perms, dir_perms, ARWrappedHandler.new(block))
  self
end

+ (Object) chmod_sync(path, perms, dir_perms = nil)

Synchronous version of Vertx::FileSystem#FileSystem#FileSystem.chmod


233
234
235
236
# File 'src/main/api_shim/core/file_system.rb', line 233

def FileSystem.chmod_sync(path, perms, dir_perms = nil)
  @@j_fs.chmodSync(path, perms, dir_perms)
  self
end

+ (Object) copy(from, to, &block)

Copy a file, asynchronously. The copy will fail if from does not exist, or if to already exists.

Parameters:

  • from (String)
    Path of file to copy
  • to (String)
    Path of file to copy to
  • hndlr (Block)
    a block representing the handler which is called on completion.


166
167
168
169
# File 'src/main/api_shim/core/file_system.rb', line 166

def FileSystem.copy(from, to, &block)
  @@j_fs.copy(from, to, ARWrappedHandler.new(block))
  self
end

+ (Object) copy_recursive(from, to, &block)

Copy a file recursively, asynchronously. The copy will fail if from does not exist, or if to already exists and is not empty. If the source is a directory all contents of the directory will be copied recursively, i.e. the entire directory tree is copied.

Parameters:

  • from (String)
    Path of file to copy
  • to (String)
    Path of file to copy to


182
183
184
185
# File 'src/main/api_shim/core/file_system.rb', line 182

def FileSystem.copy_recursive(from, to, &block)
  @@j_fs.copy(from, to, true, ARWrappedHandler.new(block))
  self
end

+ (Object) copy_recursive_sync(from, to)

Synchronous version of Vertx::FileSystem#FileSystem#FileSystem.copy_recursive


188
189
190
191
# File 'src/main/api_shim/core/file_system.rb', line 188

def FileSystem.copy_recursive_sync(from, to)
  @@j_fs.copySync(from, to, true)
  self
end

+ (Object) copy_sync(from, to)

Synchronous version of Vertx::FileSystem#FileSystem#FileSystem.copy


172
173
174
175
# File 'src/main/api_shim/core/file_system.rb', line 172

def FileSystem.copy_sync(from, to)
  @@j_fs.copySync(from, to)
  self
end

+ (Object) create_file(path, perms = nil, &block)

Create a new empty file, asynchronously.

Parameters:

  • path (String)
    Path of the file to create.
  • perms (String) (defaults to: nil)
    The file will be created with these permissions.


426
427
428
429
# File 'src/main/api_shim/core/file_system.rb', line 426

def FileSystem.create_file(path, perms = nil, &block)
  @@j_fs.createFile(path, perms, ARWrappedHandler.new(block))
  self
end

+ (Object) create_file_sync(path, perms = nil)

Synchronous version of Vertx::FileSystem#FileSystem#FileSystem.create_file


432
433
434
435
# File 'src/main/api_shim/core/file_system.rb', line 432

def FileSystem.create_file_sync(path, perms = nil)
  @@j_fs.createFileSync(path, perms)
  self
end

+ (Object) delete(path, &block)

Delete a file on the file system, asynchronously. The delete will fail if the file does not exist, or is a directory and is not empty.

Parameters:

  • path (String)
    Path of the file to delete.


307
308
309
310
# File 'src/main/api_shim/core/file_system.rb', line 307

def FileSystem.delete(path, &block)
  @@j_fs.delete(path, ARWrappedHandler.new(block))
  self
end

+ (Object) delete_recursive(path, &block)

Delete a file on the file system recursively, asynchronously. The delete will fail if the file does not exist. If the file is a directory the entire directory contents will be deleted recursively.

Parameters:

  • path (String)
    Path of the file to delete.


322
323
324
325
# File 'src/main/api_shim/core/file_system.rb', line 322

def FileSystem.delete_recursive(path, &block)
  @@j_fs.delete(path, true, ARWrappedHandler.new(block))
  self
end

+ (Object) delete_recursive_sync(path)

Synchronous version of Vertx::FileSystem#FileSystem#FileSystem.delete_recursive


328
329
330
331
# File 'src/main/api_shim/core/file_system.rb', line 328

def FileSystem.delete_recursive_sync(path)
  @@j_fs.deleteSync(path, true)
  self
end

+ (Object) delete_sync(path)

Synchronous version of Vertx::FileSystem#FileSystem#FileSystem.delete


313
314
315
316
# File 'src/main/api_shim/core/file_system.rb', line 313

def FileSystem.delete_sync(path)
  @@j_fs.deleteSync(path)
  self
end

+ (Boolean) exists?(path, &block)

Check if a file exists, asynchronously.

Parameters:

  • path (String)
    Path of the file to check.

Returns:

  • (Boolean)


439
440
441
442
# File 'src/main/api_shim/core/file_system.rb', line 439

def FileSystem.exists?(path, &block)
  @@j_fs.exists(path, ARWrappedHandler.new(block))
  self
end

+ (Boolean) exists_sync?(path)

Synchronous version of Vertx::FileSystem#FileSystem#FileSystem.exists?

Returns:

  • (Boolean)


445
446
447
# File 'src/main/api_shim/core/file_system.rb', line 445

def FileSystem.exists_sync?(path)
  @@j_fs.existsSync(path)
end

+ (Object) fs_props(path, &block)

Get properties for the file system, asynchronously.

Parameters:

  • path (String)
    Path in the file system.


451
452
453
454
# File 'src/main/api_shim/core/file_system.rb', line 451

def FileSystem.fs_props(path, &block)
  @@j_fs.fsProps(path, ARWrappedHandler.new(block) { |j_props| FSProps.new(j_props)})
  self
end

+ (Object) fs_props_sync(path)

Synchronous version of Vertx::FileSystem#FileSystem#FileSystem.fs_props


457
458
459
460
# File 'src/main/api_shim/core/file_system.rb', line 457

def FileSystem.fs_props_sync(path)
  j_fsprops = @@j_fs.fsPropsSync(path)
  FSProps.new(j_fsprops)
end
Create a hard link, asynchronously..

Parameters:

  • link (String)
    Path of the link to create.
  • existing (String)
    Path of where the link points to.


254
255
256
257
# File 'src/main/api_shim/core/file_system.rb', line 254

def FileSystem.link(link, existing, &block)
   @@j_fs.link(link, existing, ARWrappedHandler.new(block))
   self
end
Synchronous version of Vertx::FileSystem#FileSystem#FileSystem.link


260
261
262
263
# File 'src/main/api_shim/core/file_system.rb', line 260

def FileSystem.link_sync(link, existing)
  @@j_fs.linkSync(link, existing)
  self
end

+ (Object) mkdir(path, perms = nil, &block)

Create a directory, asynchronously. The create will fail if the directory already exists, or if it contains parent directories which do not already exist.

Parameters:

  • path (String)
    Path of the directory to create.
  • perms. (String)
    A permission string of the form rwxr-x--- to give directory.


338
339
340
341
# File 'src/main/api_shim/core/file_system.rb', line 338

def FileSystem.mkdir(path, perms = nil, &block)
  @@j_fs.mkdir(path, perms, ARWrappedHandler.new(block))
  self
end

+ (Object) mkdir_sync(path, perms = nil)

Synchronous version of Vertx::FileSystem#FileSystem#FileSystem.mkdir


344
345
346
347
# File 'src/main/api_shim/core/file_system.rb', line 344

def FileSystem.mkdir_sync(path, perms = nil)
  @@j_fs.mkdirSync(path, perms)
  self
end

+ (Object) mkdir_with_parents(path, perms = nil, &block)

Create a directory, and create all it's parent directories if they do not already exist, asynchronously. The create will fail if the directory already exists.

Parameters:

  • path (String)
    Path of the directory to create.
  • perms. (String)
    A permission string of the form rwxr-x--- to give the created directory(ies).


353
354
355
356
# File 'src/main/api_shim/core/file_system.rb', line 353

def FileSystem.mkdir_with_parents(path, perms = nil, &block)
  @@j_fs.mkdir(path, perms, true, ARWrappedHandler.new(block))
  self
end

+ (Object) mkdir_with_parents_sync(path, perms = nil)

Synchronous version of Vertx::FileSystem#FileSystem#FileSystem.mkdir_with_parents


359
360
361
362
# File 'src/main/api_shim/core/file_system.rb', line 359

def FileSystem.mkdir_with_parents_sync(path, perms = nil)
  @@j_fs.mkdirSync(path, perms, true)
  self
end

+ (Object) move(from, to, &block)

Move a file, asynchronously. The move will fail if from does not exist, or if to already exists.

Parameters:

  • from (String)
    Path of file to move
  • to (String)
    Path of file to move to


196
197
198
199
# File 'src/main/api_shim/core/file_system.rb', line 196

def FileSystem.move(from, to, &block)
  @@j_fs.move(from, to, ARWrappedHandler.new(block))
  self
end

+ (Object) move_sync(from, to)

Synchronous version of Vertx::FileSystem#FileSystem#FileSystem.move


202
203
204
205
# File 'src/main/api_shim/core/file_system.rb', line 202

def FileSystem.move_sync(from, to)
  @@j_fs.moveSync(from, to)
  self
end

+ (Object) open(path, perms = nil, read = true, write = true, create_new = true, flush = false, &block)

Open a file on the file system, asynchronously.

Parameters:

  • path (String)
    Path of the file to open.
  • perms (String) (defaults to: nil)
    If the file does not exist and create_new is true, then the file will be created with these permissions.
  • read (Boolean) (defaults to: true)
    Open the file for reading?
  • write (Boolean) (defaults to: true)
    Open the file for writing?
  • create_new (Boolean) (defaults to: true)
    Create the file if it doesn't already exist?
  • flush (Boolean) (defaults to: false)
    Whenever any data is written to the file, flush all changes to permanent storage immediately?


412
413
414
415
# File 'src/main/api_shim/core/file_system.rb', line 412

def FileSystem.open(path, perms = nil, read = true, write = true, create_new = true, flush = false, &block)
  @@j_fs.open(path, perms, read, write, create_new, flush, ARWrappedHandler.new(block){ |j_file| AsyncFile.new(j_file)})
  self
end

+ (Object) open_sync(path, perms = nil, read = true, write = true, create_new = true, flush = false)

Synchronous version of Vertx::FileSystem#FileSystem#FileSystem.open


418
419
420
421
# File 'src/main/api_shim/core/file_system.rb', line 418

def FileSystem.open_sync(path, perms = nil, read = true, write = true, create_new = true, flush = false)
  j_af = @@j_fs.open(path, perms, read, write, create_new, flush)
  AsyncFile.new(j_af)
end

+ (Object) props(path, &block)

Get file properties for a file, asynchronously.

Parameters:

  • path (String)
    Path to file


240
241
242
243
# File 'src/main/api_shim/core/file_system.rb', line 240

def FileSystem.props(path, &block)
  @@j_fs.props(path, ARWrappedHandler.new(block) { |j_props| FileProps.new(j_props) })
  self
end

+ (Object) props_sync(path)

Synchronous version of Vertx::FileSystem#FileSystem#FileSystem.props


246
247
248
249
# File 'src/main/api_shim/core/file_system.rb', line 246

def FileSystem.props_sync(path)
  j_props = @@j_fs.propsSync(path)
  FileProps.new(j_props)
end

+ (Object) read_dir(path, filter = nil, &block)

Read a directory, i.e. list it's contents, asynchronously. The read will fail if the directory does not exist. then only files which match the filter will be returned.

Parameters:

  • path (String)
    Path of the directory to read.
  • filter (String) (defaults to: nil)
    A regular expression to filter out the contents of the directory. If the filter is not nil


369
370
371
372
# File 'src/main/api_shim/core/file_system.rb', line 369

def FileSystem.read_dir(path, filter = nil, &block)
  @@j_fs.readDir(path, filter, ARWrappedHandler.new(block))
  self
end

+ (Object) read_dir_sync(path, filter = nil)

Synchronous version of Vertx::FileSystem#FileSystem#FileSystem.read_dir


375
376
377
# File 'src/main/api_shim/core/file_system.rb', line 375

def FileSystem.read_dir_sync(path, filter = nil)
  @@j_fs.readDirSync(path, filter)
end

+ (Object) read_file_as_buffer(path, &block)

Read the contents of an entire file as a Buffer, asynchronously.

Parameters:

  • path (String)
    Path of the file to read.


381
382
383
384
# File 'src/main/api_shim/core/file_system.rb', line 381

def FileSystem.read_file_as_buffer(path, &block)
  @@j_fs.readFile(path, ARWrappedHandler.new(block) { |j_buff| Buffer.new(j_buff)})
  self
end

+ (Object) read_file_as_buffer_sync(path)

Synchronous version of Vertx::FileSystem#FileSystem#FileSystem.read_file_as_buffer


387
388
389
# File 'src/main/api_shim/core/file_system.rb', line 387

def FileSystem.read_file_as_buffer_sync(path)
  @@j_fs.readFileSync(path)
end
Read a symbolic link, asynchronously. I.e. tells you where the symbolic link points.

Parameters:

  • link (String)
    Path of the link to read.


294
295
296
297
# File 'src/main/api_shim/core/file_system.rb', line 294

def FileSystem.read_symlink(link, &block)
  @@j_fs.readSymlink(link, ARWrappedHandler.new(block))
  self
end
Synchronous version of Vertx::FileSystem#FileSystem#FileSystem.read_symlink


300
301
302
# File 'src/main/api_shim/core/file_system.rb', line 300

def FileSystem.read_symlink_sync(link)
  @@j_fs.readSymlinkSync(link)
end
Create a symbolic link, asynchronously.

Parameters:

  • link (String)
    Path of the link to create.
  • existing (String)
    Path of where the link points to.


268
269
270
271
# File 'src/main/api_shim/core/file_system.rb', line 268

def FileSystem.symlink(link, existing, &block)
   @@j_fs.symlink(link, existing, ARWrappedHandler.new(block))
   self
end
Synchronous version of Vertx::FileSystem#FileSystem#FileSystem.symlink


274
275
276
277
# File 'src/main/api_shim/core/file_system.rb', line 274

def FileSystem.symlink_sync(link, existing)
  @@j_fs.symlinkSync(link, existing)
  self
end

+ (Object) truncate(path, len, &block)

Truncate a file, asynchronously. The move will fail if path does not exist.

Parameters:

  • path (String)
    Path of file to truncate
  • len (FixNum)
    Length to truncate file to. Will fail if len < 0. If len > file size then will do nothing.


210
211
212
213
# File 'src/main/api_shim/core/file_system.rb', line 210

def FileSystem.truncate(path, len, &block)
  @@j_fs.truncate(path, len, ARWrappedHandler.new(block))
  self
end

+ (Object) truncate_sync(path, len)

Synchronous version of Vertx::FileSystem#FileSystem#FileSystem.truncate


216
217
218
219
# File 'src/main/api_shim/core/file_system.rb', line 216

def FileSystem.truncate_sync(path, len)
  @@j_fs.truncateSync(path, len)
  self
end
Unlink a hard link.

Parameters:

  • link (String)
    Path of the link to unlink.


281
282
283
284
# File 'src/main/api_shim/core/file_system.rb', line 281

def FileSystem.unlink(link, &block)
  @@j_fs.unlink(link, ARWrappedHandler.new(block))
  self
end

+ (Object) unlinkSync(link)

Synchronous version of Vertx::FileSystem#FileSystem#FileSystem.unlink


287
288
289
290
# File 'src/main/api_shim/core/file_system.rb', line 287

def FileSystem.unlinkSync(link)
  @@j_fs.unlinkSync(link)
  self
end

+ (Object) write_buffer_to_file(path, buffer, &block)

Write a [Buffer] as the entire contents of a file, asynchronously.

Parameters:

  • path (String)
    Path of the file to write.
  • buffer (String)
    The Buffer to write


394
395
396
397
# File 'src/main/api_shim/core/file_system.rb', line 394

def FileSystem.write_buffer_to_file(path, buffer, &block)
  @@j_fs.writeFile(path, buffer, ARWrappedHandler.new(block))
  self
end

+ (Object) write_buffer_to_file_sync(path, buffer)

Synchronous version of Vertx::FileSystem#FileSystem#FileSystem.write_buffer_to_file


400
401
402
403
# File 'src/main/api_shim/core/file_system.rb', line 400

def FileSystem.write_buffer_to_file_sync(path, buffer)
  @@j_fs.writeFileSync(path, buffer)
  self
end