Skip to content

Commit 32656a6

Browse files
committed
Format code
1 parent 3a536a1 commit 32656a6

2 files changed

Lines changed: 23 additions & 23 deletions

File tree

src/main/java/com/microsoft/sqlserver/jdbc/SQLServerBulkCSVFileRecord.java

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -212,43 +212,43 @@ private void initFileReader(InputStreamReader sr, String encoding, String demlim
212212
}
213213
}
214214

215-
/* RFC4180 specifies that rules for quoted fields. It allows quoted string data to contain newlines data
216-
provided the contents otherwise conforms to the rules for escaping quotes. For example, the following is valid:
217-
"a","b","c"
218-
"aaa","b <-- newline is retained in data field
219-
bb","c"
220-
"aa","bb","cc"
221-
222-
We cannot simply use fileReader.readLine() to read these records but instead must continue reading until we reach
223-
a newline that is not contained within quotes.
224-
*/
215+
/*
216+
* RFC4180 specifies that rules for quoted fields. It allows quoted string data to contain newlines data
217+
* provided the contents otherwise conforms to the rules for escaping quotes. For example, the following is valid:
218+
* "a","b","c"
219+
* "aaa","b <-- newline is retained in data field
220+
* bb","c"
221+
* "aa","bb","cc"
222+
* We cannot simply use fileReader.readLine() to read these records but instead must continue reading until we reach
223+
* a newline that is not contained within quotes.
224+
*/
225225
private String readLineEscapeDelimiters() throws SQLServerException {
226226
int quoteCount = 0;
227227
StringBuilder sb = new StringBuilder();
228228
try {
229229
int c;
230230
while ((c = fileReader.read()) != -1) {
231-
if((c == '\n' || c == '\r') && quoteCount % 2 == 0) { // newlines only end the record if we are not in quotes
232-
fileReader.mark(1);
233-
c = fileReader.read(); // we might have read \r of a \r\n, if so we need to read the \n as well
234-
if(c != '\n') {
235-
fileReader.reset(); // only delimited by \n, unread last char so it goes into the next record
236-
}
237-
break;
231+
if ((c == '\n' || c == '\r') && quoteCount % 2 == 0) { // newlines only end the record if we are not in quotes
232+
fileReader.mark(1);
233+
c = fileReader.read(); // we might have read \r of a \r\n, if so we need to read the \n as well
234+
if (c != '\n') {
235+
fileReader.reset(); // only delimited by \n, unread last char so it goes into the next record
236+
}
237+
break;
238238
}
239-
sb.append((char)c);
240-
if( c == '"') {
239+
sb.append((char) c);
240+
if (c == '"') {
241241
quoteCount++;
242242
}
243243
}
244244
if (c == -1 && quoteCount % 2 != 0) { // stream ended, but we are within quotes -- data problem
245-
throw new SQLServerException(SQLServerException.getErrString("R_InvalidCSVQuotes"),null,0,null);
245+
throw new SQLServerException(SQLServerException.getErrString("R_InvalidCSVQuotes"), null, 0, null);
246246
}
247-
if(c == -1) { // keep semantics of readLine() by returning a null when there is no more data
247+
if (c == -1) { // keep semantics of readLine() by returning a null when there is no more data
248248
return null;
249249
}
250250
} catch (IOException e) {
251-
throw new SQLServerException(e.getMessage(),null,0,e);
251+
throw new SQLServerException(e.getMessage(), null, 0, e);
252252
}
253253
return sb.toString();
254254
}

src/test/resources/BulkCopyCSVTestInputDelimiterEscape.csv

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@
1212
12@1997@"F
1313
o
1414
r
15-
d"@"E350"@"""Super"" ""luxurious"" ""truck"""@
15+
d"@"E350"@"""Super"" ""luxurious"" ""truck"""@

0 commit comments

Comments
 (0)