cleaned up some code - replaced a bunch of copy loops with calls to the new
IOUtil class methods, added some javadocs to IOUtil, StringUtil, and AnyCharMatcher
This commit is contained in:
@@ -21,6 +21,7 @@ import java.io.*;
|
||||
import java.sql.*;
|
||||
import java.util.*;
|
||||
import org.apache.log4j.*;
|
||||
import com.silverwrist.util.IOUtil;
|
||||
import com.silverwrist.venice.db.*;
|
||||
import com.silverwrist.venice.core.*;
|
||||
|
||||
@@ -107,23 +108,8 @@ class ImageStore implements BinaryData
|
||||
} // end if
|
||||
|
||||
// Since the InputStream we get from JDBC will probably go away when the connection is dropped, we
|
||||
// need to make a temporary copy of it, to a ByteArrayOutputStream.
|
||||
InputStream sqldata = rs.getBinaryStream(1);
|
||||
ByteArrayOutputStream copy = new ByteArrayOutputStream(length);
|
||||
byte[] buffer = new byte[4096];
|
||||
int rd = sqldata.read(buffer);
|
||||
while (rd>=0)
|
||||
{ // write, then read again
|
||||
if (rd>0)
|
||||
copy.write(buffer,0,rd);
|
||||
rd = sqldata.read(buffer);
|
||||
|
||||
} // end while
|
||||
|
||||
// Close both our streams, making sure we create the stream we need for the return value.
|
||||
sqldata.close();
|
||||
rc = new ByteArrayInputStream(copy.toByteArray());
|
||||
copy.close();
|
||||
// need to make a temporary copy of it.
|
||||
rc = new ByteArrayInputStream(IOUtil.load(rs.getBinaryStream(1)));
|
||||
|
||||
} // end try
|
||||
catch (SQLException e)
|
||||
|
||||
@@ -22,6 +22,7 @@ import java.sql.*;
|
||||
import java.util.*;
|
||||
import java.util.zip.*;
|
||||
import org.apache.log4j.*;
|
||||
import com.silverwrist.util.IOUtil;
|
||||
import com.silverwrist.util.StringUtil;
|
||||
import com.silverwrist.venice.db.*;
|
||||
import com.silverwrist.venice.security.AuditRecord;
|
||||
@@ -432,21 +433,8 @@ class TopicMessageUserContextImpl implements TopicMessageContext
|
||||
|
||||
} // end switch
|
||||
|
||||
ByteArrayOutputStream copy = new ByteArrayOutputStream(datalen);
|
||||
byte[] buffer = new byte[4096];
|
||||
int rd = real_input.read(buffer);
|
||||
while (rd>=0)
|
||||
{ // write, then read again
|
||||
if (rd>0)
|
||||
copy.write(buffer,0,rd);
|
||||
rd = real_input.read(buffer);
|
||||
|
||||
} // end while
|
||||
|
||||
// Close both our streams, making sure we create the stream we need for the return value.
|
||||
real_input.close();
|
||||
rc = new ByteArrayInputStream(copy.toByteArray());
|
||||
copy.close();
|
||||
// Copy to a new stream.
|
||||
rc = new ByteArrayInputStream(IOUtil.load(real_input));
|
||||
|
||||
} // end try
|
||||
catch (SQLException e)
|
||||
|
||||
@@ -555,7 +555,7 @@ public class RenderConfig implements ColorSelectors
|
||||
synchronized String loadStyleSheetData() throws IOException
|
||||
{
|
||||
// Load the stylesheet data.
|
||||
StringBuffer raw_data = IOUtil.load(stylesheet);
|
||||
StringBuffer raw_data = IOUtil.loadText(stylesheet);
|
||||
stylesheet_time = stylesheet.lastModified();
|
||||
|
||||
// Set up the replacements map to replace the various parameters.
|
||||
|
||||
@@ -23,6 +23,7 @@ import java.text.DateFormat;
|
||||
import javax.servlet.*;
|
||||
import javax.servlet.http.*;
|
||||
import org.apache.log4j.*;
|
||||
import com.silverwrist.util.IOUtil;
|
||||
import com.silverwrist.util.StringUtil;
|
||||
import com.silverwrist.venice.core.DataException;
|
||||
import com.silverwrist.venice.core.IDUtils;
|
||||
@@ -462,16 +463,7 @@ public class RenderData implements ColorSelectors
|
||||
response.setHeader("Content-Disposition","attachment; filename=\"" + filename + "\";");
|
||||
|
||||
// Copy the contents of the "data" stream to the output.
|
||||
ServletOutputStream stm = response.getOutputStream();
|
||||
byte[] buffer = new byte[4096];
|
||||
int rd = data.read(buffer);
|
||||
while (rd>=0)
|
||||
{ // simple read-write loop to shove data out the door
|
||||
if (rd>0)
|
||||
stm.write(buffer,0,rd);
|
||||
rd = data.read(buffer);
|
||||
|
||||
} // end while
|
||||
IOUtil.copy(data,response.getOutputStream());
|
||||
|
||||
} // end sendBinaryData
|
||||
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
package com.silverwrist.venice.servlets.format;
|
||||
|
||||
import java.io.*;
|
||||
import com.silverwrist.util.IOUtil;
|
||||
import com.silverwrist.util.cachemap.CacheMap;
|
||||
|
||||
public class StaticRender implements ContentRender
|
||||
@@ -94,21 +95,10 @@ public class StaticRender implements ContentRender
|
||||
} // end if
|
||||
|
||||
// Read in the whole thing.
|
||||
StringBuffer raw_file = new StringBuffer();
|
||||
StringBuffer raw_file;
|
||||
try
|
||||
{ // read in from the file
|
||||
FileReader rdr = new FileReader(real_path);
|
||||
char[] buffer = new char[4096];
|
||||
int rd = rdr.read(buffer);
|
||||
while (rd>=0)
|
||||
{ // read in the raw characters
|
||||
if (rd>0)
|
||||
raw_file.append(buffer,0,rd);
|
||||
rd = rdr.read(buffer);
|
||||
|
||||
} // end while
|
||||
|
||||
rdr.close();
|
||||
raw_file = IOUtil.loadText(new File(real_path));
|
||||
|
||||
} // end try
|
||||
catch (IOException ioe)
|
||||
|
||||
Reference in New Issue
Block a user