@Override public long writeToFileAtURL( LocalFilesystemURL inputURL, String data, int offset, boolean isBinary) throws IOException, NoModificationAllowedException { boolean append = false; if (offset > 0) { this.truncateFileAtURL(inputURL, offset); append = true; } byte[] rawData; if (isBinary) { rawData = Base64.decode(data, Base64.DEFAULT); } else { rawData = data.getBytes(); } ByteArrayInputStream in = new ByteArrayInputStream(rawData); try { byte buff[] = new byte[rawData.length]; FileOutputStream out = new FileOutputStream(this.filesystemPathForURL(inputURL), append); try { in.read(buff, 0, buff.length); out.write(buff, 0, rawData.length); out.flush(); } finally { // Always close the output out.close(); } broadcastNewFile(inputURL); } catch (NullPointerException e) { // This is a bug in the Android implementation of the Java Stack NoModificationAllowedException realException = new NoModificationAllowedException(inputURL.toString()); throw realException; } return rawData.length; }