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:
Eric J. Bowersox
2001-10-31 19:38:40 +00:00
parent f1584f3f4a
commit 597ebadf35
10 changed files with 391 additions and 98 deletions
@@ -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)