1. /*
  2. * @(#)Direct-X-Buffer.java 1.48 04/05/03
  3. *
  4. * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
  5. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  6. */
  7. // -- This file was mechanically generated: Do not edit! -- //
  8. package java.nio;
  9. import sun.misc.Cleaner;
  10. import sun.misc.Unsafe;
  11. import sun.nio.ch.DirectBuffer;
  12. import sun.nio.ch.FileChannelImpl;
  13. class DirectByteBufferR
  14. extends DirectByteBuffer
  15. implements DirectBuffer
  16. {
  17. // Primary constructor
  18. //
  19. DirectByteBufferR(int cap) { // package-private
  20. super(cap);
  21. }
  22. // For memory-mapped buffers -- invoked by FileChannelImpl via reflection
  23. //
  24. protected DirectByteBufferR(int cap, long addr, Runnable unmapper) {
  25. super(cap, addr, unmapper);
  26. }
  27. // For duplicates and slices
  28. //
  29. DirectByteBufferR(DirectBuffer db, // package-private
  30. int mark, int pos, int lim, int cap,
  31. int off)
  32. {
  33. super(db, mark, pos, lim, cap, off);
  34. }
  35. public ByteBuffer slice() {
  36. int pos = this.position();
  37. int lim = this.limit();
  38. assert (pos <= lim);
  39. int rem = (pos <= lim ? lim - pos : 0);
  40. int off = (pos << 0);
  41. assert (off >= 0);
  42. return new DirectByteBufferR(this, -1, 0, rem, rem, off);
  43. }
  44. public ByteBuffer duplicate() {
  45. return new DirectByteBufferR(this,
  46. this.markValue(),
  47. this.position(),
  48. this.limit(),
  49. this.capacity(),
  50. 0);
  51. }
  52. public ByteBuffer asReadOnlyBuffer() {
  53. return duplicate();
  54. }
  55. public ByteBuffer put(byte x) {
  56. throw new ReadOnlyBufferException();
  57. }
  58. public ByteBuffer put(int i, byte x) {
  59. throw new ReadOnlyBufferException();
  60. }
  61. public ByteBuffer put(ByteBuffer src) {
  62. throw new ReadOnlyBufferException();
  63. }
  64. public ByteBuffer put(byte[] src, int offset, int length) {
  65. throw new ReadOnlyBufferException();
  66. }
  67. public ByteBuffer compact() {
  68. throw new ReadOnlyBufferException();
  69. }
  70. public boolean isDirect() {
  71. return true;
  72. }
  73. public boolean isReadOnly() {
  74. return true;
  75. }
  76. byte _get(int i) { // package-private
  77. return unsafe.getByte(address + i);
  78. }
  79. void _put(int i, byte b) { // package-private
  80. throw new ReadOnlyBufferException();
  81. }
  82. private ByteBuffer putChar(long a, char x) {
  83. throw new ReadOnlyBufferException();
  84. }
  85. public ByteBuffer putChar(char x) {
  86. throw new ReadOnlyBufferException();
  87. }
  88. public ByteBuffer putChar(int i, char x) {
  89. throw new ReadOnlyBufferException();
  90. }
  91. public CharBuffer asCharBuffer() {
  92. int off = this.position();
  93. int lim = this.limit();
  94. assert (off <= lim);
  95. int rem = (off <= lim ? lim - off : 0);
  96. int size = rem >> 1;
  97. if (!unaligned && ((address + off) % (1 << 1) != 0)) {
  98. return (bigEndian
  99. ? (CharBuffer)(new ByteBufferAsCharBufferRB(this,
  100. -1,
  101. 0,
  102. size,
  103. size,
  104. off))
  105. : (CharBuffer)(new ByteBufferAsCharBufferRL(this,
  106. -1,
  107. 0,
  108. size,
  109. size,
  110. off)));
  111. } else {
  112. return (nativeByteOrder
  113. ? (CharBuffer)(new DirectCharBufferRU(this,
  114. -1,
  115. 0,
  116. size,
  117. size,
  118. off))
  119. : (CharBuffer)(new DirectCharBufferRS(this,
  120. -1,
  121. 0,
  122. size,
  123. size,
  124. off)));
  125. }
  126. }
  127. private ByteBuffer putShort(long a, short x) {
  128. throw new ReadOnlyBufferException();
  129. }
  130. public ByteBuffer putShort(short x) {
  131. throw new ReadOnlyBufferException();
  132. }
  133. public ByteBuffer putShort(int i, short x) {
  134. throw new ReadOnlyBufferException();
  135. }
  136. public ShortBuffer asShortBuffer() {
  137. int off = this.position();
  138. int lim = this.limit();
  139. assert (off <= lim);
  140. int rem = (off <= lim ? lim - off : 0);
  141. int size = rem >> 1;
  142. if (!unaligned && ((address + off) % (1 << 1) != 0)) {
  143. return (bigEndian
  144. ? (ShortBuffer)(new ByteBufferAsShortBufferRB(this,
  145. -1,
  146. 0,
  147. size,
  148. size,
  149. off))
  150. : (ShortBuffer)(new ByteBufferAsShortBufferRL(this,
  151. -1,
  152. 0,
  153. size,
  154. size,
  155. off)));
  156. } else {
  157. return (nativeByteOrder
  158. ? (ShortBuffer)(new DirectShortBufferRU(this,
  159. -1,
  160. 0,
  161. size,
  162. size,
  163. off))
  164. : (ShortBuffer)(new DirectShortBufferRS(this,
  165. -1,
  166. 0,
  167. size,
  168. size,
  169. off)));
  170. }
  171. }
  172. private ByteBuffer putInt(long a, int x) {
  173. throw new ReadOnlyBufferException();
  174. }
  175. public ByteBuffer putInt(int x) {
  176. throw new ReadOnlyBufferException();
  177. }
  178. public ByteBuffer putInt(int i, int x) {
  179. throw new ReadOnlyBufferException();
  180. }
  181. public IntBuffer asIntBuffer() {
  182. int off = this.position();
  183. int lim = this.limit();
  184. assert (off <= lim);
  185. int rem = (off <= lim ? lim - off : 0);
  186. int size = rem >> 2;
  187. if (!unaligned && ((address + off) % (1 << 2) != 0)) {
  188. return (bigEndian
  189. ? (IntBuffer)(new ByteBufferAsIntBufferRB(this,
  190. -1,
  191. 0,
  192. size,
  193. size,
  194. off))
  195. : (IntBuffer)(new ByteBufferAsIntBufferRL(this,
  196. -1,
  197. 0,
  198. size,
  199. size,
  200. off)));
  201. } else {
  202. return (nativeByteOrder
  203. ? (IntBuffer)(new DirectIntBufferRU(this,
  204. -1,
  205. 0,
  206. size,
  207. size,
  208. off))
  209. : (IntBuffer)(new DirectIntBufferRS(this,
  210. -1,
  211. 0,
  212. size,
  213. size,
  214. off)));
  215. }
  216. }
  217. private ByteBuffer putLong(long a, long x) {
  218. throw new ReadOnlyBufferException();
  219. }
  220. public ByteBuffer putLong(long x) {
  221. throw new ReadOnlyBufferException();
  222. }
  223. public ByteBuffer putLong(int i, long x) {
  224. throw new ReadOnlyBufferException();
  225. }
  226. public LongBuffer asLongBuffer() {
  227. int off = this.position();
  228. int lim = this.limit();
  229. assert (off <= lim);
  230. int rem = (off <= lim ? lim - off : 0);
  231. int size = rem >> 3;
  232. if (!unaligned && ((address + off) % (1 << 3) != 0)) {
  233. return (bigEndian
  234. ? (LongBuffer)(new ByteBufferAsLongBufferRB(this,
  235. -1,
  236. 0,
  237. size,
  238. size,
  239. off))
  240. : (LongBuffer)(new ByteBufferAsLongBufferRL(this,
  241. -1,
  242. 0,
  243. size,
  244. size,
  245. off)));
  246. } else {
  247. return (nativeByteOrder
  248. ? (LongBuffer)(new DirectLongBufferRU(this,
  249. -1,
  250. 0,
  251. size,
  252. size,
  253. off))
  254. : (LongBuffer)(new DirectLongBufferRS(this,
  255. -1,
  256. 0,
  257. size,
  258. size,
  259. off)));
  260. }
  261. }
  262. private ByteBuffer putFloat(long a, float x) {
  263. throw new ReadOnlyBufferException();
  264. }
  265. public ByteBuffer putFloat(float x) {
  266. throw new ReadOnlyBufferException();
  267. }
  268. public ByteBuffer putFloat(int i, float x) {
  269. throw new ReadOnlyBufferException();
  270. }
  271. public FloatBuffer asFloatBuffer() {
  272. int off = this.position();
  273. int lim = this.limit();
  274. assert (off <= lim);
  275. int rem = (off <= lim ? lim - off : 0);
  276. int size = rem >> 2;
  277. if (!unaligned && ((address + off) % (1 << 2) != 0)) {
  278. return (bigEndian
  279. ? (FloatBuffer)(new ByteBufferAsFloatBufferRB(this,
  280. -1,
  281. 0,
  282. size,
  283. size,
  284. off))
  285. : (FloatBuffer)(new ByteBufferAsFloatBufferRL(this,
  286. -1,
  287. 0,
  288. size,
  289. size,
  290. off)));
  291. } else {
  292. return (nativeByteOrder
  293. ? (FloatBuffer)(new DirectFloatBufferRU(this,
  294. -1,
  295. 0,
  296. size,
  297. size,
  298. off))
  299. : (FloatBuffer)(new DirectFloatBufferRS(this,
  300. -1,
  301. 0,
  302. size,
  303. size,
  304. off)));
  305. }
  306. }
  307. private ByteBuffer putDouble(long a, double x) {
  308. throw new ReadOnlyBufferException();
  309. }
  310. public ByteBuffer putDouble(double x) {
  311. throw new ReadOnlyBufferException();
  312. }
  313. public ByteBuffer putDouble(int i, double x) {
  314. throw new ReadOnlyBufferException();
  315. }
  316. public DoubleBuffer asDoubleBuffer() {
  317. int off = this.position();
  318. int lim = this.limit();
  319. assert (off <= lim);
  320. int rem = (off <= lim ? lim - off : 0);
  321. int size = rem >> 3;
  322. if (!unaligned && ((address + off) % (1 << 3) != 0)) {
  323. return (bigEndian
  324. ? (DoubleBuffer)(new ByteBufferAsDoubleBufferRB(this,
  325. -1,
  326. 0,
  327. size,
  328. size,
  329. off))
  330. : (DoubleBuffer)(new ByteBufferAsDoubleBufferRL(this,
  331. -1,
  332. 0,
  333. size,
  334. size,
  335. off)));
  336. } else {
  337. return (nativeByteOrder
  338. ? (DoubleBuffer)(new DirectDoubleBufferRU(this,
  339. -1,
  340. 0,
  341. size,
  342. size,
  343. off))
  344. : (DoubleBuffer)(new DirectDoubleBufferRS(this,
  345. -1,
  346. 0,
  347. size,
  348. size,
  349. off)));
  350. }
  351. }
  352. }