Prefer StringBuilder over StringBuffer
The latter has unnecessary synchronization. Found via error-prone.
This commit is contained in:
parent
f7c048e5b4
commit
278e93880e
|
@ -37,7 +37,7 @@ public class HandlerState {
|
||||||
/**
|
/**
|
||||||
* Buffer for saving characters.
|
* Buffer for saving characters.
|
||||||
*/
|
*/
|
||||||
protected StringBuffer contentBuf;
|
protected StringBuilder contentBuf;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Temporarily saved objects.
|
* Temporarily saved objects.
|
||||||
|
@ -97,7 +97,7 @@ public class HandlerState {
|
||||||
return third;
|
return third;
|
||||||
}
|
}
|
||||||
|
|
||||||
public StringBuffer getContentBuf() {
|
public StringBuilder getContentBuf() {
|
||||||
return contentBuf;
|
return contentBuf;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -33,7 +33,7 @@ public class SyndHandler extends DefaultHandler {
|
||||||
@Override
|
@Override
|
||||||
public void startElement(String uri, String localName, String qName,
|
public void startElement(String uri, String localName, String qName,
|
||||||
Attributes attributes) throws SAXException {
|
Attributes attributes) throws SAXException {
|
||||||
state.contentBuf = new StringBuffer();
|
state.contentBuf = new StringBuilder();
|
||||||
Namespace handler = getHandlingNamespace(uri, qName);
|
Namespace handler = getHandlingNamespace(uri, qName);
|
||||||
if (handler != null) {
|
if (handler != null) {
|
||||||
SyndElement element = handler.handleElementStart(localName, state,
|
SyndElement element = handler.handleElementStart(localName, state,
|
||||||
|
|
|
@ -43,7 +43,7 @@ public class ChapterReader extends ID3Reader {
|
||||||
currentChapter = null;
|
currentChapter = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
StringBuffer elementId = new StringBuffer();
|
StringBuilder elementId = new StringBuilder();
|
||||||
readISOString(elementId, input, Integer.MAX_VALUE);
|
readISOString(elementId, input, Integer.MAX_VALUE);
|
||||||
char[] startTimeSource = readBytes(input, 4);
|
char[] startTimeSource = readBytes(input, 4);
|
||||||
long startTime = ((int) startTimeSource[0] << 24)
|
long startTime = ((int) startTimeSource[0] << 24)
|
||||||
|
@ -54,7 +54,7 @@ public class ChapterReader extends ID3Reader {
|
||||||
return ID3Reader.ACTION_DONT_SKIP;
|
return ID3Reader.ACTION_DONT_SKIP;
|
||||||
case FRAME_ID_TITLE:
|
case FRAME_ID_TITLE:
|
||||||
if (currentChapter != null && currentChapter.getTitle() == null) {
|
if (currentChapter != null && currentChapter.getTitle() == null) {
|
||||||
StringBuffer title = new StringBuffer();
|
StringBuilder title = new StringBuilder();
|
||||||
readString(title, input, header.getSize());
|
readString(title, input, header.getSize());
|
||||||
currentChapter
|
currentChapter
|
||||||
.setTitle(title.toString());
|
.setTitle(title.toString());
|
||||||
|
@ -67,7 +67,7 @@ public class ChapterReader extends ID3Reader {
|
||||||
if (currentChapter != null) {
|
if (currentChapter != null) {
|
||||||
// skip description
|
// skip description
|
||||||
int descriptionLength = readString(null, input, header.getSize());
|
int descriptionLength = readString(null, input, header.getSize());
|
||||||
StringBuffer link = new StringBuffer();
|
StringBuilder link = new StringBuilder();
|
||||||
readISOString(link, input, header.getSize() - descriptionLength);
|
readISOString(link, input, header.getSize() - descriptionLength);
|
||||||
String decodedLink = URLDecoder.decode(link.toString(), "UTF-8");
|
String decodedLink = URLDecoder.decode(link.toString(), "UTF-8");
|
||||||
|
|
||||||
|
|
|
@ -170,7 +170,7 @@ public class ID3Reader {
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected int readString(StringBuffer buffer, InputStream input, int max) throws IOException,
|
protected int readString(StringBuilder buffer, InputStream input, int max) throws IOException,
|
||||||
ID3ReaderException {
|
ID3ReaderException {
|
||||||
if (max > 0) {
|
if (max > 0) {
|
||||||
char[] encoding = readBytes(input, 1);
|
char[] encoding = readBytes(input, 1);
|
||||||
|
@ -191,7 +191,7 @@ public class ID3Reader {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected int readISOString(StringBuffer buffer, InputStream input, int max)
|
protected int readISOString(StringBuilder buffer, InputStream input, int max)
|
||||||
throws IOException, ID3ReaderException {
|
throws IOException, ID3ReaderException {
|
||||||
|
|
||||||
int bytesRead = 0;
|
int bytesRead = 0;
|
||||||
|
@ -204,7 +204,7 @@ public class ID3Reader {
|
||||||
return bytesRead;
|
return bytesRead;
|
||||||
}
|
}
|
||||||
|
|
||||||
private int readUnicodeString(StringBuffer strBuffer, InputStream input, int max, Charset charset)
|
private int readUnicodeString(StringBuilder strBuffer, InputStream input, int max, Charset charset)
|
||||||
throws IOException, ID3ReaderException {
|
throws IOException, ID3ReaderException {
|
||||||
byte[] buffer = new byte[max];
|
byte[] buffer = new byte[max];
|
||||||
int c, cZero = -1;
|
int c, cZero = -1;
|
||||||
|
|
Loading…
Reference in New Issue