<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="ru">
		<id>http://www.jexp.ru/index.php?action=history&amp;feed=atom&amp;title=Java_by_API%2Fjava.nio%2FBuffer</id>
		<title>Java by API/java.nio/Buffer - История изменений</title>
		<link rel="self" type="application/atom+xml" href="http://www.jexp.ru/index.php?action=history&amp;feed=atom&amp;title=Java_by_API%2Fjava.nio%2FBuffer"/>
		<link rel="alternate" type="text/html" href="http://www.jexp.ru/index.php?title=Java_by_API/java.nio/Buffer&amp;action=history"/>
		<updated>2026-04-23T01:34:03Z</updated>
		<subtitle>История изменений этой страницы в вики</subtitle>
		<generator>MediaWiki 1.30.0</generator>

	<entry>
		<id>http://www.jexp.ru/index.php?title=Java_by_API/java.nio/Buffer&amp;diff=1237&amp;oldid=prev</id>
		<title> в 17:43, 31 мая 2010</title>
		<link rel="alternate" type="text/html" href="http://www.jexp.ru/index.php?title=Java_by_API/java.nio/Buffer&amp;diff=1237&amp;oldid=prev"/>
				<updated>2010-05-31T17:43:48Z</updated>
		
		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table class=&quot;diff diff-contentalign-left&quot; data-mw=&quot;interface&quot;&gt;
				&lt;tr style=&quot;vertical-align: top;&quot; lang=&quot;ru&quot;&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;← Предыдущая&lt;/td&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;Версия 17:43, 31 мая 2010&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; style=&quot;text-align: center;&quot; lang=&quot;ru&quot;&gt;&lt;div class=&quot;mw-diff-empty&quot;&gt;(нет различий)&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;</summary>
			</entry>

	<entry>
		<id>http://www.jexp.ru/index.php?title=Java_by_API/java.nio/Buffer&amp;diff=1238&amp;oldid=prev</id>
		<title>Admin: 1 версия</title>
		<link rel="alternate" type="text/html" href="http://www.jexp.ru/index.php?title=Java_by_API/java.nio/Buffer&amp;diff=1238&amp;oldid=prev"/>
				<updated>2010-05-31T14:31:51Z</updated>
		
		<summary type="html">&lt;p&gt;1 версия&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Новая страница&lt;/b&gt;&lt;/p&gt;&lt;div&gt;== Buffer: hasRemaining() ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- start source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
    &amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
import java.io.FileInputStream;&lt;br /&gt;
import java.nio.ByteBuffer;&lt;br /&gt;
import java.nio.channels.FileChannel;&lt;br /&gt;
public class Main {&lt;br /&gt;
  private static final int BSIZE = 1024;&lt;br /&gt;
  public static void main(String[] args) throws Exception {&lt;br /&gt;
    FileChannel fc = new FileInputStream(&amp;quot;data.txt&amp;quot;).getChannel();&lt;br /&gt;
    ByteBuffer buff = ByteBuffer.allocate(BSIZE);&lt;br /&gt;
    fc.read(buff);&lt;br /&gt;
    buff.flip();&lt;br /&gt;
    while (buff.hasRemaining())&lt;br /&gt;
      System.out.print((char) buff.get());&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;/source&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- end source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Buffer: limit(int newLimit) ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- start source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
    &amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
import static java.lang.Math.ceil;&lt;br /&gt;
import static java.lang.Math.min;&lt;br /&gt;
import static java.lang.Math.sqrt;&lt;br /&gt;
import java.io.File;&lt;br /&gt;
import java.io.FileNotFoundException;&lt;br /&gt;
import java.io.FileOutputStream;&lt;br /&gt;
import java.io.IOException;&lt;br /&gt;
import java.nio.ByteBuffer;&lt;br /&gt;
import java.nio.LongBuffer;&lt;br /&gt;
import java.nio.channels.FileChannel;&lt;br /&gt;
public class MainClass {&lt;br /&gt;
  public static void main(String[] args) {&lt;br /&gt;
    int count = 100;&lt;br /&gt;
    long[] numbers = new long[count];&lt;br /&gt;
    for (int i = 0; i &amp;lt; numbers.length; i++) {&lt;br /&gt;
      numbers[i] = i;&lt;br /&gt;
    }&lt;br /&gt;
    File aFile = new File(&amp;quot;data.bin&amp;quot;);&lt;br /&gt;
    FileOutputStream outputFile = null;&lt;br /&gt;
    try {&lt;br /&gt;
      outputFile = new FileOutputStream(aFile);&lt;br /&gt;
    } catch (FileNotFoundException e) {&lt;br /&gt;
      e.printStackTrace(System.err);&lt;br /&gt;
      System.exit(1);&lt;br /&gt;
    }&lt;br /&gt;
    FileChannel file = outputFile.getChannel();&lt;br /&gt;
    final int BUFFERSIZE = 100;&lt;br /&gt;
    ByteBuffer buf = ByteBuffer.allocate(BUFFERSIZE);&lt;br /&gt;
    LongBuffer longBuf = buf.asLongBuffer();&lt;br /&gt;
    int numberWritten = 0;&lt;br /&gt;
    while (numberWritten &amp;lt; numbers.length) {&lt;br /&gt;
      longBuf.put(numbers, numberWritten, min(longBuf.capacity(), numbers.length - numberWritten));&lt;br /&gt;
      buf.limit(8 * longBuf.position());&lt;br /&gt;
      try {&lt;br /&gt;
        file.write(buf);&lt;br /&gt;
        numberWritten += longBuf.position();&lt;br /&gt;
      } catch (IOException e) {&lt;br /&gt;
        e.printStackTrace(System.err);&lt;br /&gt;
        System.exit(1);&lt;br /&gt;
      }&lt;br /&gt;
      longBuf.clear();&lt;br /&gt;
      buf.clear();&lt;br /&gt;
    }&lt;br /&gt;
    try {&lt;br /&gt;
      System.out.println(&amp;quot;File written is &amp;quot; + file.size() + &amp;quot; bytes.&amp;quot;);&lt;br /&gt;
      outputFile.close();&lt;br /&gt;
    } catch (IOException e) {&lt;br /&gt;
      e.printStackTrace(System.err);&lt;br /&gt;
      System.exit(1);&lt;br /&gt;
    }&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
           &lt;br /&gt;
         &lt;br /&gt;
  &amp;lt;/source&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- end source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Buffer: remaining() ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- start source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
    &amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
import java.io.File;&lt;br /&gt;
import java.io.FileInputStream;&lt;br /&gt;
import java.io.IOException;&lt;br /&gt;
import java.io.FileNotFoundException;&lt;br /&gt;
import java.nio.ByteBuffer;&lt;br /&gt;
import java.nio.LongBuffer;&lt;br /&gt;
import java.nio.BufferUnderflowException;&lt;br /&gt;
import java.nio.channels.FileChannel;&lt;br /&gt;
public class MainClass {&lt;br /&gt;
  public static void main(String[] args) {&lt;br /&gt;
    File aFile = new File(&amp;quot;data.dat&amp;quot;);&lt;br /&gt;
    FileInputStream inFile = null;&lt;br /&gt;
    try {&lt;br /&gt;
      inFile = new FileInputStream(aFile);&lt;br /&gt;
    } catch (FileNotFoundException e) {&lt;br /&gt;
      e.printStackTrace(System.err);&lt;br /&gt;
      System.exit(1);&lt;br /&gt;
    }&lt;br /&gt;
    FileChannel inChannel = inFile.getChannel();&lt;br /&gt;
    final int COUNT = 6;&lt;br /&gt;
    ByteBuffer buf = ByteBuffer.allocate(8 * COUNT);&lt;br /&gt;
    long[] data = new long[COUNT];&lt;br /&gt;
    try {&lt;br /&gt;
      int pos = 0;&lt;br /&gt;
      while (inChannel.read(buf) != -1) {&lt;br /&gt;
        try {&lt;br /&gt;
          ((ByteBuffer) (buf.flip())).asLongBuffer().get(data);&lt;br /&gt;
          pos = data.length;&lt;br /&gt;
        } catch (BufferUnderflowException e) {&lt;br /&gt;
          LongBuffer longBuf = buf.asLongBuffer();&lt;br /&gt;
          pos = longBuf.remaining();&lt;br /&gt;
          longBuf.get(data, 0, pos);&lt;br /&gt;
        }&lt;br /&gt;
        System.out.println();&lt;br /&gt;
        for (int i = 0; i &amp;lt; pos; i++) {&lt;br /&gt;
          System.out.printf(&amp;quot;%10d&amp;quot;, data[i]);&lt;br /&gt;
        }&lt;br /&gt;
        buf.clear();&lt;br /&gt;
      }&lt;br /&gt;
      System.out.println(&amp;quot;\nEOF reached.&amp;quot;);&lt;br /&gt;
      inFile.close();&lt;br /&gt;
    } catch (IOException e) {&lt;br /&gt;
      e.printStackTrace(System.err);&lt;br /&gt;
      System.exit(1);&lt;br /&gt;
    }&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
           &lt;br /&gt;
         &lt;br /&gt;
  &amp;lt;/source&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- end source code --&amp;gt;&lt;/div&gt;</summary>
		<author><name>Admin</name></author>	</entry>

	</feed>