Skip to content

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
wants to merge 19 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
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 May 23, 2025
d81eb05
Added Sample code to avoid Build failure
shreyasgosavi May 23, 2025
bc2a2cd
Paasio Code begins | Started Code structure set-up
shreyasgosavi May 25, 2025
c83978c
Developing with TDD strategy | Test-cases for file-reading operations…
shreyasgosavi May 25, 2025
52e1794
Test cases for Write Operations for file handling written
shreyasgosavi May 28, 2025
3507f1c
Sample Code added for File-Operations
shreyasgosavi May 28, 2025
4a94e3c
FileOperation Changes added
shreyasgosavi May 31, 2025
d1d9917
Adding Generic Input-Output Operation class | Referring to that imple…
shreyasgosavi Jun 1, 2025
4c67d9b
Adding tags to the File Operation Test Cases
shreyasgosavi Jun 1, 2025
9706a9f
Test Cases for SOcket Opearations added. along with its implementations
shreyasgosavi Jun 5, 2025
8c3aaf5
Another test case to verify data written in output-stream
shreyasgosavi Jun 5, 2025
0aeb078
Changed the implementation to more generic code.
shreyasgosavi Jun 20, 2025
71e0867
Code formatted
shreyasgosavi Jun 20, 2025
b934489
Un-necessary test-cases consolidated and shortened
shreyasgosavi Jun 23, 2025
b8ba510
Merge branch 'paasio-exercise'
shreyasgosavi Jul 3, 2025
e07be74
Sonar Qube changes added | Changes in test cases -- corrected arguments
shreyasgosavi Jul 4, 2025
03ee525
Merge branch 'paasio-exercise'
shreyasgosavi Jul 4, 2025
47ef869
Changes synced with reference code
shreyasgosavi Jul 4, 2025
fbf5c8d
Code formatted
shreyasgosavi Jul 4, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions config.json
Original file line number Diff line number Diff line change
Expand Up @@ -1869,6 +1869,14 @@
"lists"
],
"difficulty": 10
},
{
"slug": "paasio",
"name": "PaaS I/O",
"uuid": "81177978-2ed3-47c2-a6a0-fef316d94c0b",
"practices": [],
"prerequisites": [],
"difficulty": 1
Copy link
Member

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.

}
],
"foregone": [
Expand Down
13 changes: 13 additions & 0 deletions exercises/practice/paasio/.docs/instructions.md
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
17 changes: 17 additions & 0 deletions exercises/practice/paasio/.meta/config.json
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 exercises/practice/paasio/.meta/src/reference/java/Paasio.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
import java.io.*;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please don't use * imports. For example:

Suggested change
import java.io.*;
import java.io.Closeable;
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 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();
}
}

}




25 changes: 25 additions & 0 deletions exercises/practice/paasio/build.gradle
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.
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
Loading