public XmlSerializer text(char[] buf, int start, int len) throws IOException, IllegalArgumentException, IllegalStateException { if (mInTag) { append(">"); mInTag = false; } escapeAndAppendString(buf, start, len); if (mIndent) { mLineStart = buf[start+len-1] == '\n'; } return this; }
public XmlSerializer startTag(String namespace, String name) throws IOException, IllegalArgumentException, IllegalStateException { if (mInTag) { append(">\n"); } if (mIndent) { appendIndent(mNesting); } mNesting++; append('<'); if (namespace != null) { append(namespace); append(':'); } append(name); mInTag = true; mLineStart = false; return this; }
private void append(String str, int i, final int length) throws IOException { if (length > BUFFER_LEN) { final int end = i + length; while (i < end) { int next = i + BUFFER_LEN; append(str, i, next<end ? BUFFER_LEN : (end-i)); i = next; } return; } int pos = mPos; if ((pos+length) > BUFFER_LEN) { flush(); pos = mPos; } str.getChars(i, i+length, mText, pos); mPos = pos + length; }
private void escapeAndAppendString(char[] buf, int start, int len) throws IOException { final char NE = (char)ESCAPE_TABLE.length; final String[] escapes = ESCAPE_TABLE; int end = start+len; int lastPos = start; int pos; for (pos=start; pos<end; pos++) { char c = buf[pos]; if (c >= NE) continue; String escape = escapes[c]; if (escape == null) continue; if (lastPos < pos) append(buf, lastPos, pos-lastPos); lastPos = pos + 1; append(escape); } if (lastPos < pos) append(buf, lastPos, pos-lastPos); }
private void append(char c) throws IOException { int pos = mPos; if (pos >= (BUFFER_LEN-1)) { flush(); pos = mPos; } mText[pos] = c; mPos = pos+1; }
private void writeUserListLocked() { FileOutputStream fos = null; AtomicFile userListFile = new AtomicFile(mUserListFile); try { fos = userListFile.startWrite(); final BufferedOutputStream bos = new BufferedOutputStream(fos); // XmlSerializer serializer = XmlUtils.serializerInstance(); final XmlSerializer serializer = new FastXmlSerializer(); serializer.setOutput(bos, "utf-8"); serializer.startDocument(null, true); serializer.setFeature("http://xmlpull.org/v1/doc/features.html#indent-output", true); serializer.startTag(null, TAG_USERS); serializer.attribute(null, ATTR_NEXT_SERIAL_NO, Integer.toString(mNextSerialNumber)); serializer.attribute(null, ATTR_USER_VERSION, Integer.toString(mUserVersion)); for (int i = 0; i < mUsers.size(); i++) { VUserInfo user = mUsers.valueAt(i); serializer.startTag(null, TAG_USER); serializer.attribute(null, ATTR_ID, Integer.toString(user.id)); serializer.endTag(null, TAG_USER); } serializer.endTag(null, TAG_USERS); serializer.endDocument(); userListFile.finishWrite(fos); } catch (Exception e) { userListFile.failWrite(fos); VLog.e(LOG_TAG, "Error writing user list"); } }
public void flush() throws IOException { //Log.i("PackageManager", "flush mPos=" + mPos); if (mPos > 0) { if (mOutputStream != null) { CharBuffer charBuffer = CharBuffer.wrap(mText, 0, mPos); CoderResult result = mCharset.encode(charBuffer, mBytes, true); while (true) { if (result.isError()) { throw new IOException(result.toString()); } else if (result.isOverflow()) { flushBytes(); result = mCharset.encode(charBuffer, mBytes, true); continue; } break; } flushBytes(); mOutputStream.flush(); } else { mWriter.write(mText, 0, mPos); mWriter.flush(); } mPos = 0; } }
private void append(String str) throws IOException { append(str, 0, str.length()); }
public void endDocument() throws IOException, IllegalArgumentException, IllegalStateException { flush(); }
final XmlSerializer serializer = new FastXmlSerializer(); serializer.setOutput(bos, "utf-8"); serializer.startDocument(null, true);
public void flush() throws IOException { //Log.i("PackageManager", "flush mPos=" + mPos); if (mPos > 0) { if (mOutputStream != null) { CharBuffer charBuffer = CharBuffer.wrap(mText, 0, mPos); CoderResult result = mCharset.encode(charBuffer, mBytes, true); while (true) { if (result.isError()) { throw new IOException(result.toString()); } else if (result.isOverflow()) { flushBytes(); result = mCharset.encode(charBuffer, mBytes, true); continue; } break; } flushBytes(); mOutputStream.flush(); } else { mWriter.write(mText, 0, mPos); mWriter.flush(); } mPos = 0; } }
public XmlSerializer attribute(String namespace, String name, String value) throws IOException, IllegalArgumentException, IllegalStateException { append(' '); if (namespace != null) { append(namespace); append(':'); } append(name); append("=\""); escapeAndAppendString(value); append('"'); mLineStart = false; return this; }
public XmlSerializer endTag(String namespace, String name) throws IOException, IllegalArgumentException, IllegalStateException { mNesting--; if (mInTag) { append(" />\n"); } else { if (mIndent && mLineStart) { appendIndent(mNesting); } append("</"); if (namespace != null) { append(namespace); append(':'); } append(name); append(">\n"); } mLineStart = true; mInTag = false; return this; }
private void append(char[] buf, int i, final int length) throws IOException { if (length > BUFFER_LEN) { final int end = i + length; while (i < end) { int next = i + BUFFER_LEN; append(buf, i, next<end ? BUFFER_LEN : (end-i)); i = next; } return; } int pos = mPos; if ((pos+length) > BUFFER_LEN) { flush(); pos = mPos; } System.arraycopy(buf, i, mText, pos, length); mPos = pos + length; }
private void escapeAndAppendString(final String string) throws IOException { final int N = string.length(); final char NE = (char)ESCAPE_TABLE.length; final String[] escapes = ESCAPE_TABLE; int lastPos = 0; int pos; for (pos=0; pos<N; pos++) { char c = string.charAt(pos); if (c >= NE) continue; String escape = escapes[c]; if (escape == null) continue; if (lastPos < pos) append(string, lastPos, pos-lastPos); lastPos = pos + 1; append(escape); } if (lastPos < pos) append(string, lastPos, pos-lastPos); }
private void append(char c) throws IOException { int pos = mPos; if (pos >= (BUFFER_LEN-1)) { flush(); pos = mPos; } mText[pos] = c; mPos = pos+1; }
private void writeUserListLocked() { FileOutputStream fos = null; AtomicFile userListFile = new AtomicFile(mUserListFile); try { fos = userListFile.startWrite(); final BufferedOutputStream bos = new BufferedOutputStream(fos); // XmlSerializer serializer = XmlUtils.serializerInstance(); final XmlSerializer serializer = new FastXmlSerializer(); serializer.setOutput(bos, "utf-8"); serializer.startDocument(null, true); serializer.setFeature("http://xmlpull.org/v1/doc/features.html#indent-output", true); serializer.startTag(null, TAG_USERS); serializer.attribute(null, ATTR_NEXT_SERIAL_NO, Integer.toString(mNextSerialNumber)); serializer.attribute(null, ATTR_USER_VERSION, Integer.toString(mUserVersion)); for (int i = 0; i < mUsers.size(); i++) { VUserInfo user = mUsers.valueAt(i); serializer.startTag(null, TAG_USER); serializer.attribute(null, ATTR_ID, Integer.toString(user.id)); serializer.endTag(null, TAG_USER); } serializer.endTag(null, TAG_USERS); serializer.endDocument(); userListFile.finishWrite(fos); } catch (Exception e) { userListFile.failWrite(fos); VLog.e(LOG_TAG, "Error writing user list"); } }
public void flush() throws IOException { //Log.i("PackageManager", "flush mPos=" + mPos); if (mPos > 0) { if (mOutputStream != null) { CharBuffer charBuffer = CharBuffer.wrap(mText, 0, mPos); CoderResult result = mCharset.encode(charBuffer, mBytes, true); while (true) { if (result.isError()) { throw new IOException(result.toString()); } else if (result.isOverflow()) { flushBytes(); result = mCharset.encode(charBuffer, mBytes, true); continue; } break; } flushBytes(); mOutputStream.flush(); } else { mWriter.write(mText, 0, mPos); mWriter.flush(); } mPos = 0; } }
public XmlSerializer text(String text) throws IOException, IllegalArgumentException, IllegalStateException { if (mInTag) { append(">"); mInTag = false; } escapeAndAppendString(text); if (mIndent) { mLineStart = text.length() > 0 && (text.charAt(text.length()-1) == '\n'); } return this; }
public XmlSerializer startTag(String namespace, String name) throws IOException, IllegalArgumentException, IllegalStateException { if (mInTag) { append(">\n"); } if (mIndent) { appendIndent(mNesting); } mNesting++; append('<'); if (namespace != null) { append(namespace); append(':'); } append(name); mInTag = true; mLineStart = false; return this; }