Skip to content

Commit

Permalink
Merge pull request #10 from bobbywhitesfdc/WindowsCompatibility
Browse files Browse the repository at this point in the history
Update dependency version
  • Loading branch information
bobbywhitesfdc authored Jul 8, 2021
2 parents 59af43e + 570cb96 commit 358dd49
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 17 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5.8</version>
<version>4.5.13</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
Expand Down
36 changes: 20 additions & 16 deletions src/main/java/bobby/sfdc/prototype/util/SizeLimitedWriter.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

public class SizeLimitedWriter extends BufferedWriter {
public static final String SIZE_LIMIT_WOULD_BE_EXCEEDED = "Size Limit would be exceeded";
public static final long MEGABYTE = 1024*1024;
public static final long MEGABYTE = 1024L*1024L;
long bytesWritten=0;
long recordsWritten=0;
long lastMBAnnounced=0;
Expand All @@ -15,26 +15,28 @@ public class SizeLimitedWriter extends BufferedWriter {
public static final String NEWLINE_SEPARATOR = "\n"; // Hardwire Unix style for consistency across all platforms
public static final int NEWLINE_SEPARATOR_LEN = NEWLINE_SEPARATOR.length();

public SizeLimitedWriter(Writer out) {
public SizeLimitedWriter(final Writer out) {
super(out);
maxBytes=100 * MEGABYTE;
maxBytes = 100 * MEGABYTE;
}

public SizeLimitedWriter(final Writer out, final int sz) {
super(out, sz);
maxBytes=100 * MEGABYTE;
maxBytes = 100 * MEGABYTE;
}

public SizeLimitedWriter(final Writer out, final long maxBytes) {
super(out);
this.maxBytes=maxBytes;
this.maxBytes = maxBytes;
}
public void setRecordLimit(long maxRecords) {
this.maxRecords=maxRecords;

public void setRecordLimit(final long maxRecords) {
this.maxRecords = maxRecords;
}

/**
* Convenience method that writes the line and terminates it
*
* @param line
* @throws IOException
*/
Expand All @@ -43,27 +45,29 @@ public void writeLine(final String line) throws IOException {
write(line);
newLine();
}

private void checkLimit(final String line) throws SizeLimitExceeded {
if (line==null) {
if (line == null) {
throw new IllegalArgumentException("Null line");
} else {
long targetLength = bytesWritten + line.length();
if ((targetLength) > maxBytes || (maxRecords > 0 && recordsWritten >= maxRecords) ) {
final long targetLength = bytesWritten + line.length();
if ((targetLength) > maxBytes || (maxRecords > 0 && recordsWritten >= maxRecords)) {
throw new SizeLimitExceeded(SIZE_LIMIT_WOULD_BE_EXCEEDED);
}
}
}

/**
* Keep track of bytes written
*
* @param line the line of text to write
**/
@Override
public void write(final String line) throws IOException {
bytesWritten += line.length();
super.write(line);
}

/**
* Keep track of bytes written
**/
Expand All @@ -77,11 +81,11 @@ public void newLine() throws IOException {
public double getBytesWritten() {
return bytesWritten;
}

public class SizeLimitExceeded extends IOException {
private static final long serialVersionUID = -6195202197503740493L;
private static final long serialVersionUID = 1L;

public SizeLimitExceeded(String msg) {
public SizeLimitExceeded(final String msg) {
super(msg);
}
}
Expand Down

0 comments on commit 358dd49

Please sign in to comment.