1 package nom.tam.util; 2 3 /* 4 * #%L 5 * nom.tam FITS library 6 * %% 7 * Copyright (C) 1996 - 2024 nom-tam-fits 8 * %% 9 * This is free and unencumbered software released into the public domain. 10 * 11 * Anyone is free to copy, modify, publish, use, compile, sell, or 12 * distribute this software, either in source code form or as a compiled 13 * binary, for any purpose, commercial or non-commercial, and by any 14 * means. 15 * 16 * In jurisdictions that recognize copyright laws, the author or authors 17 * of this software dedicate any and all copyright interest in the 18 * software to the public domain. We make this dedication for the benefit 19 * of the public at large and to the detriment of our heirs and 20 * successors. We intend this dedication to be an overt act of 21 * relinquishment in perpetuity of all present and future rights to this 22 * software under copyright law. 23 * 24 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 25 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 26 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 27 * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR 28 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 29 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 30 * OTHER DEALINGS IN THE SOFTWARE. 31 * #L% 32 */ 33 34 /** 35 * @deprecated (<i>for internal use</i>) It is a rusty-rail compatibility implementation only, unsafe for general use. 36 * No longer used within the FITS package itself. If you do attempt to use it with the deprecated APIs, 37 * beware that no data will be filled into the buffer of this object ever by the library, although its 38 * length and position fields may be updated to pretend as if the buffer were always hall full / half 39 * available... 40 * 41 * @see BufferEncoder 42 * @see BufferDecoder 43 */ 44 @Deprecated 45 public class BufferPointer { 46 47 /** 48 * The data buffer. 49 */ 50 protected byte[] buffer; 51 52 /** 53 * The number of valid characters in the buffer 54 */ 55 protected int length; 56 57 /** 58 * The current offset into the buffer 59 */ 60 protected int pos; 61 62 /** 63 * Constructs a new buffer pointer with no associated buffer 64 * 65 * @deprecated Rusty rail implementation only. 66 */ 67 public BufferPointer() { 68 } 69 70 /** 71 * Constructs a new buffer pointer for the specified byte buffer 72 * 73 * @param buffer the array containing the bytes of the buffer. 74 * 75 * @deprecated Rusty rail implementation only. 76 */ 77 public BufferPointer(byte[] buffer) { 78 this(); 79 this.buffer = buffer; 80 } 81 82 /** 83 * (re)initializes the underlying buffer, creating a new buffer of the specified size 84 * 85 * @param bufferSize 86 * 87 * @return itself 88 * 89 * @deprecated Rusty rail implementation only. 90 */ 91 protected BufferPointer init(int bufferSize) { 92 buffer = new byte[bufferSize]; 93 pos = 0; 94 length = 0; 95 return this; 96 } 97 98 /** 99 * Invalidates the pointer, setting both the length and the position to zero. 100 */ 101 protected void invalidate() { 102 length = 0; 103 pos = 0; 104 } 105 106 /** 107 * Returns the current buffer position 108 * 109 * @return the current position 110 */ 111 public int position() { 112 return pos; 113 } 114 115 /** 116 * Returns the current sizeof the buffer 117 * 118 * @return the size (or accessible limit) of the buffer 119 */ 120 public int limit() { 121 return length; 122 } 123 }