burlapoutput.java
来自「RESIN 3.2 最新源码」· Java 代码 · 共 965 行 · 第 1/2 页
JAVA
965 行
if (utcCalendar == null) { utcCalendar = Calendar.getInstance(TimeZone.getTimeZone("UTC")); date = new Date(); } date.setTime(time); utcCalendar.setTime(date); printDate(utcCalendar); print("</date>"); } /** * Writes a null value to the stream. * The null will be written with the following syntax * * <code><pre> * <null></null> * </pre></code> * * @param value the string value to write. */ public void writeNull() throws IOException { print("<null></null>"); } /** * Writes a string value to the stream using UTF-8 encoding. * The string will be written with the following syntax: * * <code><pre> * <string>string-value</string> * </pre></code> * * If the value is null, it will be written as * * <code><pre> * <null></null> * </pre></code> * * @param value the string value to write. */ public void writeString(String value) throws IOException { if (value == null) { print("<null></null>"); } else { print("<string>"); printString(value); print("</string>"); } } /** * Writes a string value to the stream using UTF-8 encoding. * The string will be written with the following syntax: * * <code><pre> * S b16 b8 string-value * </pre></code> * * If the value is null, it will be written as * * <code><pre> * N * </pre></code> * * @param value the string value to write. */ public void writeString(char []buffer, int offset, int length) throws IOException { if (buffer == null) { print("<null></null>"); } else { print("<string>"); printString(buffer, offset, length); print("</string>"); } } /** * Writes a byte array to the stream. * The array will be written with the following syntax: * * <code><pre> * <base64>bytes</base64> * </pre></code> * * If the value is null, it will be written as * * <code><pre> * <null></null> * </pre></code> * * @param value the string value to write. */ public void writeBytes(byte []buffer) throws IOException { if (buffer == null) print("<null></null>"); else writeBytes(buffer, 0, buffer.length); } /** * Writes a byte array to the stream. * The array will be written with the following syntax: * * <code><pre> * <base64>bytes</base64> * </pre></code> * * If the value is null, it will be written as * * <code><pre> * <null></null> * </pre></code> * * @param value the string value to write. */ public void writeBytes(byte []buffer, int offset, int length) throws IOException { if (buffer == null) { print("<null></null>"); } else { print("<base64>"); int i = 0; for (; i + 2 < length; i += 3) { if (i != 0 && (i & 0x3f) == 0) print('\n'); int v = (((buffer[offset + i] & 0xff) << 16) + ((buffer[offset + i + 1] & 0xff) << 8) + (buffer[offset + i + 2] & 0xff)); print(encode(v >> 18)); print(encode(v >> 12)); print(encode(v >> 6)); print(encode(v)); } if (i + 1 < length) { int v = (((buffer[offset + i] & 0xff) << 8) + (buffer[offset + i + 1] & 0xff)); print(encode(v >> 10)); print(encode(v >> 4)); print(encode(v << 2)); print('='); } else if (i < length) { int v = buffer[offset + i] & 0xff; print(encode(v >> 2)); print(encode(v << 4)); print('='); print('='); } print("</base64>"); } } /** * Writes a byte buffer to the stream. */ public void writeByteBufferStart() throws IOException { throw new UnsupportedOperationException(); } /** * Writes a byte buffer to the stream. * * <code><pre> * b b16 b18 bytes * </pre></code> */ public void writeByteBufferPart(byte []buffer, int offset, int length) throws IOException { throw new UnsupportedOperationException(); } /** * Writes a byte buffer to the stream. * * <code><pre> * b b16 b18 bytes * </pre></code> */ public void writeByteBufferEnd(byte []buffer, int offset, int length) throws IOException { throw new UnsupportedOperationException(); } /** * Encodes a digit */ private char encode(int d) { d &= 0x3f; if (d < 26) return (char) (d + 'A'); else if (d < 52) return (char) (d + 'a' - 26); else if (d < 62) return (char) (d + '0' - 52); else if (d == 62) return '+'; else return '/'; } /** * Writes a reference. * * <code><pre> * <ref>int</ref> * </pre></code> * * @param value the integer value to write. */ public void writeRef(int value) throws IOException { print("<ref>"); print(value); print("</ref>"); } /** * If the object has already been written, just write its ref. * * @return true if we're writing a ref. */ public boolean addRef(Object object) throws IOException { if (_refs == null) _refs = new IdentityHashMap(); Integer ref = (Integer) _refs.get(object); if (ref != null) { int value = ref.intValue(); writeRef(value); return true; } else { _refs.put(object, new Integer(_refs.size())); return false; } } /** * Removes a reference. */ public boolean removeRef(Object obj) throws IOException { if (_refs != null) { _refs.remove(obj); return true; } else return false; } /** * Replaces a reference from one object to another. */ public boolean replaceRef(Object oldRef, Object newRef) throws IOException { Integer value = (Integer) _refs.remove(oldRef); if (value != null) { _refs.put(newRef, value); return true; } else return false; } /** * Prints a string to the stream, encoded as UTF-8 * * @param v the string to print. */ public void printString(String v) throws IOException { printString(v, 0, v.length()); } /** * Prints a string to the stream, encoded as UTF-8 * * @param v the string to print. */ public void printString(String v, int offset, int length) throws IOException { for (int i = 0; i < length; i++) { char ch = v.charAt(i + offset); if (ch == '<') { os.write('&'); os.write('#'); os.write('6'); os.write('0'); os.write(';'); } else if (ch == '&') { os.write('&'); os.write('#'); os.write('3'); os.write('8'); os.write(';'); } else if (ch < 0x80) os.write(ch); else if (ch < 0x800) { os.write(0xc0 + ((ch >> 6) & 0x1f)); os.write(0x80 + (ch & 0x3f)); } else { os.write(0xe0 + ((ch >> 12) & 0xf)); os.write(0x80 + ((ch >> 6) & 0x3f)); os.write(0x80 + (ch & 0x3f)); } } } /** * Prints a string to the stream, encoded as UTF-8 * * @param v the string to print. */ public void printString(char []v, int offset, int length) throws IOException { for (int i = 0; i < length; i++) { char ch = v[i + offset]; if (ch < 0x80) os.write(ch); else if (ch < 0x800) { os.write(0xc0 + ((ch >> 6) & 0x1f)); os.write(0x80 + (ch & 0x3f)); } else { os.write(0xe0 + ((ch >> 12) & 0xf)); os.write(0x80 + ((ch >> 6) & 0x3f)); os.write(0x80 + (ch & 0x3f)); } } } /** * Prints a date. * * @param date the date to print. */ public void printDate(Calendar calendar) throws IOException { int year = calendar.get(Calendar.YEAR); os.write((char) ('0' + (year / 1000 % 10))); os.write((char) ('0' + (year / 100 % 10))); os.write((char) ('0' + (year / 10 % 10))); os.write((char) ('0' + (year % 10))); int month = calendar.get(Calendar.MONTH) + 1; os.write((char) ('0' + (month / 10 % 10))); os.write((char) ('0' + (month % 10))); int day = calendar.get(Calendar.DAY_OF_MONTH); os.write((char) ('0' + (day / 10 % 10))); os.write((char) ('0' + (day % 10))); os.write('T'); int hour = calendar.get(Calendar.HOUR_OF_DAY); os.write((char) ('0' + (hour / 10 % 10))); os.write((char) ('0' + (hour % 10))); int minute = calendar.get(Calendar.MINUTE); os.write((char) ('0' + (minute / 10 % 10))); os.write((char) ('0' + (minute % 10))); int second = calendar.get(Calendar.SECOND); os.write((char) ('0' + (second / 10 % 10))); os.write((char) ('0' + (second % 10))); int ms = calendar.get(Calendar.MILLISECOND); os.write('.'); os.write((char) ('0' + (ms / 100 % 10))); os.write((char) ('0' + (ms / 10 % 10))); os.write((char) ('0' + (ms % 10))); os.write('Z'); } /** * Prints a char to the stream. * * @param v the char to print. */ protected void print(char v) throws IOException { os.write(v); } /** * Prints an integer to the stream. * * @param v the integer to print. */ protected void print(int v) throws IOException { print(String.valueOf(v)); } /** * Prints a long to the stream. * * @param v the long to print. */ protected void print(long v) throws IOException { print(String.valueOf(v)); } /** * Prints a double to the stream. * * @param v the double to print. */ protected void print(double v) throws IOException { print(String.valueOf(v)); } /** * Prints a string as ascii to the stream. Used for tags, etc. * that are known to the ascii. * * @param s the ascii string to print. */ protected void print(String s) throws IOException { int len = s.length(); for (int i = 0; i < len; i++) { int ch = s.charAt(i); os.write(ch); } }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?