-
-
Notifications
You must be signed in to change notification settings - Fork 712
Passio Practice Exercise implemented #2970
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
shreyasgosavi
wants to merge
19
commits into
exercism:main
Choose a base branch
from
shreyasgosavi:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
a912d0c
Setting up paasio exercise | Added paasio in settings.gradle | Added…
shreyasgosavi d81eb05
Added Sample code to avoid Build failure
shreyasgosavi bc2a2cd
Paasio Code begins | Started Code structure set-up
shreyasgosavi c83978c
Developing with TDD strategy | Test-cases for file-reading operations…
shreyasgosavi 52e1794
Test cases for Write Operations for file handling written
shreyasgosavi 3507f1c
Sample Code added for File-Operations
shreyasgosavi 4a94e3c
FileOperation Changes added
shreyasgosavi d1d9917
Adding Generic Input-Output Operation class | Referring to that imple…
shreyasgosavi 4c67d9b
Adding tags to the File Operation Test Cases
shreyasgosavi 9706a9f
Test Cases for SOcket Opearations added. along with its implementations
shreyasgosavi 8c3aaf5
Another test case to verify data written in output-stream
shreyasgosavi 0aeb078
Changed the implementation to more generic code.
shreyasgosavi 71e0867
Code formatted
shreyasgosavi b934489
Un-necessary test-cases consolidated and shortened
shreyasgosavi b8ba510
Merge branch 'paasio-exercise'
shreyasgosavi e07be74
Sonar Qube changes added | Changes in test cases -- corrected arguments
shreyasgosavi 03ee525
Merge branch 'paasio-exercise'
shreyasgosavi 47ef869
Changes synced with reference code
shreyasgosavi fbf5c8d
Code formatted
shreyasgosavi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# Instructions | ||
|
||
Report network IO statistics. | ||
|
||
You are writing a [PaaS][paas], and you need a way to bill customers based on network and filesystem usage. | ||
|
||
Create a wrapper for network connections and files that can report IO statistics. | ||
The wrapper must report: | ||
|
||
- The total number of bytes read/written. | ||
- The total number of read/write operations. | ||
|
||
[paas]: https://en.wikipedia.org/wiki/Platform_as_a_service |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"authors": [], | ||
"files": { | ||
"solution": [ | ||
"src/main/java/Paasio.java" | ||
], | ||
"test": [ | ||
"src/test/java/PaasioTest.java" | ||
], | ||
"example": [ | ||
".meta/src/reference/java/Paasio.java" | ||
] | ||
}, | ||
"blurb": "Report network IO statistics.", | ||
"source": "Brian Matsuo", | ||
"source_url": "https://github.com/bmatsuo" | ||
} |
140 changes: 140 additions & 0 deletions
140
exercises/practice/paasio/.meta/src/reference/java/Paasio.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,140 @@ | ||||||||||
import java.io.*; | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please don't use
Suggested change
|
||||||||||
|
||||||||||
public class Paasio implements Closeable { | ||||||||||
|
||||||||||
private long bytesRead; | ||||||||||
private long readOperationCount; | ||||||||||
private long bytesWritten; | ||||||||||
private long writeOperationCount; | ||||||||||
|
||||||||||
private final InputStream inputStream; | ||||||||||
private final OutputStream outputStream; | ||||||||||
|
||||||||||
public Paasio(InputStream inputStream, OutputStream outputStream) { | ||||||||||
this.inputStream = inputStream; | ||||||||||
this.outputStream = outputStream; | ||||||||||
} | ||||||||||
|
||||||||||
public int read() throws IOException { | ||||||||||
int byteData = inputStream.read(); | ||||||||||
if (byteData != -1) { | ||||||||||
bytesRead += 1; | ||||||||||
readOperationCount++; | ||||||||||
} | ||||||||||
return byteData; | ||||||||||
} | ||||||||||
|
||||||||||
public int read(byte[] b) throws IOException { | ||||||||||
|
||||||||||
int totalBytesRead = inputStream.read(b); | ||||||||||
if (totalBytesRead != -1) { | ||||||||||
bytesRead += totalBytesRead; | ||||||||||
readOperationCount++; | ||||||||||
} | ||||||||||
return totalBytesRead; | ||||||||||
|
||||||||||
} | ||||||||||
|
||||||||||
public int read(byte[] b, int off, int len) throws IOException { | ||||||||||
|
||||||||||
int bytesReadIntoBuffer = inputStream.read(b, off, len); | ||||||||||
|
||||||||||
if (bytesReadIntoBuffer != -1) { | ||||||||||
bytesRead += bytesReadIntoBuffer; | ||||||||||
readOperationCount++; | ||||||||||
} | ||||||||||
return bytesReadIntoBuffer; | ||||||||||
|
||||||||||
|
||||||||||
} | ||||||||||
|
||||||||||
public byte[] readAllBytes() throws IOException { | ||||||||||
|
||||||||||
byte[] allData = this.inputStream.readAllBytes(); | ||||||||||
|
||||||||||
if (allData.length > 0) { | ||||||||||
readOperationCount++; | ||||||||||
bytesRead += allData.length; | ||||||||||
} | ||||||||||
return allData; | ||||||||||
|
||||||||||
} | ||||||||||
|
||||||||||
public byte[] readNBytes(int len) throws IOException { | ||||||||||
|
||||||||||
byte[] allData = this.inputStream.readNBytes(len); | ||||||||||
if (allData.length > 0) { | ||||||||||
readOperationCount++; | ||||||||||
bytesRead += allData.length; | ||||||||||
} | ||||||||||
return allData; | ||||||||||
} | ||||||||||
|
||||||||||
public void write(int b) throws IOException { | ||||||||||
|
||||||||||
try { | ||||||||||
this.outputStream.write(b); | ||||||||||
writeOperationCount++; | ||||||||||
bytesWritten++; | ||||||||||
|
||||||||||
} catch (IOException ioException) { | ||||||||||
ioException.printStackTrace(); | ||||||||||
} | ||||||||||
|
||||||||||
} | ||||||||||
|
||||||||||
public void write(byte[] b) throws IOException { | ||||||||||
try { | ||||||||||
|
||||||||||
this.outputStream.write(b); | ||||||||||
writeOperationCount++; | ||||||||||
bytesWritten += b.length; | ||||||||||
|
||||||||||
|
||||||||||
} catch (IOException ioException) { | ||||||||||
ioException.printStackTrace(); | ||||||||||
} | ||||||||||
} | ||||||||||
|
||||||||||
public void write(byte[] b, int off, int len) throws IOException { | ||||||||||
try { | ||||||||||
this.outputStream.write(b, off, len); | ||||||||||
writeOperationCount++; | ||||||||||
bytesWritten += len; | ||||||||||
|
||||||||||
} catch (IOException ioException) { | ||||||||||
ioException.printStackTrace(); | ||||||||||
} | ||||||||||
} | ||||||||||
|
||||||||||
public long getBytesRead() { | ||||||||||
return bytesRead; | ||||||||||
} | ||||||||||
|
||||||||||
public long getReadOperationCount() { | ||||||||||
return readOperationCount; | ||||||||||
} | ||||||||||
|
||||||||||
public long getBytesWritten() { | ||||||||||
return bytesWritten; | ||||||||||
} | ||||||||||
|
||||||||||
public long getWriteOperationCount() { | ||||||||||
return writeOperationCount; | ||||||||||
} | ||||||||||
|
||||||||||
@Override | ||||||||||
public void close() throws IOException { | ||||||||||
if (this.inputStream != null) { | ||||||||||
this.inputStream.close(); | ||||||||||
} | ||||||||||
if (this.outputStream != null) { | ||||||||||
this.outputStream.close(); | ||||||||||
} | ||||||||||
} | ||||||||||
|
||||||||||
} | ||||||||||
|
||||||||||
|
||||||||||
|
||||||||||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
plugins { | ||
id "java" | ||
} | ||
|
||
repositories { | ||
mavenCentral() | ||
} | ||
|
||
dependencies { | ||
testImplementation platform("org.junit:junit-bom:5.10.0") | ||
testImplementation "org.junit.jupiter:junit-jupiter" | ||
testImplementation "org.assertj:assertj-core:3.25.1" | ||
|
||
testRuntimeOnly "org.junit.platform:junit-platform-launcher" | ||
} | ||
|
||
test { | ||
useJUnitPlatform() | ||
|
||
testLogging { | ||
exceptionFormat = "full" | ||
showStandardStreams = true | ||
events = ["passed", "failed", "skipped"] | ||
} | ||
} |
Binary file not shown.
7 changes: 7 additions & 0 deletions
7
exercises/practice/paasio/gradle/wrapper/gradle-wrapper.properties
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
distributionBase=GRADLE_USER_HOME | ||
distributionPath=wrapper/dists | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip | ||
networkTimeout=10000 | ||
validateDistributionUrl=true | ||
zipStoreBase=GRADLE_USER_HOME | ||
zipStorePath=wrapper/dists |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This really shouldn't be a one (it's not that easy). Perhaps we could use the Go track as a guide - they have used 4 as the difficulty.