Repository navigation
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
Open
shreyasgosavi
wants to merge
2
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.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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" | ||
| } | ||
162 changes: 162 additions & 0 deletions
162
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,162 @@ | ||
| import java.io.Closeable; | ||
| import java.io.IOException; | ||
| import java.io.InputStream; | ||
| import java.io.OutputStream; | ||
|
|
||
| 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 InputStream getInputStream() { | ||
| return inputStream; | ||
| } | ||
|
|
||
| public OutputStream getOutputStream() { | ||
| return 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 int readNBytes(byte[] byteArray, int offset, int len) throws IOException { | ||
|
|
||
| int totalBytesRead = this.inputStream.readNBytes(byteArray, offset, len); | ||
| if (totalBytesRead > 0) { | ||
| readOperationCount++; | ||
| bytesRead += totalBytesRead; | ||
| } | ||
| return totalBytesRead; | ||
| } | ||
|
|
||
| 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.
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.
Feel free to add yourself as the author