?.?.?. ???????? ?.?. (email: egrinkrug@hse.ru) - PowerPoint PPT Presentation

About This Presentation
Title:

?.?.?. ???????? ?.?. (email: egrinkrug@hse.ru)

Description:

... ( ?) - ( java.nio) java.nio JDK 1.4 ... – PowerPoint PPT presentation

Number of Views:108
Avg rating:3.0/5.0
Slides: 20
Provided by: hse96
Category:
Tags: egrinkrug | email | hse | java

less

Transcript and Presenter's Notes

Title: ?.?.?. ???????? ?.?. (email: egrinkrug@hse.ru)


1
????????-??????????????? ?????? ?
????????????????
?????? 14 ????/????? (???????????)
?.?.?. ???????? ?.?. (email egrinkrug_at_hse.ru)
2
????????? Serializable
  • ????????? java.io.Serializable
  • ?? ????? ??????? (?????? ?????????)
  • ?? ???????? ??????????? ??? ??????????? ???????
    (?? ????? ?????????? default-????????????
    ??????????????? ???????????? ??? ???? ?????????
    ??????? ??? ????????????/?????????????? ????? ??
    ?????????????? (!))
  • ????????? ???????????????? ???????????? /
    ?????????????? ? ?????????????? ObjectOutputStrem
    / ObjectInputStream, ??????? ????? ????????????
    ????????????? ????? ??????????? ?????????
    ???????
  • private void writeObject(java.io.ObjectOutputStrea
    m out) throws IOException
  • private void readObject(java.io.ObjectInputStream
    in) throws IOException, ClassNotFoundException
  • ? ???? ???? ??????? ????? ????????????,
    ??????????????, ????????
  • out.defaultWriteObject()
  • in.defaultReadObject() // ????? ???????
    ??????????? ????????? ?????? / ??????.

3
????????? Externalizable
  • ???? ????? ?? ?????????? ?? ???????? ????????????
    (Serizlizable), ?? ????? ?????????? ????
    ?????????? ???????? ?????? ? ?????? ????????
    ??????????? ????????? java.io.Externalazable
  • ??? ?????????? ????????? ? ????????
  • public interface Externalazable extends
    Serializable
  • public void writeExternal (ObjectOutput out)
    throws IOException
  • public void readExternal (ObjectInput in)
    throws IOException, ClassNotFoundException
  • // ? ???????? ????????? ... ??????
    (????????? ?? ??????????, ? ??????...)
  • ???????? ???????????? / ?????????????? ? ????
    ?????? ?????? ????? ? ????? ?????????? ? ??????
    ??????? (??? ????????????) ? ??????? ?????
    ????????? ??????? ??? ?????????? (???
    ???????...?)
  • ????????? ?????? ??????? ???? ????????? ????
    ??????
  • ? ??????? ?? ???????????? ??? ??????
    ???????????? (public)
  • ??? ?????????? ??? ????????? ??????? ??????????
  • ObjectOutput.writeObject(Object )
  • ObjectInput.readObject()

4
  • ?????????
  • ??????????? ???????????? ???????? ????????
    ????????
  • ????????????? Externalizable ????? ????????
    ???????? ?????? / ?????????????? ????????
  • ????????????? ?????? Externalizable-??????????
    ????????? ???????? ????????? ?????????????
    ??????? (??????? readExternal()) (????? ????
    ?????? ? ??????? ???????? ?????????... ???
    writeExternal())

5
?????????? ??????? (????? File)
  • ????????? ?????? ??????? ??? ?????? ? ??????????
    ??????
  • ????? File ??? ?????? ? ?????? ???????.
  • Java ?????? ?????????????? ???????? ???????????
    ?????? ??????????? ??? ?????????? ????????????,
    ????????? ? ??????? ????????????? ?????????
    ?????????? ?? ??????????? ??????????????
    ???????? native-???????
  • ?????????? ??????????? File(String s) ????????
    ??? ?????
  • ???? ??? ?? ??????, ?? ????? ???? ?? ????????
    ????????
  • ??????? ??????? ??? ???? ???, ?? ????????
    ???????? Java VM (???? JVM ??????????? ??
    ????????? ??????).
  • ???? ????? ? ????? ?????? ?? ??????????, ?? ??
    ?????????
  • ??????????? ???????? ????? ?? ??????? ?????? File
    ???????? ?????-?? ??????? ??? ??????????? ???????
    ?????? File createNewFile(), ??????? ???????
    ????? ????, ???? ??? ?? ???? (?????? ??
    ??????...).

6
  • ???? ?????? File, ????? ??????, ?????????? ??
    ????? ????
  • ??????? exists() -gt true/false
  • ???? ???????????? ?????? File ? ?????????
    ???????? (null ???????? ??????? ???????) ?
    ????? ????? ? ???. ??????? ????? ???????
  • ?????? (???????)
  • ???????? ?????? File (?????? File ??????????
    ??????? ????? ? ????????)
  • ??????, ??? ?????? ???????? ?????? File ?????
    ????????
  • isDirectory()
  • isFile()
  • ??????? ?????? File, ?????????????? ???????
    (??????????) ????? ???
  • File tempDir new File( File.separator
    temp)
  • ????? ???? tempDir.mkdir() ??????? ??????????
    (???? ?? ??? ???...)

7
  • ?? ??????? ???????????? ?????????? ????????????
    ????, ???????? ? ?????? ???????? ??????? ????
    ???????????? ??????????? ?? ?????? File
    File.separator
  • ? Win32FileSystem ??? backslash (\)
  • ? Unix ??? forward slash (/).
  • ???? ????? ? ????, ??? ? Java \ - ??? escape -
    ?????? (??? ????)

8
????? ????-????? (????? java.nio)
  • ????? java.nio ???????? ? JDK 1.4 (?? ?? ??? ???
    ?????????? new i/o)
  • ??????????? ?????? ? ?????? (memory-mapped files)
    ???????? ??????????? ??????????? ????????????
    ?????? ? ?????? (??? ??????? ??????? ??????????)
    ???????? ?????? ?? ????????? ? ?????????????
    ????????? ??????????
  • ????? java.nio ????? ??? ????? ????????
  • ????????? ?????? ??? ??????
  • ?????? FileInputStream, FileOutputStream ?
    RundomAccessFile ????? ????? getChannel(),
    ??????? ?????????? FileChannel
  • ????????? ByteBuffer? ?? ??????
  • ????? FileChannel ????? ????? map(), ??????? ????
    MappedByteBuffer
  • MappedByteBuffer extends ByteBuffer.
  • ??? ????????? ?????? ? ?????? ??????????? ?????
    ??????????? (MapMode) ? ??????? ?????,
    ???????????? ? ?????? (?????? ? ??????)

9
  • Java ???????????? ??? ?????? ???????????
  • FileChannel.MapMode.READ_ONLY
  • ????????? ????? ?????? ??? ?????? (????? -
    exception)
  • FileChannel.MapMode.READ_WRITE
  • ????? ????????? ??????, ?????-?????? ?????????
    ???????? ? ?????...
  • FileChannel.MapMode.PRIVATE
  • ? ????? ????? ??????, ?? ????????? ? ???? ??
    ????????.
  • ???? ByteBuffer, ????? ???????????? ??? ????????
    ??? ?????? ?/??? ?????? ??????
  • ?????? ???????????? ???????????????? ?/???
    ???????????? ?????? ? ??????.
  • ? ?????? ?????????? ???????, ??????? ?????????? ?
    ?????????? ?????????? ??????? get() ? put()
  • ???????? ???????????? ??????
  • ????????, byte d buffer.get(i)
  • ???????? ?????? / pfgbcm ??????? ??????,
    ????????
  • get(byte bytes) ??? get(byte bytes, int
    offset, int length)

10
  • ????? ?????? / ?????? ???????? ?????????????
    ??????? ?????
  • getInt(), getLong(), getShort(), getChar(),
    getFloat(), getDouble()
  • putInt(), putLong(), putShort(), putChar(),
    putFloat(), putDouble()
  • ??? ???? ????????????? ???????? ? ???????
    ???????? ?????? ? ????? (ByteOrder.LITTLE_ENDIAN
    ??? ByteOrder. BIG_ENDIAN)
  • ??????, ????? ??????? ? ??????
  • ByteOrder bo buffer.order()
  • ?????????? ?????? ???????
  • Buffer.order(ByteOrder.LITTLE_ENDIAN) // ???
    BIG_ENDIAN

11
????????? ??????
  • ??? ??????????? ????? ? ?????? ????????? ?????,
    ??????? ?????? ?? ???? ???? ??? ??? ?????? ?????
  • ????? ??? ?????? ???????? ????????????? ????
    ?? ???????????? ?????? Buffer ???????????
    ByteBuffer, CharBuffer, FloatBuffer, IntBuffer, ?
    ?.?.
  • ????? ????? ????????? ??????????????
  • ????? (capacity), ??????? ?? ????????
  • ??????? (position) ??????/?????? ??????????
    ????????
  • ??????? (limit), ?? ??????? ??????/?????? ??
    ????? ??????
  • ?????? (??????????????) ??? ??????????
    ??????/??????.

12
  • ????? ? ???????? ??????????? ??? ??????/??????
    ?????????? ? ?????
  • ? ?????? ?????? ??????? ??????? ????? 0, ???????
    ????? ??????
  • ????? get() ????? ???????? ?? ??? ???, ????
  • Remaining (??????? - ???????) gt 0
  • ????? flip () ????????????? ??????? ??????
    ??????? ???????, ? ??????? ?????? 0
  • ????? clear() ?????? ??????? ? 0 ? ???????
    ?????? ??????
  • ????????? ????????? ????? ???????????? ? ???????
    ??????? rewind(), mark(), reset().

13
?????????? ??????
  • ??? ? ?????? ? ???????????? ????? ? ??????,
    ?????????? ????? ???????? ????????? ??
    ???????????? ???????
  • ?????????? ????? ?????? ?????, ???? ?????????
    ???????? ????????? ???????? ? ????? ??????.
  • ???? ??????????? ???????? ??????? ??????
    FileChannel
  • FileLock lock channel.lock() // ????????
    ??????????? ??????????...
  • FileLock lock channel.tryLock() // ??????????
    ??? null, ???? ????? ???...
  • ????? ????????????? ????? ?????
  • FileLock lock(long start, long size, boolean
    exclusive)
  • FileLock tryLock(long start, long size, boolean
    exclusive)
  • excusive true, ???? ??????????????
    ?????????? (??? ??????)
  • exclusive false, ???? ?????????? ??????????
    (??? ????????????? ??????) ??? ????????
    ?????????????? ?? ????? ?????????????
    ?????????...

14
(No Transcript)
15
?????????-??????????????? ??? (native code)
  • ?????? ?????????? ???????????? ?????????-?????????
    ?????? ???
  • ??? ???? ??????? ??????????? ??????, ???????
    ??????? ???????????? (OpenGL, ????????)
  • ????????? ??????? ?????????? OS ??? ??????
  • ??????? ??????????? ??? ????????? ??????? (??
    ????? ???? just-in-time ?????????? ??????????
    ??????? ? ????????????????? ?-?????).
  • ??? ????????????? native-???? ???? ????????
    ???????? ?? ??????
  • ??? ???????, ???????????? ?? ?????? ????? ???? ?
    native-?????, ? ??? ???? ????????? ?????? ?
    ??????? ???????. ???? ???????????? ???????
    ??????? ??????? ??????? ????????? ?????,
    ???????? ????????? ?? ? java...

16
????? C-??????? ?? java-?????????
  • ? ????????? ?????? java ???????????
    native-???????, ????????,
  • public native String translateEnglishIntoRussian
    (String s)
  • ?????, ?????????? ??? ?????????? native-??????,
    ??????????????, ?? ??? ??????????
    UnsatisfiedLinkError - JVM ?? ????? ????? ??????
    ???????. Native-????? ????? ???? ??? ?? ????
    ???????????.
  • ?????? ????
  • ??????? ?? ????? C ???????? (??????????),
    ??????? ??????????? ????? ?? java ? ????????? ?
    ?????? C-?????? ? ?????????, ???? ?????
    ????????? ?? ????? JVM ? ???????? ??
    ????????????????? C-???????
  • ??????? ??????????? ??????????? ?????????? (dll
    ? Windows), ??????? ???????????? ??? ????????
  • ???????????? ??????????? ????? java
    System.loadLibrary(), ?????? ??? ???? dll

17
  • ?????????? ???? ?????????? ??????
  • ?????? ????????????? java-????? ?
    native-????????
  • ????? ?????????? ??????????? ??????? ?? ????????
    jdk/bin ??? ????????? javah.exe ??????????
    ??????? ?????? ?????-????. ??? ??????? ??????????
    Header-???? (lt???_??????gt.h) ??? ???????? ????
    ??? ????????????? ?-????????????. ? ??? ?????
    ???????????? jni.h, ??? ?????????? ???
    ??????????? ?????...
  • ? ??????????????? ???????????? ????? ?????
    ???????? ?????????? ???????, ??????? ????
    ??????????? ?? ?.
  • ??? ????? ????????????? ?-??????? ?????????? ?
    dll, ????????,
  • myNatives.dll
  • ? java-??????, ??? ????? native-??????, ??????
    ??????????? ????????????? (????? ?? ?????
    ?????????)
  • static System.loadLibrary(myNatives)
  • ???? myNatives.dll ???? ???????? ? ?????? ?????
    ...

18
  • ??????? ??????, ????????? ?
  • ????????? ??????? ????????????, ??????????? ?
    ????????????? ???????
  • ????????? ?????????? ? ???????????? ????????
  • ??????? ? ????????????? ?????????
  • ????????? ?????? ? ?????????????? ????????
  • ? ?.?.
  • ??? ???, ??? ??????? C (C) ??? ?????? ??
    ????????.

19
Q A
  • Have a nice test !
Write a Comment
User Comments (0)
About PowerShow.com