私は以下のコードを持っています:
public synchronized InputStream getResourceStream(final String name)
throws ResourceNotFoundException
{
if (org.apache.commons.lang.StringUtils.isEmpty(name))
{
throw new ResourceNotFoundException("DataSourceResourceLoader: Template name was empty or null");
}
Connection conn = null;
ResultSet rs = null;
PreparedStatement ps = null;
try
{
conn = openDbConnection();
ps = getStatement(conn, templateColumn, name);
rs = ps.executeQuery();
if (rs.next())
{
InputStream stream = rs.getBinaryStream(templateColumn);
if (stream == null)
{
throw new ResourceNotFoundException("DataSourceResourceLoader: "
+ "template column for '"
+ name + "' is null");
}
return new BufferedInputStream(stream);
}
else
{
throw new ResourceNotFoundException("DataSourceResourceLoader: "
+ "could not find resource '"
+ name + "'");
}
}
catch (SQLException sqle)
{
String msg = "DataSourceResourceLoader: database problem while getting resource '"
+ name + "': ";
log.error(msg, sqle);
throw new ResourceNotFoundException(msg);
}
catch (NamingException ne)
{
String msg = "DataSourceResourceLoader: database problem while getting resource '"
+ name + "': ";
log.error(msg, ne);
throw new ResourceNotFoundException(msg);
}
finally
{
closeResultSet(rs);
closeStatement(ps);
closeDbConnection(conn);
}
}
上記のメソッドの戻り値の型はInputStream
. 上記では、列の値を取得し InputStream stream = rs.getBinaryStream(templateColumn);
て同じものを返しています。今、私の要件は、もう 1 つの列の値を取得し、同じストリームで とともに返す必要があることですtemplateColumn
。どうやってやるの?
基本的に上記のロジックでは、以下のようにもう 1 行追加する必要があります。
InputStream stream2 = rs.getBinaryStream(oneMoreColumn);
単一のストリームで両方の値を返すことは可能ですか?
ありがとう!