/** * Retrieve a record (=row) * @param dbfHeader dBase meta info * @param recordNumber starts with 1 * @return the String with the complete record * or null if the record is marked as deleted * @see tinySQLTable#GetCol */ public String GetRecord(java.io.RandomAccessFile ff, DBFHeader dbfHeader, int recordNumber) //throws tinySQLException { if (recordNumber < 1) { throw new TinySQLException("Internal error - current record number < 1"); } try { // seek the starting offset of the current record, // as indicated by recordNumber ff.seek(dbfHeader.headerLength + (recordNumber - 1) * dbfHeader.recordLength); // fully read a byte array out to the length of // the record. byte[] b = new byte[dbfHeader.recordLength]; ff.readFully(b); // make it into a String String record = new java.lang.StringJ(b, Utils.encode); // remove deleted records if (DBFFileTable.isDeleted(record)) { return(null); } return(record); } catch (Exception e) { throw new TinySQLException(e.getMessage()); } }
/** * Returns the contents of this {@code CharArrayWriter} as a string. The * string returned is a copy and any modifications made to this writer after * calling this method are not reflected in the result. * * @return this CharArrayWriters contents as a new string. */ public override String ToString() { lock (lockJ) { java.lang.StringJ result = new java.lang.StringJ(buf, 0, count); return(new java.lang.StringJ(buf, 0, count)); } }
// Write a string to the output stream. private void write(java.lang.StringJ s) { try { this.writer.write(s); } catch (java.lang.Exception e) { // logging.14=Exception occurred when writing to the output stream. getErrorManager().error("Exception occurred when writing to the output stream.", e, //$NON-NLS-1$ ErrorManager.WRITE_FAILURE); } }
/* * Appends a subsequence of the character sequence {@code csq} to this * writer's {@code StringBuffer}. This method works the same way as {@code * StringWriter.writer(csq.subsequence(start, end).toString())}. If {@code * csq} is {@code null}, then the specified subsequence of the string "null" * will be written to the target. * * @param csq * the character sequence appended to the target. * @param start * the index of the first char in the character sequence appended * to the target. * @param end * the index of the character following the last character of the * subsequence appended to the target. * @return this writer. * @throws IndexOutOfBoundsException * if {@code start > end}, {@code start < 0}, {@code end < 0} or * either {@code start} or {@code end} are greater or equal than * the length of {@code csq}. */ public new StringWriter append(java.lang.CharSequence csq, int start, int end) { if (null == csq) { csq = new java.lang.StringJ(TOKEN_NULL); } String output = csq.subSequence(start, end).toString(); write(output, 0, output.length()); return(this); }
/** * Method to convert a null terminated C string into a java string using the * defined encoding * * @param data * An array of bytes containing a C string * @param offset * An offset from which to start to read the string from the data * array * @param enc * A encoding as defined in java.lang.String * * @return A java string representig a null terminated C string * @throws UnsupportedEncodingException * if the encoding is not supported */ public static String cArrayToString(byte[] data, int offset, String enc) {// throws UnsupportedEncodingException { if (offset > data.Length) { throw new java.lang.IllegalArgumentException("Data offset is too big"); } for (int i = offset; i < data.Length; i++) { if (data[i] == 0) { java.lang.StringJ result = new java.lang.StringJ(data, offset, i - offset, enc); return(result.ToString()); } } // TODO: Warning goes here that there is no null terminated string return(""); }
/** * Compares two strings based not on the strings * themselves, but on an encoding of the two * strings using the StringEncoder this Comparator * was created with. * * If an {@link EncoderException} is encountered, return <code>0</code>. * * @param o1 the object to compare * @param o2 the object to compare to * @return the Comparable.compareTo() return code or 0 if an encoding error was caught. * @see Comparable */ public int compare(String o1, String o2) { int compareCode = 0; try { Object eO1 = this.stringEncoder.encode(o1); Object eO2 = this.stringEncoder.encode(o2); String sJ1 = null; String sJ2 = null; if (eO1 is byte[]) { sJ1 = new java.lang.StringJ((byte[])eO1); } else { sJ1 = (String)eO1; } if (eO2 is byte[]) { sJ2 = new java.lang.StringJ((byte[])eO2); } else { sJ2 = (String)eO2; } compareCode = sJ1.compareTo(sJ2); /*java.lang.Comparable<String> s1 = (java.lang.Comparable<String>)this.stringEncoder.encode(o1); * java.lang.Comparable<String> s2 = (java.lang.Comparable<String>)this.stringEncoder.encode(o2); * compareCode = s1.compareTo(s2);*/ } catch (EncoderException) { compareCode = 0; } return(compareCode); }
public override byte[] getByteArray(String key, byte[] deflt) { java.lang.StringJ svalue = get(key, null); if (svalue == null) { return(deflt); } if (svalue.length() == 0) { return(new byte[0]); } try { byte[] bavalue = svalue.getBytes("US-ASCII"); //$NON-NLS-1$ if (bavalue.Length % 4 != 0) { return(deflt); } return(new java.lang.StringJ(System.Text.Encoding.ASCII.GetString(Convert.FromBase64String(svalue))).getBytes()); //return Base64.decode(bavalue); } catch (Exception e) { return(deflt); } }
/** * Appends a subsequence of the character sequence {@code csq} to the * target. This method works the same way as {@code * PrintWriter.print(csq.subsequence(start, end).toString())}. If {@code * csq} is {@code null}, then the specified subsequence of the string "null" * will be written to the target. * * @param csq * the character sequence appended to the target. * @param start * the index of the first char in the character sequence appended * to the target. * @param end * the index of the character following the last character of the * subsequence appended to the target. * @return this writer. * @throws StringIndexOutOfBoundsException * if {@code start > end}, {@code start < 0}, {@code end < 0} or * either {@code start} or {@code end} are greater or equal than * the length of {@code csq}. */ public new PrintWriter append(java.lang.CharSequence csq, int start, int end) { if (null == csq) { csq = new java.lang.StringJ(TOKEN_NULL); } String output = csq.subSequence(start, end).toString(); write(output, 0, output.length()); return this; }
/** * Reading a column definition from file<br> * @param ff file handle (correctly positioned) * @param iCol index starts with 1 * @param locn offset to the current column * @return struct with column info */ internal static TsColumn readColdef(java.io.RandomAccessFile ff, String tableName, int iCol, int locn) //throws tinySQLException { try { // seek the position of the field definition data. // This information appears after the first 32 byte // table information, and lives in 32 byte chunks. // ff.seek((iCol - 1) * 32 + 32); // get the column name into a byte array // byte[] b = new byte[11]; ff.readFully(b); // convert the byte array to a String // Seek first 0x00 occurence and strip array after that // // some C-implementations do not set the remaining bytes // after the name to 0x00, so we have to correct this. //bool clear = false; int i = 0; while ((i < 11) && (b[i] != 0)) { i++; } while (i < 11) { b[i] = 0; i++; } String colName = (new java.lang.StringJ(b, Utils.encode)).trim(); // read in the column type which follows the 11 byte column name // byte[] c = new byte[1]; c[0] = ff.readByte(); String ftyp = new java.lang.StringJ(c, Utils.encode); // skip four bytes // ff.skipBytes(4); // get field length and precision which are in the two bytes following // the column type. // short flen = Utils.fixByte(ff.readByte()); // 16 short fdec = Utils.fixByte(ff.readByte()); // 17 if (ftyp.equals("N") & fdec == 0) { ftyp = "I"; } // bytes 18 - 31 are reserved // create a new tsColumn object and assign it the // attributes of the current field // if (TinySQLGlobals.DEBUG) { java.lang.SystemJ.outJ.println("Try and create tsColumn for " + colName); } TsColumn column = new TsColumn(colName); /* * The column type is now given as java.sql.Types constant */ column.type = typeToSQLType(ftyp); column.size = flen; column.decimalPlaces = fdec; column.position = locn + 1; // set the field position to the current column.tableName = tableName; return(column); } catch (Exception e) { throw new TinySQLException(e.getMessage()); } }
public void writeBytes(String s) { byte[] writeBuffer = new java.lang.StringJ(s).getBytes(); this.write(writeBuffer, 0, writeBuffer.Length); }
public void write(char c) { byte [] writeBuffer = new java.lang.StringJ("" + c).getBytes(); this.write(writeBuffer, 0, 1); }
public void writeBytes(String s) { byte[] writeBuffer = new java.lang.StringJ(s).getBytes(); this.write(writeBuffer, 0, writeBuffer.Length); }
public void write(char c) { byte [] writeBuffer = new java.lang.StringJ (""+c).getBytes(); this.write(writeBuffer, 0, 1); }
public void SetUp() { this.rootDir = "../../../"; }