Soumettre la recherche
Mettre en ligne
Nio2
•
Télécharger en tant que PPTX, PDF
•
3 j'aime
•
1,099 vues
Appresso Engineering Team
Suivre
Signaler
Partager
Signaler
Partager
1 sur 23
Télécharger maintenant
Recommandé
もっと New I/O。
もっと New I/O。
Yuichi Sakuraba
NIO.2を使って簡単ファイル操作
NIO.2を使って簡単ファイル操作
Yuichi Sakuraba
第3回 FIC&FCS合同勉強会
第3回 FIC&FCS合同勉強会
Hiroyuki Honta
How to make gem
How to make gem
Ken Iiboshi
Gunosy Go lang study #6 net http url
Gunosy Go lang study #6 net http url
Innami Satoshi
PythonでRakeもどきを作ってみた
PythonでRakeもどきを作ってみた
kwatch
LinAction Theme LPICの問題を解いてみる~インストールとパッケージ管理編~
LinAction Theme LPICの問題を解いてみる~インストールとパッケージ管理編~
cyberblack28 Ichikawa
debugging server with strace
debugging server with strace
Yoshinari Takaoka
Recommandé
もっと New I/O。
もっと New I/O。
Yuichi Sakuraba
NIO.2を使って簡単ファイル操作
NIO.2を使って簡単ファイル操作
Yuichi Sakuraba
第3回 FIC&FCS合同勉強会
第3回 FIC&FCS合同勉強会
Hiroyuki Honta
How to make gem
How to make gem
Ken Iiboshi
Gunosy Go lang study #6 net http url
Gunosy Go lang study #6 net http url
Innami Satoshi
PythonでRakeもどきを作ってみた
PythonでRakeもどきを作ってみた
kwatch
LinAction Theme LPICの問題を解いてみる~インストールとパッケージ管理編~
LinAction Theme LPICの問題を解いてみる~インストールとパッケージ管理編~
cyberblack28 Ichikawa
debugging server with strace
debugging server with strace
Yoshinari Takaoka
Boostライブラリ一周の旅
Boostライブラリ一周の旅
Akira Takahashi
2011年10月7日
2011年10月7日
nukaemon
Tottoruby 20110903
Tottoruby 20110903
Takashi SAKAGUCHI
みんなのPython勉強会#77 パッケージングしよう
みんなのPython勉強会#77 パッケージングしよう
Atsushi Odagiri
Lithium Labo #1
Lithium Labo #1
Yusuke Ando
Stagefright入門
Stagefright入門
l_b__
しょしんしゃのためのhello world
しょしんしゃのためのhello world
wata2ki
Rails初心者レッスン lesson5 2edition
Rails初心者レッスン lesson5 2edition
Satomi Tsujita
リナックスに置ける様々なリモートエキスプロイト手法 by スクハー・リー
リナックスに置ける様々なリモートエキスプロイト手法 by スクハー・リー
CODE BLUE
Easy caching and logging package using annotation in Python
Easy caching and logging package using annotation in Python
Yasunori Horikoshi
/etc/network/interfaces について
/etc/network/interfaces について
Kazuhiro Nishiyama
MacPort_&_FTP_ver1.0
MacPort_&_FTP_ver1.0
Satoshi Kume
ソフトウェアエンジニアのための「機械学習理論」入門・ハンズオン演習ガイド
ソフトウェアエンジニアのための「機械学習理論」入門・ハンズオン演習ガイド
Etsuji Nakai
10分でわかるFuelPHP @ 2012/05 OSC2012 Nagoya
10分でわかるFuelPHP @ 2012/05 OSC2012 Nagoya
kenjis
APASEC 2013 - ROP/JIT を使わずに DEP/ASLR を回避する手法を見てみた。
APASEC 2013 - ROP/JIT を使わずに DEP/ASLR を回避する手法を見てみた。
Satoshi Mimura
PYTHON PACKAGING (PyFes 2012.03 発表資料)
PYTHON PACKAGING (PyFes 2012.03 発表資料)
Takayuki Shimizukawa
Solaris Container
Solaris Container
Fumikazu FUJIWARA
ParliamentでGeoSPARQL
ParliamentでGeoSPARQL
Teppei Inaba
知って得する標準関数の使い方
知って得する標準関数の使い方
Soudai Sone
FuelPHPをさわってみて
FuelPHPをさわってみて
Sotaro Omura
20150302 java8 第一回_ラムダ式(1)
20150302 java8 第一回_ラムダ式(1)
Appresso Engineering Team
Effective Java 輪読会 項目77-78
Effective Java 輪読会 項目77-78
Appresso Engineering Team
Contenu connexe
Tendances
Boostライブラリ一周の旅
Boostライブラリ一周の旅
Akira Takahashi
2011年10月7日
2011年10月7日
nukaemon
Tottoruby 20110903
Tottoruby 20110903
Takashi SAKAGUCHI
みんなのPython勉強会#77 パッケージングしよう
みんなのPython勉強会#77 パッケージングしよう
Atsushi Odagiri
Lithium Labo #1
Lithium Labo #1
Yusuke Ando
Stagefright入門
Stagefright入門
l_b__
しょしんしゃのためのhello world
しょしんしゃのためのhello world
wata2ki
Rails初心者レッスン lesson5 2edition
Rails初心者レッスン lesson5 2edition
Satomi Tsujita
リナックスに置ける様々なリモートエキスプロイト手法 by スクハー・リー
リナックスに置ける様々なリモートエキスプロイト手法 by スクハー・リー
CODE BLUE
Easy caching and logging package using annotation in Python
Easy caching and logging package using annotation in Python
Yasunori Horikoshi
/etc/network/interfaces について
/etc/network/interfaces について
Kazuhiro Nishiyama
MacPort_&_FTP_ver1.0
MacPort_&_FTP_ver1.0
Satoshi Kume
ソフトウェアエンジニアのための「機械学習理論」入門・ハンズオン演習ガイド
ソフトウェアエンジニアのための「機械学習理論」入門・ハンズオン演習ガイド
Etsuji Nakai
10分でわかるFuelPHP @ 2012/05 OSC2012 Nagoya
10分でわかるFuelPHP @ 2012/05 OSC2012 Nagoya
kenjis
APASEC 2013 - ROP/JIT を使わずに DEP/ASLR を回避する手法を見てみた。
APASEC 2013 - ROP/JIT を使わずに DEP/ASLR を回避する手法を見てみた。
Satoshi Mimura
PYTHON PACKAGING (PyFes 2012.03 発表資料)
PYTHON PACKAGING (PyFes 2012.03 発表資料)
Takayuki Shimizukawa
Solaris Container
Solaris Container
Fumikazu FUJIWARA
ParliamentでGeoSPARQL
ParliamentでGeoSPARQL
Teppei Inaba
知って得する標準関数の使い方
知って得する標準関数の使い方
Soudai Sone
FuelPHPをさわってみて
FuelPHPをさわってみて
Sotaro Omura
Tendances
(20)
Boostライブラリ一周の旅
Boostライブラリ一周の旅
2011年10月7日
2011年10月7日
Tottoruby 20110903
Tottoruby 20110903
みんなのPython勉強会#77 パッケージングしよう
みんなのPython勉強会#77 パッケージングしよう
Lithium Labo #1
Lithium Labo #1
Stagefright入門
Stagefright入門
しょしんしゃのためのhello world
しょしんしゃのためのhello world
Rails初心者レッスン lesson5 2edition
Rails初心者レッスン lesson5 2edition
リナックスに置ける様々なリモートエキスプロイト手法 by スクハー・リー
リナックスに置ける様々なリモートエキスプロイト手法 by スクハー・リー
Easy caching and logging package using annotation in Python
Easy caching and logging package using annotation in Python
/etc/network/interfaces について
/etc/network/interfaces について
MacPort_&_FTP_ver1.0
MacPort_&_FTP_ver1.0
ソフトウェアエンジニアのための「機械学習理論」入門・ハンズオン演習ガイド
ソフトウェアエンジニアのための「機械学習理論」入門・ハンズオン演習ガイド
10分でわかるFuelPHP @ 2012/05 OSC2012 Nagoya
10分でわかるFuelPHP @ 2012/05 OSC2012 Nagoya
APASEC 2013 - ROP/JIT を使わずに DEP/ASLR を回避する手法を見てみた。
APASEC 2013 - ROP/JIT を使わずに DEP/ASLR を回避する手法を見てみた。
PYTHON PACKAGING (PyFes 2012.03 発表資料)
PYTHON PACKAGING (PyFes 2012.03 発表資料)
Solaris Container
Solaris Container
ParliamentでGeoSPARQL
ParliamentでGeoSPARQL
知って得する標準関数の使い方
知って得する標準関数の使い方
FuelPHPをさわってみて
FuelPHPをさわってみて
Plus de Appresso Engineering Team
20150302 java8 第一回_ラムダ式(1)
20150302 java8 第一回_ラムダ式(1)
Appresso Engineering Team
Effective Java 輪読会 項目77-78
Effective Java 輪読会 項目77-78
Appresso Engineering Team
Effective Java 輪読会 項目74-75
Effective Java 輪読会 項目74-75
Appresso Engineering Team
マルチスレッド デザインパターン ― Single Threaded Execution
マルチスレッド デザインパターン ― Single Threaded Execution
Appresso Engineering Team
JavaScript 勉強会 ― 変数・演算子・文
JavaScript 勉強会 ― 変数・演算子・文
Appresso Engineering Team
JavaScript 勉強会 ― 型と値
JavaScript 勉強会 ― 型と値
Appresso Engineering Team
Effective Java 輪読会 項目69-70追加
Effective Java 輪読会 項目69-70追加
Appresso Engineering Team
Effective Java 輪読会 項目69-70
Effective Java 輪読会 項目69-70
Appresso Engineering Team
Effective Java 輪読会 項目66-68
Effective Java 輪読会 項目66-68
Appresso Engineering Team
Effective Java 輪読会 項目71-73
Effective Java 輪読会 項目71-73
Appresso Engineering Team
Java Day Tokyo 2014 まとめ (chen)
Java Day Tokyo 2014 まとめ (chen)
Appresso Engineering Team
Effective Java 輪読会 項目63-65
Effective Java 輪読会 項目63-65
Appresso Engineering Team
Effective Java 輪読会 項目60-62
Effective Java 輪読会 項目60-62
Appresso Engineering Team
Effective java 輪読会 項目57-59
Effective java 輪読会 項目57-59
Appresso Engineering Team
Effective Java 輪読会 項目49-52
Effective Java 輪読会 項目49-52
Appresso Engineering Team
Effective Java 輪読会 項目45-48
Effective Java 輪読会 項目45-48
Appresso Engineering Team
Effective Java 輪読会 項目53-56
Effective Java 輪読会 項目53-56
Appresso Engineering Team
Effective Java 輪読会 第7章 項目43-44
Effective Java 輪読会 第7章 項目43-44
Appresso Engineering Team
Effective Java 輪読会 第7章 項目41-42
Effective Java 輪読会 第7章 項目41-42
Appresso Engineering Team
Effective Java 輪読会 第7章 項目38-40
Effective Java 輪読会 第7章 項目38-40
Appresso Engineering Team
Plus de Appresso Engineering Team
(20)
20150302 java8 第一回_ラムダ式(1)
20150302 java8 第一回_ラムダ式(1)
Effective Java 輪読会 項目77-78
Effective Java 輪読会 項目77-78
Effective Java 輪読会 項目74-75
Effective Java 輪読会 項目74-75
マルチスレッド デザインパターン ― Single Threaded Execution
マルチスレッド デザインパターン ― Single Threaded Execution
JavaScript 勉強会 ― 変数・演算子・文
JavaScript 勉強会 ― 変数・演算子・文
JavaScript 勉強会 ― 型と値
JavaScript 勉強会 ― 型と値
Effective Java 輪読会 項目69-70追加
Effective Java 輪読会 項目69-70追加
Effective Java 輪読会 項目69-70
Effective Java 輪読会 項目69-70
Effective Java 輪読会 項目66-68
Effective Java 輪読会 項目66-68
Effective Java 輪読会 項目71-73
Effective Java 輪読会 項目71-73
Java Day Tokyo 2014 まとめ (chen)
Java Day Tokyo 2014 まとめ (chen)
Effective Java 輪読会 項目63-65
Effective Java 輪読会 項目63-65
Effective Java 輪読会 項目60-62
Effective Java 輪読会 項目60-62
Effective java 輪読会 項目57-59
Effective java 輪読会 項目57-59
Effective Java 輪読会 項目49-52
Effective Java 輪読会 項目49-52
Effective Java 輪読会 項目45-48
Effective Java 輪読会 項目45-48
Effective Java 輪読会 項目53-56
Effective Java 輪読会 項目53-56
Effective Java 輪読会 第7章 項目43-44
Effective Java 輪読会 第7章 項目43-44
Effective Java 輪読会 第7章 項目41-42
Effective Java 輪読会 第7章 項目41-42
Effective Java 輪読会 第7章 項目38-40
Effective Java 輪読会 第7章 項目38-40
Nio2
1.
nio2(JSR203)勉強会 大崎 瑶
2.
nio2 • nio(JSR51)の積み残し • 非同期I/O •
マルチキャストサポート • ファイルシステムインタフェース
3.
ファイルシステムインタフェース
4.
java.nio.file.FileSystem FileSystem fileSystem =
FileSystems.getDefault(); Path path = fileSystem.getPath(“foo.txt”); FileSystemの取得 Pathの取得 List<FileSystemProvider> providers = FileSystemProvider.installedProviders(); FileSystemはFileSystemProviderによって提供される。 一覧は、installedProviders()で取得できます。
5.
ディレクトリ DirectoryStream<Path> directory = Files.newDirectoryStream(path); for
(Path childPath: directory) { ... } if (Files.isDirectory(path, LinkOption.NOFOLLOW_LINKS)) { ... } ディレクトリの情報はDirectoryStreamで取得できます。 DirectoryStreamはIterableをのサブインタフェース Pathがディレクトリかどうかを調べるにはFilesユーティリティを使います。
6.
入出力 Path path =
...; InputStream iStream = Files.newInputStream(path); OutputStream oStream1 = Files.newOutputStream(path); OutputStream oStream2 = Files.newOutputStream(path, StandardOpenOption.APPEND); StandardOpenOption.CREATTE StandardOpenOption.CREATE_NEW StandardOpenOption.READ StandardOpenOption.WRITE StandardOpenOption.APPEND
7.
入出力 Path path =
...; BufferedReader reader = Files.newBufferedReader(path, Charset.defaultCharset()); BufferedWriter writer1 = Files.newBufferedWriter(path, Charset.defaultCharset()); BufferedWriter writer2 = Files.newBufferedWriter(path, Charset.defaultCharset(), StandardOpenOption.APPEND); FileChannel や SeekableByteChannel といったファイルチャネルを取得することもで きます。
8.
ファイル・ディレクトリの作成 Path path =
fileSystem.getPath(“filename”); Files.createFile(path); path = fileSystem.getPath(“dirname”); Files.createDirectory(path); path = fileSystem.getPath(“parentdir/childdir”); Files.createDirectory(path);
9.
ファイル・ディレクトリのコピー Path foo =
fileSystem.getPath("foo.txt"); Path bar = fileSystem.getPath("bar.txt"); Path baz = fileSystem.getPath("baz.txt"); // ファイルのコピー Files.copy(foo, bar); // ファイルのコピー(上書きコピー) Files.copy(foo, bar, StandardCopyOption.REPLACE_EXISTING); // ファイルのコピー(属性を含む) Files.copy(foo, baz, StandardCopyOption.COPY_ATTRIBUTES); StandardCopyOption.REPLACE_EXISTING StandardCopyOption.COPY_ATTRIBUTES StandardCopyOption.ATOMIC_MOVE
10.
メタデータ • Filesクラスのユーティリティメソッド – ex.
Files.setOwner(),Files.getLastModifiedTime() • Files.getAttribute(),Files.setAttribute() • FileAttributeViewインタフェース
11.
Filesクラスのユーティリティメソッドを 使ったメタデータの取得設定 FileTime lastModified =
File.getFileLastModifiedTime(path); UserPricipal owner = File.getOwner(path); Set<PosixFilePermission> permission = File.getPosixFilePermission(path); File.setFileLastModifiedTime(path, lastModified); File.setOwner(path, owner); File.setPosixFilePermission(path, permission); UserPrincipalLookupService service = FileSystems.getDefault().getUserPrincipalLookupService(); UserPrincipal user = service.lookupPrincipalByName("ap091011"); UserPrincipalはUserPrincipalLookupServiceから取得することが出来る。
12.
Files.getAttribute() Files.setAttribute() FileTime lastModified = (FileTime)
File.getAttribute(path, “lastModifiedTime”); FileTime creationTime = (FileTime) File.getAttribute(path, “creationTime”); UserPrincipal owner = File.getAttribute(path, “acl:onwer”); File.setAttribute(path, “lastModifiedTime“, lastModified); File.setAttribute(path, “creationTime”, creationTime); File.setAttribute(path, “acl:owner”, owner);
13.
ファイル・ディレクトリの移動・削除 // ファイルの移動 Files.move(foo, bar); //
ディレクトリの移動 Files.move(dirFoo, dirBar); // ファイルの削除 Files.delete(bar); // ファイルが存在していなくても、例外をスローしない Files.deleteIfExists(foo2); ファイルの移動とディレクトの移動は同じメソッド。 同じディレクトリ内のファイル(ディレクトリ)の移動はリネーム ファイルの移動とディレクトの移動は同じメソッド。 ディレクトリの場合ディレクトリ内にファイルがあると例外がスローされる
14.
FileAttributeViewインタフェース BasicFileAttributeView attrView = Files.getFileAttributeView(path,
BasicFileAttributeView.class); FileTime lastModified = attrView .readAttributes().lastModifiedTime(); FileTime creationTime = attrView .readAttributes().creationTime(); attrView.setTimes(lastModified, lastAccess, creationTime); AclFileAttributeView acl = Files.getFileAttributeView(path, AclFileAttributeView.class); UserPrincipal owner = acl.getOwner();
15.
java.nio.file.FileVisitor • preVisitDirectory() – ディレクトリに入る時 •
postVisitDirectory() – ディレクトリから出る時 • visitFile() – ファイルの訪問時 • visitFileFailed() – ファイルの訪問に失敗した時
16.
java.nio.file.WatchService Path dest =
fileSystem.getPath("dest"); WatchService watcher = fileSystem.newWatchService(); dest.register(watcher, StandardWatchEventKinds.ENTRY_CREATE, StandardWatchEventKinds.ENTRY_DELETE, StandardWatchEventKinds.ENTRY_MODIFY); Pathに対してWatchServiceを登録します。
17.
java.nio.file.WatchService while (true) { WatchKey
key = null; try { key = watcher.take(); } catch (InterruptedException ex) { break; } } ざんねんながら、自分でポーリングしなくてはなりません。 ただし、同期化してくれるので便利といえば、便利です。 書き込み途中で何かしようとしちゃう問題とか・・・
18.
非同期I/O • AsynchronousSocketChannel • AsynchronousServerSocketChannel •
AsynchronousFileChannel • AsynchronousDatagramChannel SocketChannel, ServerSocketChannel, FileChannel, DatagramChannelの非同期版 それぞれのサブクラスにはなっていません
19.
非同期I/O • Future<V>インタフェースを使う方法 • java.nio.channels.CompletionHandlerを使う方 法 非同期を実現するのに2つの方法がある。
20.
AsynchronousSocketChannel AsynchronousSocketChannel client = AsynchronousSocketChannel.open(); client.connect(server.getLocalAddress()).get(); Future<AsynchronousSocketChannel>
acceptFuture = server.accept(); AsynchronousSocketChannel ch = acceptFuture.get(); クライアントソケットの作成 サーバー側でアクセプトしたソケット
21.
AsynchronousServerSocketChannel (Future) Future<AsynchronousSocketChannel> acceptFuture =
server.accept(); 接続を受け付けるまでブロックされます AsynchronousSocketChannel worker = future.get(); acept()はブロックされません。
22.
AsynchronousServerSocketChannel (CompletionHandler) acept()はブロックされません。 server.accept(null, new CompletionHandler<AsynchronousSocketChannel,
Void>() { public void completed(AsynchronousSocketChannel ch, Void att) { ... } public void failed(Throwable exc, Void att) { ... } )}
23.
AsynchronousFileChannel AsynchronousFileChannel fileChannel = AsynchronousFileChannel.open(Paths.get("myfile")); Future<Integer>
readFuture = fileChannel.read(dst, pos); ByteBuffer buffer = ByteBuffer.allocate(1024); int pos = 0; while (true) { buffer.clear(); Future<Integer> future = channel.read(buffer, pos); int len = future.get(); if (len < 0) { break; } pos += len; }
Télécharger maintenant