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