「ももっち・うらっち」 イラストデザイン集(新し …...⑦ 1 ももっち マスク ⑦ 2 ももっち 手指消毒1 ⑦ 3 ももっち 手指消毒1(マスク)
もっと New I/O。
-
Upload
skrb -
Category
Technology
-
view
7.237 -
download
1
description
Transcript of もっと New I/O。
![Page 1: もっと New I/O。](https://reader034.fdocuments.net/reader034/viewer/2022042512/548279f3b07959240c8b47f4/html5/thumbnails/1.jpg)
もっと New I/O。
Java in the Box
櫻庭 祐一
![Page 2: もっと New I/O。](https://reader034.fdocuments.net/reader034/viewer/2022042512/548279f3b07959240c8b47f4/html5/thumbnails/2.jpg)
JSR 51 New I/O APIs
Mark Reinhold
Buffer/Direct Buffer
Channel
ノンブロッキング I/O
Charset
積み残しあり!
![Page 3: もっと New I/O。](https://reader034.fdocuments.net/reader034/viewer/2022042512/548279f3b07959240c8b47f4/html5/thumbnails/3.jpg)
JSR 51 New I/O APIs
Mark Reinhold
Buffer/Direct Buffer
Channel
ノンブロッキング I/O
Charset
積み残しあり!
An API for scalable I/O operations
on both files and sockets, in the form of
either
or polling
asynchronous requests
that supports bulk access
to file attributes (including MIME content types),
escape to filesystem-specific APIs,
and a service-provider interface for pluggable filesystem
implementations.
that supports bulk access
to file attributes (including MIME content types),
escape to filesystem-specific APIs,
and a service-provider interface for pluggable filesystem
implementations.
A new filesystem interface
![Page 4: もっと New I/O。](https://reader034.fdocuments.net/reader034/viewer/2022042512/548279f3b07959240c8b47f4/html5/thumbnails/4.jpg)
JSR 203 More New I/O APIs
Alan Bateman
非同期 I/O
SocketChannel のマルチキャスト
ファイルシステムインタフェース
当初 J2SE5.0 向け
![Page 5: もっと New I/O。](https://reader034.fdocuments.net/reader034/viewer/2022042512/548279f3b07959240c8b47f4/html5/thumbnails/5.jpg)
なぜファイルシステム ?
メタデータメタデータ
シンボリックリンクシンボリックリンク
ファイルの監視ファイルの監視
![Page 6: もっと New I/O。](https://reader034.fdocuments.net/reader034/viewer/2022042512/548279f3b07959240c8b47f4/html5/thumbnails/6.jpg)
なぜファイルシステム ?
メタデータメタデータ
シンボリックリンクシンボリックリンク
ファイルの監視ファイルの監視
新しいファイルシステム
インタフェースなら
すべて解決 !!
![Page 7: もっと New I/O。](https://reader034.fdocuments.net/reader034/viewer/2022042512/548279f3b07959240c8b47f4/html5/thumbnails/7.jpg)
<<factory>>FileSystems FileSystem
PathFiles <<interface>>AttributeView
<<interface>>FileVisitor
<<interface>>WatchService
![Page 8: もっと New I/O。](https://reader034.fdocuments.net/reader034/viewer/2022042512/548279f3b07959240c8b47f4/html5/thumbnails/8.jpg)
生成
FileSystem fileSystem = FileSystems.getDefault();
// file.txt の生成
Path path1 = fileSystem.getPath("file.txt", null);
// foo/bar/file.txt の生成
Path path2 = fileSystem.getPath("foo", "bar", "file.txt");
![Page 9: もっと New I/O。](https://reader034.fdocuments.net/reader034/viewer/2022042512/548279f3b07959240c8b47f4/html5/thumbnails/9.jpg)
生成
File file = ...;
// File から Path
Path path = file.toPath();
// Path から File
File file2 = path.toFile();
![Page 10: もっと New I/O。](https://reader034.fdocuments.net/reader034/viewer/2022042512/548279f3b07959240c8b47f4/html5/thumbnails/10.jpg)
生成
FileSystem fileSystem = FileSystems.getDefault();
// file.txt の生成
Path path1 = fileSystem.getPath("file.txt", null);
// foo/bar/file.txt の生成
Path path2 = fileSystem.getPath("foo", "bar", "file.txt");
File file = ...;
// File から Path
Path path = file.toPath();
// Path から File
File file2 = path.toFile();
// シンボリックリンクのターゲット
Path target = fileSystem.getPath("realfile.txt");
// シンボリックリンクするファイル
Path link = fileSystem.getPath("link.txt");
// シンボリックリンクの作成
Files.createSymbolicLink(link, target);
![Page 11: もっと New I/O。](https://reader034.fdocuments.net/reader034/viewer/2022042512/548279f3b07959240c8b47f4/html5/thumbnails/11.jpg)
操作 : Files クラス
// ファイルのコピー
String source = ...;
Path source = fileSystem.getPath(source);
String destination = ...;
Path destination = fileSystem.getPath(destination);
Files.copy(source, destination);
![Page 12: もっと New I/O。](https://reader034.fdocuments.net/reader034/viewer/2022042512/548279f3b07959240c8b47f4/html5/thumbnails/12.jpg)
操作 : Files クラス
Path source = ...; Path dest = ...;
// 移動
Files.move(source, dest);
// 削除
Files.delete(dest);
Files.deleteIfExists(dest);
![Page 13: もっと New I/O。](https://reader034.fdocuments.net/reader034/viewer/2022042512/548279f3b07959240c8b47f4/html5/thumbnails/13.jpg)
操作 : Files クラス
Path path = ...;
// ストリームなどの取得
BufferedReader reader = Files.newBufferedReader(path,
Charset.defaultCharset());
BufferedWriter writer = Files.newBufferedWriter(path,
Charset.defaultCharset());
InputStream iStream = Files.newInputStream(path);
OutputStream oStream = Files.newOutputStream(path);
ByteChannel channel = Files.newByteChannel(path);
![Page 14: もっと New I/O。](https://reader034.fdocuments.net/reader034/viewer/2022042512/548279f3b07959240c8b47f4/html5/thumbnails/14.jpg)
操作 : Files クラス
// ファイルのコピー
String source = ...;
Path source = fileSystem.getPath(source);
String destination = ...;
Path destination = fileSystem.getPath(destination);
Files.copy(source, destination);
Path source = ...; Path dest = ...;
// 移動
Files.move(source, dest);
// 削除
Files.delete(dest);
Files.deleteIfExists(dest);
Path path = ...;
// ストリームなどの取得
BufferedReader reader = Files.newBufferedReader(path,
Charset.defaultCharset());
BufferedWriter writer = Files.newBufferedWriter(path,
Charset.defaultCharset());
InputStream iStream = Files.newInputStream(path);
OutputStream oStream = Files.newOutputStream(path);
ByteChannel channel = Files.newByteChannel(path);
Path path = ...;
// 簡易入出力
byte[] bytes = Files.readAllBytes(path);
List<String> lines = Files.readAllLines(path,
Charset.defaultCharset());
Files.write(path, bytes);
Files.write(path, lines, Charset.defaultCharset());
![Page 15: もっと New I/O。](https://reader034.fdocuments.net/reader034/viewer/2022042512/548279f3b07959240c8b47f4/html5/thumbnails/15.jpg)
メタデータ
Path path = ...;
// 直接取得
FileTime creationTime
= (FileTime)Files.getAttribute(path, "creationTime");
// AttributeView を介して取得
BasicFileAttributeView view
= Files.getFileAttributeView(path,
BasicFileAttributeView.class);
BasicFileAttributes attributes = view.readAttributes();
FileTime lastAccessTime = attributes.lastAccessTime();
Path path = ...;
// 直接取得
FileTime creationTime
= (FileTime)Files.getAttribute(path, "creationTime");
// AttributeView を介して取得
BasicFileAttributeView view
= Files.getFileAttributeView(path,
BasicFileAttributeView.class);
BasicFileAttributes attributes = view.readAttributes();
FileTime lastAccessTime = attributes.lastAccessTime();
![Page 16: もっと New I/O。](https://reader034.fdocuments.net/reader034/viewer/2022042512/548279f3b07959240c8b47f4/html5/thumbnails/16.jpg)
メタデータ
Path path = ...;
// 直接取得
FileTime creationTime
= (FileTime)Files.getAttribute(path, "creationTime");
// AttributeView を介して取得
BasicFileAttributeView view
= Files.getFileAttributeView(path,
BasicFileAttributeView.class);
BasicFileAttributes attributes = view.readAttributes();
FileTime lastAccessTime = attributes.lastAccessTime();
Path path = ...;
// 直接取得
FileTime creationTime
= (FileTime)Files.getAttribute(path, "creationTime");
// AttributeView を介して取得
BasicFileAttributeView view
= Files.getFileAttributeView(path,
BasicFileAttributeView.class);
BasicFileAttributes attributes = view.readAttributes();
FileTime lastAccessTime = attributes.lastAccessTime();
![Page 17: もっと New I/O。](https://reader034.fdocuments.net/reader034/viewer/2022042512/548279f3b07959240c8b47f4/html5/thumbnails/17.jpg)
ファイルビジター Vistor パターンを使用してファイルツリーを探索
Path startDir = ...;
Files.walkFileTree(path, new SimpleFileVisitor<Path>() {
public FileVisitResult visitFile(Path file,
BasicFileAttributes attrs) throws IOException {
System.out.println("Visit File: " + file);
return FileVisitResult.CONTINUE;
}
public FileVisitResult preVisitDirectory(Path dir,
BasicFileAttributes attrs) throws IOException {
System.out.println("Visit Directory: " + dir);
return FileVisitResult.CONTINUE;
}
});
![Page 18: もっと New I/O。](https://reader034.fdocuments.net/reader034/viewer/2022042512/548279f3b07959240c8b47f4/html5/thumbnails/18.jpg)
ファイルの監視WatchService
Path dir = fileSystem.getPath(...);
WatchService service = fileSystem.newWatchService();
dir.register(service,
StandardWatchEventKind.ENTRY_MODIFY);
for (;;) {
WatchKey key = service.take();
for (WatchEvent<?> event : key.pollEvents()) {
System.out.println(event.kind()
+ " " + event.context());
}
key.reset();
}
Path dir = fileSystem.getPath(...);
WatchService service = fileSystem.newWatchService();
dir.register(service,
StandardWatchEventKind.ENTRY_MODIFY);
for (;;) {
WatchKey key = service.take();
for (WatchEvent<?> event : key.pollEvents()) {
System.out.println(event.kind()
+ " " + event.context());
}
key.reset();
}
Path dir = fileSystem.getPath(...);
WatchService service = fileSystem.newWatchService();
dir.register(service,
StandardWatchEventKind.ENTRY_MODIFY);
for (;;) {
WatchKey key = service.take();
for (WatchEvent<?> event : key.pollEvents()) {
System.out.println(event.kind()
+ " " + event.context());
}
key.reset();
}
![Page 19: もっと New I/O。](https://reader034.fdocuments.net/reader034/viewer/2022042512/548279f3b07959240c8b47f4/html5/thumbnails/19.jpg)
非同期 I/O
Selector
AsynchronousChannelFuture
CompletionHandler
マルチキャスト
DatagramChannel
![Page 20: もっと New I/O。](https://reader034.fdocuments.net/reader034/viewer/2022042512/548279f3b07959240c8b47f4/html5/thumbnails/20.jpg)
JSR 51 の積み残し
非同期 I/O
ファイルシステムインタフェース
マルチキャスト
JSR 203 More New I/O
ファイルシステムインタフェース
メタデータ ファイルビジター
ファイルの監視
![Page 21: もっと New I/O。](https://reader034.fdocuments.net/reader034/viewer/2022042512/548279f3b07959240c8b47f4/html5/thumbnails/21.jpg)
もっと New I/O。
Java in the Box
櫻庭 祐一