Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -321,24 +321,20 @@ public void writeTimestamp(java.sql.Timestamp x) throws SQLException {
* use by a <code>SQLData</code> object attempting to write the attribute
* values of a UDT to the database.
*/
@SuppressWarnings("unchecked")
public void writeCharacterStream(java.io.Reader x) throws SQLException {
BufferedReader bufReader = new BufferedReader(x);
try {
int i;
while( (i = bufReader.read()) != -1 ) {
BufferedReader bufReader = new BufferedReader(x);
try {
int i;
while ((i = bufReader.read()) != -1) {
Copy link
Contributor

@RogerRiggs RogerRiggs Sep 26, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the single character read really necessary?
BufferedReader.readLine() returns null on EOF.
It seems plausable that only the readLine and writeString are needed in the loop.

Similarly, for the read loops below for InputStreams and binary stream.
The BufferedReader and readline can be used for the binary streams by constructing with the ASCII Charset.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this single character is \n, then direct replacing with readLine would change behavior of the method.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see your point and this PR isn't the place to figure out why a single newline in the attributes Vector would be significant vs an empty string or no entry.

char ch = (char)i;
StringBuffer strBuf = new StringBuffer();
strBuf.append(ch);

String str = new String(strBuf);
String strLine = bufReader.readLine();

writeString(str.concat(strLine));
}
} catch(IOException ioe) {
writeString(ch + strLine);
}
} catch (IOException ioe) {

}
}
}

/**
Expand All @@ -351,23 +347,17 @@ public void writeCharacterStream(java.io.Reader x) throws SQLException {
* use by a <code>SQLData</code> object attempting to write the attribute
* values of a UDT to the database.
*/
@SuppressWarnings("unchecked")
public void writeAsciiStream(java.io.InputStream x) throws SQLException {
BufferedReader bufReader = new BufferedReader(new InputStreamReader(x));
try {
int i;
while( (i=bufReader.read()) != -1 ) {
BufferedReader bufReader = new BufferedReader(new InputStreamReader(x));
try {
int i;
while ((i = bufReader.read()) != -1) {
char ch = (char)i;

StringBuffer strBuf = new StringBuffer();
strBuf.append(ch);

String str = new String(strBuf);
String strLine = bufReader.readLine();

writeString(str.concat(strLine));
writeString(ch + strLine);
}
}catch(IOException ioe) {
} catch (IOException ioe) {
throw new SQLException(ioe.getMessage());
}
}
Expand All @@ -381,23 +371,18 @@ public void writeAsciiStream(java.io.InputStream x) throws SQLException {
* use by a <code>SQLData</code> object attempting to write the attribute
* values of a UDT to the database.
*/
@SuppressWarnings("unchecked")
public void writeBinaryStream(java.io.InputStream x) throws SQLException {
BufferedReader bufReader = new BufferedReader(new InputStreamReader(x));
try {
int i;
while( (i=bufReader.read()) != -1 ) {
BufferedReader bufReader = new BufferedReader(new InputStreamReader(x));
try {
int i;
while ((i = bufReader.read()) != -1) {
char ch = (char)i;

StringBuffer strBuf = new StringBuffer();
strBuf.append(ch);

String str = new String(strBuf);
String strLine = bufReader.readLine();

writeString(str.concat(strLine));
}
} catch(IOException ioe) {
writeString(ch + strLine);
}
} catch (IOException ioe) {
throw new SQLException(ioe.getMessage());
}
}
Expand Down