Skip to content
Snippets Groups Projects
Commit f1f9b243 authored by Mick Jordan's avatar Mick Jordan
Browse files

add connection forceOpens

parent 432f3745
No related branches found
No related tags found
No related merge requests found
...@@ -742,11 +742,22 @@ public class ForeignFunctions { ...@@ -742,11 +742,22 @@ public class ForeignFunctions {
quoteSet = s; quoteSet = s;
} }
} }
boolean wasOpen = true;
try { try {
wasOpen = conn.forceOpen("r");
return CountFields.execute(conn, sepChar, quoteSet, nskip, RRuntime.fromLogical(blskip), comChar); return CountFields.execute(conn, sepChar, quoteSet, nskip, RRuntime.fromLogical(blskip), comChar);
} catch (IllegalStateException | IOException ex) { } catch (IllegalStateException | IOException ex) {
errorProfile.enter(); errorProfile.enter();
throw RError.error(getEncapsulatingSourceSection(), RError.Message.GENERIC, ex.getMessage()); throw RError.error(getEncapsulatingSourceSection(), RError.Message.GENERIC, ex.getMessage());
} finally {
if (!wasOpen) {
try {
conn.internalClose();
} catch (IOException ex) {
errorProfile.enter();
throw RError.error(getEncapsulatingSourceSection(), RError.Message.GENERIC, ex.getMessage());
}
}
} }
} }
...@@ -761,11 +772,22 @@ public class ForeignFunctions { ...@@ -761,11 +772,22 @@ public class ForeignFunctions {
Object[] argValues = args.getValues(); Object[] argValues = args.getValues();
RConnection conn = (RConnection) argValues[0]; RConnection conn = (RConnection) argValues[0];
int nlines = castInt(frame, castVector(frame, argValues[1])); int nlines = castInt(frame, castVector(frame, argValues[1]));
boolean wasOpen = true;
try { try {
wasOpen = conn.forceOpen("r");
return RDataFactory.createStringVector(conn.readLines(nlines), RDataFactory.COMPLETE_VECTOR); return RDataFactory.createStringVector(conn.readLines(nlines), RDataFactory.COMPLETE_VECTOR);
} catch (IOException ex) { } catch (IOException ex) {
errorProfile.enter(); errorProfile.enter();
throw RError.error(getEncapsulatingSourceSection(), RError.Message.ERROR_READING_CONNECTION, ex.getMessage()); throw RError.error(getEncapsulatingSourceSection(), RError.Message.ERROR_READING_CONNECTION, ex.getMessage());
} finally {
if (!wasOpen) {
try {
conn.internalClose();
} catch (IOException ex) {
errorProfile.enter();
throw RError.error(getEncapsulatingSourceSection(), RError.Message.GENERIC, ex.getMessage());
}
}
} }
} }
...@@ -835,12 +857,12 @@ public class ForeignFunctions { ...@@ -835,12 +857,12 @@ public class ForeignFunctions {
controlVisibility(); controlVisibility();
Object[] argValues = args.getValues(); Object[] argValues = args.getValues();
Object conArg = argValues[1]; Object conArg = argValues[1];
RConnection con; RConnection conn;
if (!(conArg instanceof RConnection)) { if (!(conArg instanceof RConnection)) {
errorProfile.enter(); errorProfile.enter();
throw RError.error(getEncapsulatingSourceSection(), RError.Message.GENERIC, "'file' is not a connection"); throw RError.error(getEncapsulatingSourceSection(), RError.Message.GENERIC, "'file' is not a connection");
} else { } else {
con = (RConnection) conArg; conn = (RConnection) conArg;
} }
// TODO check connection writeable // TODO check connection writeable
...@@ -899,11 +921,22 @@ public class ForeignFunctions { ...@@ -899,11 +921,22 @@ public class ForeignFunctions {
quoteCol[qi - 1] = true; quoteCol[qi - 1] = true;
} }
} }
boolean wasOpen = true;
try { try {
WriteTable.execute(con, argValues[0], nr, nc, rnamesArg, csep, ceol, cna, cdec.charAt(0), RRuntime.fromLogical(qmethod), quoteCol, quoteRn); wasOpen = conn.forceOpen("wt");
WriteTable.execute(conn, argValues[0], nr, nc, rnamesArg, csep, ceol, cna, cdec.charAt(0), RRuntime.fromLogical(qmethod), quoteCol, quoteRn);
} catch (IOException | IllegalArgumentException ex) { } catch (IOException | IllegalArgumentException ex) {
errorProfile.enter(); errorProfile.enter();
throw RError.error(getEncapsulatingSourceSection(), RError.Message.GENERIC, ex.getMessage()); throw RError.error(getEncapsulatingSourceSection(), RError.Message.GENERIC, ex.getMessage());
} finally {
if (!wasOpen) {
try {
conn.internalClose();
} catch (IOException ex) {
errorProfile.enter();
throw RError.error(getEncapsulatingSourceSection(), RError.Message.GENERIC, ex.getMessage());
}
}
} }
return RNull.instance; return RNull.instance;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment