private void maybeDeleteTempFile(Object stream) { streamList.remove(stream); if (!inmem && tempFile != null && streamList.isEmpty() && allowDeleteOfFile) { if (currentStream != null) { try { currentStream.close(); postClose(); } catch (Exception e) { //ignore } } deleteTempFile(); currentStream = new LoadingCharArrayWriter(); inmem = true; } }
if (currentStream instanceof LoadingCharArrayWriter) { LoadingCharArrayWriter s = (LoadingCharArrayWriter)currentStream; out.append(s.rawCharArray(), 0, (int)limit); } else { throw new IOException("Unknown format of currentStream");
public void writeCacheTo(StringBuilder out) throws IOException { flush(); if (inmem) { if (currentStream instanceof LoadingCharArrayWriter) { LoadingCharArrayWriter lcaw = (LoadingCharArrayWriter)currentStream; out.append(lcaw.rawCharArray(), 0, lcaw.size()); } else { throw new IOException("Unknown format of currentStream"); } } else { // read the file Reader r = createInputStreamReader(tempFile); try { char chars[] = new char[1024]; int x = r.read(chars); while (x != -1) { out.append(chars, 0, x); x = r.read(chars); } } finally { if (r != null) { r.close(); } } } }
out = new LoadingCharArrayWriter(); if (currentStream instanceof LoadingCharArrayWriter) { LoadingCharArrayWriter byteOut = (LoadingCharArrayWriter) currentStream; if (copyOldContent && byteOut.size() > 0) { byteOut.writeTo(out);
out = new LoadingCharArrayWriter(); if (currentStream instanceof LoadingCharArrayWriter) { LoadingCharArrayWriter byteOut = (LoadingCharArrayWriter) currentStream; if (copyOldContent && byteOut.size() > 0) { byteOut.writeTo(out);
out = new LoadingCharArrayWriter(); if (currentStream instanceof LoadingCharArrayWriter) { LoadingCharArrayWriter byteOut = (LoadingCharArrayWriter) currentStream; if (copyOldContent && byteOut.size() > 0) { byteOut.writeTo(out);
if (currentStream instanceof LoadingCharArrayWriter) { LoadingCharArrayWriter lcaw = (LoadingCharArrayWriter)currentStream; return new CharArrayReader(lcaw.rawCharArray(), 0, lcaw.size()); } else { return null;
if (currentStream instanceof LoadingCharArrayWriter) { LoadingCharArrayWriter lcaw = (LoadingCharArrayWriter)currentStream; return new CharArrayReader(lcaw.rawCharArray(), 0, lcaw.size()); } else { return null;
out = new LoadingCharArrayWriter(); if (currentStream instanceof LoadingCharArrayWriter) { LoadingCharArrayWriter byteOut = (LoadingCharArrayWriter) currentStream; if (copyOldContent && byteOut.size() > 0) { byteOut.writeTo(out);
if (currentStream instanceof LoadingCharArrayWriter) { LoadingCharArrayWriter s = (LoadingCharArrayWriter)currentStream; out.append(s.rawCharArray(), 0, (int)limit); } else { throw new IOException("Unknown format of currentStream");
if (currentStream instanceof LoadingCharArrayWriter) { LoadingCharArrayWriter lcaw = (LoadingCharArrayWriter)currentStream; return new CharArrayReader(lcaw.rawCharArray(), 0, lcaw.size());
if (currentStream instanceof LoadingCharArrayWriter) { LoadingCharArrayWriter s = (LoadingCharArrayWriter)currentStream; out.append(s.rawCharArray(), 0, (int)limit); } else { throw new IOException("Unknown format of currentStream");
if (currentStream instanceof LoadingCharArrayWriter) { LoadingCharArrayWriter lcaw = (LoadingCharArrayWriter)currentStream; return new CharArrayReader(lcaw.rawCharArray(), 0, lcaw.size());
if (currentStream instanceof LoadingCharArrayWriter) { LoadingCharArrayWriter s = (LoadingCharArrayWriter)currentStream; out.append(s.rawCharArray(), 0, (int)limit); } else { throw new IOException("Unknown format of currentStream");
private void createFileOutputStream() throws IOException { if (tempFileFailed) { return; } LoadingCharArrayWriter bout = (LoadingCharArrayWriter)currentStream; try { if (outputDir == null) { tempFile = FileUtils.createTempFile("cos", "tmp"); } else { tempFile = FileUtils.createTempFile("cos", "tmp", outputDir, false); } currentStream = createOutputStreamWriter(tempFile); bout.writeTo(currentStream); inmem = false; streamList.add(currentStream); } catch (Exception ex) { //Could be IOException or SecurityException or other issues. //Don't care what, just keep it in memory. tempFileFailed = true; if (currentStream != bout) { currentStream.close(); } deleteTempFile(); inmem = true; currentStream = bout; } }
public char[] getChars() throws IOException { flush(); if (inmem) { if (currentStream instanceof LoadingCharArrayWriter) { return ((LoadingCharArrayWriter)currentStream).toCharArray(); } else { throw new IOException("Unknown format of currentStream"); } } else { // read the file Reader fin = null; try { fin = createInputStreamReader(tempFile); CharArrayWriter out = new CharArrayWriter((int)tempFile.length()); char bytes[] = new char[1024]; int x = fin.read(bytes); while (x != -1) { out.write(bytes, 0, x); x = fin.read(bytes); } return out.toCharArray(); } finally { if (fin != null) { fin.close(); } } } }
private void createFileOutputStream() throws IOException { if (tempFileFailed) { return; } LoadingCharArrayWriter bout = (LoadingCharArrayWriter)currentStream; try { if (outputDir == null) { tempFile = FileUtils.createTempFile("cos", "tmp"); } else { tempFile = FileUtils.createTempFile("cos", "tmp", outputDir, false); } currentStream = createOutputStreamWriter(tempFile); bout.writeTo(currentStream); inmem = false; streamList.add(currentStream); } catch (Exception ex) { //Could be IOException or SecurityException or other issues. //Don't care what, just keep it in memory. tempFileFailed = true; if (currentStream != bout) { currentStream.close(); } deleteTempFile(); inmem = true; currentStream = bout; } }
public void writeCacheTo(Writer out) throws IOException { flush(); if (inmem) { if (currentStream instanceof LoadingCharArrayWriter) { ((LoadingCharArrayWriter)currentStream).writeTo(out); } else { throw new IOException("Unknown format of currentStream"); } } else { // read the file Reader fin = null; try { fin = createInputStreamReader(tempFile); char bytes[] = new char[1024]; int x = fin.read(bytes); while (x != -1) { out.write(bytes, 0, x); x = fin.read(bytes); } } finally { if (fin != null) { fin.close(); } } } }
public void writeCacheTo(Writer out) throws IOException { flush(); if (inmem) { if (currentStream instanceof LoadingCharArrayWriter) { ((LoadingCharArrayWriter)currentStream).writeTo(out); } else { throw new IOException("Unknown format of currentStream"); } } else { // read the file Reader fin = null; try { fin = createInputStreamReader(tempFile); char bytes[] = new char[1024]; int x = fin.read(bytes); while (x != -1) { out.write(bytes, 0, x); x = fin.read(bytes); } } finally { if (fin != null) { fin.close(); } } } }
public void writeCacheTo(StringBuilder out) throws IOException { flush(); if (inmem) { if (currentStream instanceof LoadingCharArrayWriter) { LoadingCharArrayWriter lcaw = (LoadingCharArrayWriter)currentStream; out.append(lcaw.rawCharArray(), 0, lcaw.size()); } else { throw new IOException("Unknown format of currentStream"); } } else { // read the file Reader r = createInputStreamReader(tempFile); try { char chars[] = new char[1024]; int x = r.read(chars); while (x != -1) { out.append(chars, 0, x); x = r.read(chars); } } finally { if (r != null) { r.close(); } } } }