SlideShare une entreprise Scribd logo
1  sur  21
Télécharger pour lire hors ligne
もっと New I/O。



   Java in the Box
   櫻庭 祐一
JSR 51 New I/O APIs

Buffer/Direct Buffer

 Channel

ノンブロッキング I/O

   Charset


 積み残しあり!
                       Mark Reinhold
JSR 51 New I/O APIs
  An API for scalable I/O operations
   Buffer/Directsockets, in the form of
  on both files and Buffer
  either asynchronous requests
   Channel
  or polling

Aノンブロッキングinterface that supports bulk access
 new filesystem I/O
to file attributes (including MIME content types),
escape Charset
         to filesystem-specific APIs,
and a service-provider interface for pluggable filesystem

   積み残しあり!
implementations.



                                             Mark Reinhold
JSR 203 More New I/O APIs

  非同期 I/O

 ファイルシステムインタフェース

  SocketChannel
     のマルチキャスト


                       Alan Bateman
当初 J2SE5.0 向け
なぜファイルシステム ?

 メタデータ
          シンボリックリンク
ファイルの監視
なぜファイルシステム ?
               テ ム
               シ ス
           イ ル
       フ ァ     な ら
     い
 メタデータ
   し       ー ス
 新       ェ
        フ シンボリックリンク
    ン タ     !!
  イ     解 決
    べ て
ファイルの監視
  す
<<factory>>
                      FileSystem
FileSystems



                                         <<interface>>
   Files                   Path
                                         AttributeView




           <<interface>>          <<interface>>
             FileVisitor          WatchService
生成
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();
生成
// シンボリックリンクのターゲット
File file
FileSystem=fileSystem = FileSystems.getDefault();
            ...;
Path target = fileSystem.getPath("realfile.txt");
// file.txt の生成
   シンボリックリンクするファイル
   File から Path
Path path1==file.toPath();
     link
     path   fileSystem.getPath("link.txt"); null);
             fileSystem.getPath("file.txt",

// foo/bar/file.txt の生成
   シンボリックリンクの作成
   Path から File
Files.createSymbolicLink(link, target);
File file2
Path path2 = fileSystem.getPath("foo", "bar", "file.txt");
             path.toFile();
操作 : Files クラス
// ファイルのコピー
String source = ...;
Path source = fileSystem.getPath(source);

String destination = ...;
Path destination = fileSystem.getPath(destination);

Files.copy(source, destination);
操作 : Files クラス
Path source = ...; Path dest = ...;

// 移動
Files.move(source, dest);

// 削除
Files.delete(dest);
Files.deleteIfExists(dest);
操作 : 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);
操作 : Files クラス
Path source = ...;
// ファイルのコピーPath dest = ...;
     path = ...;
// ストリームなどの取得
String source = ...;
   簡易入出力
byte[]
BufferedReader reader = Files.newBufferedReader(path,
// 移動bytes
Path source ==fileSystem.getPath(source);
               Files.readAllBytes(path);
List<String> lines = Files.readAllLines(path,
Files.move(source, dest);       Charset.defaultCharset());
BufferedWriter writer = Files.newBufferedWriter(path,
String destination = ...;    Charset.defaultCharset());
// 削除
Path destination = fileSystem.getPath(destination);
                                Charset.defaultCharset());
Files.write(path, bytes);
InputStream iStream
Files.delete(dest); = Files.newInputStream(path);
Files.write(path, destination);
OutputStream oStream = Files.newOutputStream(path);
Files.deleteIfExists(dest);
Files.copy(source,lines, Charset.defaultCharset());
ByteChannel channel = Files.newByteChannel(path);
メタデータ
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();
ファイルビジター                     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;
    }
});
ファイルの監視
                           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();
}
非同期 I/O
Selector
           AsynchronousChannel
             Future
              CompletionHandler
マルチキャスト
      DatagramChannel
JSR 51 の積み残し
 非同期 I/O
ファイルシステムインタフェース
  マルチキャスト


       JSR 203 More New I/O
ファイルシステムインタフェース
    メタデータ      ファイルビジター
        ファイルの監視
もっと New I/O。




   Java in the Box
   櫻庭 祐一

Contenu connexe

Similaire à もっと New I/O。

File API: Writer & Directories and System
File API: Writer & Directories and SystemFile API: Writer & Directories and System
File API: Writer & Directories and SystemTaku AMANO
 
詳解UNIXプログラミング 第4章 ファイルとディレクトリ
詳解UNIXプログラミング 第4章 ファイルとディレクトリ詳解UNIXプログラミング 第4章 ファイルとディレクトリ
詳解UNIXプログラミング 第4章 ファイルとディレクトリTakaya Kotohata
 
2019-10-18 JXUG Xamarin.Essentials - #3 File System Helpers
2019-10-18 JXUG Xamarin.Essentials - #3 File System Helpers2019-10-18 JXUG Xamarin.Essentials - #3 File System Helpers
2019-10-18 JXUG Xamarin.Essentials - #3 File System HelpersTakeshi Fujimoto
 
Javaセキュアコーディングセミナー東京第3回講義
Javaセキュアコーディングセミナー東京第3回講義Javaセキュアコーディングセミナー東京第3回講義
Javaセキュアコーディングセミナー東京第3回講義JPCERT Coordination Center
 
XML と PHP のイケナイ関係 (セキュリティ的な意味で) -Introduction of XXE attack and XML Bomb with...
XML と PHP のイケナイ関係 (セキュリティ的な意味で) -Introduction of XXE attack and XML Bomb with...XML と PHP のイケナイ関係 (セキュリティ的な意味で) -Introduction of XXE attack and XML Bomb with...
XML と PHP のイケナイ関係 (セキュリティ的な意味で) -Introduction of XXE attack and XML Bomb with...Kousuke Ebihara
 
Data Factory V2 新機能徹底活用入門
Data Factory V2 新機能徹底活用入門Data Factory V2 新機能徹底活用入門
Data Factory V2 新機能徹底活用入門Keisuke Fujikawa
 
Spring Framework ふりかえりと4.3新機能
Spring Framework ふりかえりと4.3新機能Spring Framework ふりかえりと4.3新機能
Spring Framework ふりかえりと4.3新機能kimulla
 
Couchbase MeetUP Tokyo - #11 Omoidenote
Couchbase MeetUP Tokyo - #11 OmoidenoteCouchbase MeetUP Tokyo - #11 Omoidenote
Couchbase MeetUP Tokyo - #11 Omoidenotekitsugi
 
yidev第七回勉強会:「Assets Library手習い」発表資料
yidev第七回勉強会:「Assets Library手習い」発表資料yidev第七回勉強会:「Assets Library手習い」発表資料
yidev第七回勉強会:「Assets Library手習い」発表資料Hirohito Kato
 
明日から使える Java SE 7
明日から使える Java SE 7明日から使える Java SE 7
明日から使える Java SE 7Yuichi Sakuraba
 
ひのきのぼうだけで全クリ目指す
ひのきのぼうだけで全クリ目指すひのきのぼうだけで全クリ目指す
ひのきのぼうだけで全クリ目指すAromaBlack
 
初めての Data api
初めての Data api初めての Data api
初めての Data apiYuji Takayama
 
アップグレードセミナー
アップグレードセミナーアップグレードセミナー
アップグレードセミナーkmiyako
 
NXT開発環境(ETロボコン向けTOPPERS活用セミナー5)
NXT開発環境(ETロボコン向けTOPPERS活用セミナー5)NXT開発環境(ETロボコン向けTOPPERS活用セミナー5)
NXT開発環境(ETロボコン向けTOPPERS活用セミナー5)Takuya Azumi
 
使いこなせて安全なLinuxを目指して
使いこなせて安全なLinuxを目指して使いこなせて安全なLinuxを目指して
使いこなせて安全なLinuxを目指してToshiharu Harada, Ph.D
 

Similaire à もっと New I/O。 (20)

File API: Writer & Directories and System
File API: Writer & Directories and SystemFile API: Writer & Directories and System
File API: Writer & Directories and System
 
詳解UNIXプログラミング 第4章 ファイルとディレクトリ
詳解UNIXプログラミング 第4章 ファイルとディレクトリ詳解UNIXプログラミング 第4章 ファイルとディレクトリ
詳解UNIXプログラミング 第4章 ファイルとディレクトリ
 
2019-10-18 JXUG Xamarin.Essentials - #3 File System Helpers
2019-10-18 JXUG Xamarin.Essentials - #3 File System Helpers2019-10-18 JXUG Xamarin.Essentials - #3 File System Helpers
2019-10-18 JXUG Xamarin.Essentials - #3 File System Helpers
 
Javaセキュアコーディングセミナー東京第3回講義
Javaセキュアコーディングセミナー東京第3回講義Javaセキュアコーディングセミナー東京第3回講義
Javaセキュアコーディングセミナー東京第3回講義
 
20061122
2006112220061122
20061122
 
XML と PHP のイケナイ関係 (セキュリティ的な意味で) -Introduction of XXE attack and XML Bomb with...
XML と PHP のイケナイ関係 (セキュリティ的な意味で) -Introduction of XXE attack and XML Bomb with...XML と PHP のイケナイ関係 (セキュリティ的な意味で) -Introduction of XXE attack and XML Bomb with...
XML と PHP のイケナイ関係 (セキュリティ的な意味で) -Introduction of XXE attack and XML Bomb with...
 
Data Factory V2 新機能徹底活用入門
Data Factory V2 新機能徹底活用入門Data Factory V2 新機能徹底活用入門
Data Factory V2 新機能徹底活用入門
 
BBBBB
BBBBBBBBBB
BBBBB
 
1MB
1MB1MB
1MB
 
Spring Framework ふりかえりと4.3新機能
Spring Framework ふりかえりと4.3新機能Spring Framework ふりかえりと4.3新機能
Spring Framework ふりかえりと4.3新機能
 
Couchbase MeetUP Tokyo - #11 Omoidenote
Couchbase MeetUP Tokyo - #11 OmoidenoteCouchbase MeetUP Tokyo - #11 Omoidenote
Couchbase MeetUP Tokyo - #11 Omoidenote
 
yidev第七回勉強会:「Assets Library手習い」発表資料
yidev第七回勉強会:「Assets Library手習い」発表資料yidev第七回勉強会:「Assets Library手習い」発表資料
yidev第七回勉強会:「Assets Library手習い」発表資料
 
明日から使える Java SE 7
明日から使える Java SE 7明日から使える Java SE 7
明日から使える Java SE 7
 
ひのきのぼうだけで全クリ目指す
ひのきのぼうだけで全クリ目指すひのきのぼうだけで全クリ目指す
ひのきのぼうだけで全クリ目指す
 
初めての Data api
初めての Data api初めての Data api
初めての Data api
 
アップグレードセミナー
アップグレードセミナーアップグレードセミナー
アップグレードセミナー
 
20061125
2006112520061125
20061125
 
NXT開発環境(ETロボコン向けTOPPERS活用セミナー5)
NXT開発環境(ETロボコン向けTOPPERS活用セミナー5)NXT開発環境(ETロボコン向けTOPPERS活用セミナー5)
NXT開発環境(ETロボコン向けTOPPERS活用セミナー5)
 
後期02
後期02後期02
後期02
 
使いこなせて安全なLinuxを目指して
使いこなせて安全なLinuxを目指して使いこなせて安全なLinuxを目指して
使いこなせて安全なLinuxを目指して
 

Plus de Yuichi Sakuraba

Vector API - Javaによるベクターコンピューティング
Vector API - JavaによるベクターコンピューティングVector API - Javaによるベクターコンピューティング
Vector API - JavaによるベクターコンピューティングYuichi Sakuraba
 
Oracle Code One - Java KeynoteとJava SE
Oracle Code One - Java KeynoteとJava SEOracle Code One - Java KeynoteとJava SE
Oracle Code One - Java KeynoteとJava SEYuichi Sakuraba
 
Project Loom + Project Panama
Project Loom + Project PanamaProject Loom + Project Panama
Project Loom + Project PanamaYuichi Sakuraba
 
Project Loom - 限定継続と軽量スレッド -
Project Loom - 限定継続と軽量スレッド - Project Loom - 限定継続と軽量スレッド -
Project Loom - 限定継続と軽量スレッド - Yuichi Sakuraba
 
Oracle Code One 報告会 Java SE Update
Oracle Code One 報告会 Java SE UpdateOracle Code One 報告会 Java SE Update
Oracle Code One 報告会 Java SE UpdateYuichi Sakuraba
 
今こそStream API入門
今こそStream API入門今こそStream API入門
今こそStream API入門Yuichi Sakuraba
 
Oracle Code One 報告会 Java SE Update
Oracle Code One 報告会 Java SE UpdateOracle Code One 報告会 Java SE Update
Oracle Code One 報告会 Java SE UpdateYuichi Sakuraba
 
Learn Language 2018 Java Language Update
Learn Language 2018 Java Language Update Learn Language 2018 Java Language Update
Learn Language 2018 Java Language Update Yuichi Sakuraba
 
Dockerに向けて、Javaもダイエット
Dockerに向けて、JavaもダイエットDockerに向けて、Javaもダイエット
Dockerに向けて、JavaもダイエットYuichi Sakuraba
 
Migration Guide to Java SE 10, and also Java SE 11
Migration Guide to Java SE 10, and also Java SE 11Migration Guide to Java SE 10, and also Java SE 11
Migration Guide to Java SE 10, and also Java SE 11Yuichi Sakuraba
 
琥珀色のJava - Project Amber -
琥珀色のJava - Project Amber -琥珀色のJava - Project Amber -
琥珀色のJava - Project Amber -Yuichi Sakuraba
 
Moving to Module: Issues & Solutions
Moving to Module: Issues & SolutionsMoving to Module: Issues & Solutions
Moving to Module: Issues & SolutionsYuichi Sakuraba
 
モジュール移行の課題と対策
モジュール移行の課題と対策モジュール移行の課題と対策
モジュール移行の課題と対策Yuichi Sakuraba
 
Project Jigsawと、ちょっとだけVector API
Project Jigsawと、ちょっとだけVector APIProject Jigsawと、ちょっとだけVector API
Project Jigsawと、ちょっとだけVector APIYuichi Sakuraba
 
Java SEの現在、過去 そして未来
Java SEの現在、過去 そして未来Java SEの現在、過去 そして未来
Java SEの現在、過去 そして未来Yuichi Sakuraba
 
Introduction of Project Jigsaw
Introduction of Project JigsawIntroduction of Project Jigsaw
Introduction of Project JigsawYuichi Sakuraba
 
Encouragement of Java SE 9
Encouragement of Java SE 9Encouragement of Java SE 9
Encouragement of Java SE 9Yuichi Sakuraba
 

Plus de Yuichi Sakuraba (20)

Vector API - Javaによるベクターコンピューティング
Vector API - JavaによるベクターコンピューティングVector API - Javaによるベクターコンピューティング
Vector API - Javaによるベクターコンピューティング
 
Oracle Code One - Java KeynoteとJava SE
Oracle Code One - Java KeynoteとJava SEOracle Code One - Java KeynoteとJava SE
Oracle Code One - Java KeynoteとJava SE
 
Project Loom + Project Panama
Project Loom + Project PanamaProject Loom + Project Panama
Project Loom + Project Panama
 
Project Loom - 限定継続と軽量スレッド -
Project Loom - 限定継続と軽量スレッド - Project Loom - 限定継続と軽量スレッド -
Project Loom - 限定継続と軽量スレッド -
 
Oracle Code One 報告会 Java SE Update
Oracle Code One 報告会 Java SE UpdateOracle Code One 報告会 Java SE Update
Oracle Code One 報告会 Java SE Update
 
今こそStream API入門
今こそStream API入門今こそStream API入門
今こそStream API入門
 
Oracle Code One 報告会 Java SE Update
Oracle Code One 報告会 Java SE UpdateOracle Code One 報告会 Java SE Update
Oracle Code One 報告会 Java SE Update
 
Learn Language 2018 Java Language Update
Learn Language 2018 Java Language Update Learn Language 2018 Java Language Update
Learn Language 2018 Java Language Update
 
Dockerに向けて、Javaもダイエット
Dockerに向けて、JavaもダイエットDockerに向けて、Javaもダイエット
Dockerに向けて、Javaもダイエット
 
What's New in Java
What's New in JavaWhat's New in Java
What's New in Java
 
Migration Guide to Java SE 10, and also Java SE 11
Migration Guide to Java SE 10, and also Java SE 11Migration Guide to Java SE 10, and also Java SE 11
Migration Guide to Java SE 10, and also Java SE 11
 
琥珀色のJava - Project Amber -
琥珀色のJava - Project Amber -琥珀色のJava - Project Amber -
琥珀色のJava - Project Amber -
 
Moving to Module: Issues & Solutions
Moving to Module: Issues & SolutionsMoving to Module: Issues & Solutions
Moving to Module: Issues & Solutions
 
モジュール移行の課題と対策
モジュール移行の課題と対策モジュール移行の課題と対策
モジュール移行の課題と対策
 
Project Jigsawと、ちょっとだけVector API
Project Jigsawと、ちょっとだけVector APIProject Jigsawと、ちょっとだけVector API
Project Jigsawと、ちょっとだけVector API
 
Java SE 9の全貌
Java SE 9の全貌Java SE 9の全貌
Java SE 9の全貌
 
Java SEの現在、過去 そして未来
Java SEの現在、過去 そして未来Java SEの現在、過去 そして未来
Java SEの現在、過去 そして未来
 
Java SE 9 のススメ
Java SE 9 のススメJava SE 9 のススメ
Java SE 9 のススメ
 
Introduction of Project Jigsaw
Introduction of Project JigsawIntroduction of Project Jigsaw
Introduction of Project Jigsaw
 
Encouragement of Java SE 9
Encouragement of Java SE 9Encouragement of Java SE 9
Encouragement of Java SE 9
 

Dernier

Open Source UN-Conference 2024 Kawagoe - 独自OS「DaisyOS GB」の紹介
Open Source UN-Conference 2024 Kawagoe - 独自OS「DaisyOS GB」の紹介Open Source UN-Conference 2024 Kawagoe - 独自OS「DaisyOS GB」の紹介
Open Source UN-Conference 2024 Kawagoe - 独自OS「DaisyOS GB」の紹介Yuma Ohgami
 
スマートフォンを用いた新生児あやし動作の教示システム
スマートフォンを用いた新生児あやし動作の教示システムスマートフォンを用いた新生児あやし動作の教示システム
スマートフォンを用いた新生児あやし動作の教示システムsugiuralab
 
[DevOpsDays Tokyo 2024] 〜デジタルとアナログのはざまに〜 スマートビルディング爆速開発を支える 自動化テスト戦略
[DevOpsDays Tokyo 2024] 〜デジタルとアナログのはざまに〜 スマートビルディング爆速開発を支える 自動化テスト戦略[DevOpsDays Tokyo 2024] 〜デジタルとアナログのはざまに〜 スマートビルディング爆速開発を支える 自動化テスト戦略
[DevOpsDays Tokyo 2024] 〜デジタルとアナログのはざまに〜 スマートビルディング爆速開発を支える 自動化テスト戦略Ryo Sasaki
 
論文紹介:Automated Classification of Model Errors on ImageNet
論文紹介:Automated Classification of Model Errors on ImageNet論文紹介:Automated Classification of Model Errors on ImageNet
論文紹介:Automated Classification of Model Errors on ImageNetToru Tamaki
 
【早稲田AI研究会 講義資料】3DスキャンとTextTo3Dのツールを知ろう!(Vol.1)
【早稲田AI研究会 講義資料】3DスキャンとTextTo3Dのツールを知ろう!(Vol.1)【早稲田AI研究会 講義資料】3DスキャンとTextTo3Dのツールを知ろう!(Vol.1)
【早稲田AI研究会 講義資料】3DスキャンとTextTo3Dのツールを知ろう!(Vol.1)Hiroki Ichikura
 
TSAL operation mechanism and circuit diagram.pdf
TSAL operation mechanism and circuit diagram.pdfTSAL operation mechanism and circuit diagram.pdf
TSAL operation mechanism and circuit diagram.pdftaisei2219
 
論文紹介:Content-Aware Token Sharing for Efficient Semantic Segmentation With Vis...
論文紹介:Content-Aware Token Sharing for Efficient Semantic Segmentation With Vis...論文紹介:Content-Aware Token Sharing for Efficient Semantic Segmentation With Vis...
論文紹介:Content-Aware Token Sharing for Efficient Semantic Segmentation With Vis...Toru Tamaki
 
論文紹介:Semantic segmentation using Vision Transformers: A survey
論文紹介:Semantic segmentation using Vision Transformers: A survey論文紹介:Semantic segmentation using Vision Transformers: A survey
論文紹介:Semantic segmentation using Vision Transformers: A surveyToru Tamaki
 
SOPを理解する 2024/04/19 の勉強会で発表されたものです
SOPを理解する       2024/04/19 の勉強会で発表されたものですSOPを理解する       2024/04/19 の勉強会で発表されたものです
SOPを理解する 2024/04/19 の勉強会で発表されたものですiPride Co., Ltd.
 
Postman LT Fukuoka_Quick Prototype_By Daniel
Postman LT Fukuoka_Quick Prototype_By DanielPostman LT Fukuoka_Quick Prototype_By Daniel
Postman LT Fukuoka_Quick Prototype_By Danieldanielhu54
 

Dernier (10)

Open Source UN-Conference 2024 Kawagoe - 独自OS「DaisyOS GB」の紹介
Open Source UN-Conference 2024 Kawagoe - 独自OS「DaisyOS GB」の紹介Open Source UN-Conference 2024 Kawagoe - 独自OS「DaisyOS GB」の紹介
Open Source UN-Conference 2024 Kawagoe - 独自OS「DaisyOS GB」の紹介
 
スマートフォンを用いた新生児あやし動作の教示システム
スマートフォンを用いた新生児あやし動作の教示システムスマートフォンを用いた新生児あやし動作の教示システム
スマートフォンを用いた新生児あやし動作の教示システム
 
[DevOpsDays Tokyo 2024] 〜デジタルとアナログのはざまに〜 スマートビルディング爆速開発を支える 自動化テスト戦略
[DevOpsDays Tokyo 2024] 〜デジタルとアナログのはざまに〜 スマートビルディング爆速開発を支える 自動化テスト戦略[DevOpsDays Tokyo 2024] 〜デジタルとアナログのはざまに〜 スマートビルディング爆速開発を支える 自動化テスト戦略
[DevOpsDays Tokyo 2024] 〜デジタルとアナログのはざまに〜 スマートビルディング爆速開発を支える 自動化テスト戦略
 
論文紹介:Automated Classification of Model Errors on ImageNet
論文紹介:Automated Classification of Model Errors on ImageNet論文紹介:Automated Classification of Model Errors on ImageNet
論文紹介:Automated Classification of Model Errors on ImageNet
 
【早稲田AI研究会 講義資料】3DスキャンとTextTo3Dのツールを知ろう!(Vol.1)
【早稲田AI研究会 講義資料】3DスキャンとTextTo3Dのツールを知ろう!(Vol.1)【早稲田AI研究会 講義資料】3DスキャンとTextTo3Dのツールを知ろう!(Vol.1)
【早稲田AI研究会 講義資料】3DスキャンとTextTo3Dのツールを知ろう!(Vol.1)
 
TSAL operation mechanism and circuit diagram.pdf
TSAL operation mechanism and circuit diagram.pdfTSAL operation mechanism and circuit diagram.pdf
TSAL operation mechanism and circuit diagram.pdf
 
論文紹介:Content-Aware Token Sharing for Efficient Semantic Segmentation With Vis...
論文紹介:Content-Aware Token Sharing for Efficient Semantic Segmentation With Vis...論文紹介:Content-Aware Token Sharing for Efficient Semantic Segmentation With Vis...
論文紹介:Content-Aware Token Sharing for Efficient Semantic Segmentation With Vis...
 
論文紹介:Semantic segmentation using Vision Transformers: A survey
論文紹介:Semantic segmentation using Vision Transformers: A survey論文紹介:Semantic segmentation using Vision Transformers: A survey
論文紹介:Semantic segmentation using Vision Transformers: A survey
 
SOPを理解する 2024/04/19 の勉強会で発表されたものです
SOPを理解する       2024/04/19 の勉強会で発表されたものですSOPを理解する       2024/04/19 の勉強会で発表されたものです
SOPを理解する 2024/04/19 の勉強会で発表されたものです
 
Postman LT Fukuoka_Quick Prototype_By Daniel
Postman LT Fukuoka_Quick Prototype_By DanielPostman LT Fukuoka_Quick Prototype_By Daniel
Postman LT Fukuoka_Quick Prototype_By Daniel
 

もっと New I/O。

  • 1. もっと New I/O。 Java in the Box 櫻庭 祐一
  • 2. JSR 51 New I/O APIs Buffer/Direct Buffer Channel ノンブロッキング I/O Charset 積み残しあり! Mark Reinhold
  • 3. JSR 51 New I/O APIs An API for scalable I/O operations Buffer/Directsockets, in the form of on both files and Buffer either asynchronous requests Channel or polling Aノンブロッキングinterface that supports bulk access new filesystem I/O to file attributes (including MIME content types), escape Charset to filesystem-specific APIs, and a service-provider interface for pluggable filesystem 積み残しあり! implementations. Mark Reinhold
  • 4. JSR 203 More New I/O APIs 非同期 I/O ファイルシステムインタフェース SocketChannel のマルチキャスト Alan Bateman 当初 J2SE5.0 向け
  • 5. なぜファイルシステム ? メタデータ シンボリックリンク ファイルの監視
  • 6. なぜファイルシステム ? テ ム シ ス イ ル フ ァ な ら い メタデータ し ー ス 新 ェ フ シンボリックリンク ン タ !! イ 解 決 べ て ファイルの監視 す
  • 7. <<factory>> FileSystem FileSystems <<interface>> Files Path AttributeView <<interface>> <<interface>> FileVisitor WatchService
  • 8. 生成 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");
  • 9. 生成 File file = ...; // File から Path Path path = file.toPath(); // Path から File File file2 = path.toFile();
  • 10. 生成 // シンボリックリンクのターゲット File file FileSystem=fileSystem = FileSystems.getDefault(); ...; Path target = fileSystem.getPath("realfile.txt"); // file.txt の生成 シンボリックリンクするファイル File から Path Path path1==file.toPath(); link path fileSystem.getPath("link.txt"); null); fileSystem.getPath("file.txt", // foo/bar/file.txt の生成 シンボリックリンクの作成 Path から File Files.createSymbolicLink(link, target); File file2 Path path2 = fileSystem.getPath("foo", "bar", "file.txt"); path.toFile();
  • 11. 操作 : Files クラス // ファイルのコピー String source = ...; Path source = fileSystem.getPath(source); String destination = ...; Path destination = fileSystem.getPath(destination); Files.copy(source, destination);
  • 12. 操作 : Files クラス Path source = ...; Path dest = ...; // 移動 Files.move(source, dest); // 削除 Files.delete(dest); Files.deleteIfExists(dest);
  • 13. 操作 : 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);
  • 14. 操作 : Files クラス Path source = ...; // ファイルのコピーPath dest = ...; path = ...; // ストリームなどの取得 String source = ...; 簡易入出力 byte[] BufferedReader reader = Files.newBufferedReader(path, // 移動bytes Path source ==fileSystem.getPath(source); Files.readAllBytes(path); List<String> lines = Files.readAllLines(path, Files.move(source, dest); Charset.defaultCharset()); BufferedWriter writer = Files.newBufferedWriter(path, String destination = ...; Charset.defaultCharset()); // 削除 Path destination = fileSystem.getPath(destination); Charset.defaultCharset()); Files.write(path, bytes); InputStream iStream Files.delete(dest); = Files.newInputStream(path); Files.write(path, destination); OutputStream oStream = Files.newOutputStream(path); Files.deleteIfExists(dest); Files.copy(source,lines, Charset.defaultCharset()); ByteChannel channel = Files.newByteChannel(path);
  • 15. メタデータ 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();
  • 16. メタデータ 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();
  • 17. ファイルビジター 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; } });
  • 18. ファイルの監視 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(); }
  • 19. 非同期 I/O Selector AsynchronousChannel Future CompletionHandler マルチキャスト DatagramChannel
  • 20. JSR 51 の積み残し 非同期 I/O ファイルシステムインタフェース マルチキャスト JSR 203 More New I/O ファイルシステムインタフェース メタデータ ファイルビジター ファイルの監視
  • 21. もっと New I/O。 Java in the Box 櫻庭 祐一