void () { synchronized (myBuffer) { if (myBuffer.length() == 0) return; // warning! Since myBuffer is reused, do not use myBuffer.toString() to fetch the string // because the created string will get StringBuffer's internal char array as a buffer which is possibly too large. final String s = myBuffer.substring(0, myBuffer.length()); myBuffer.setLength(0); textAvailable(s); } }