Skip to content

Commit 16cde49

Browse files
committed
Code cleanup
1 parent f051a3c commit 16cde49

6 files changed

Lines changed: 40 additions & 38 deletions

File tree

src/main/java/picoded/dstack/FileWorkspace.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -163,22 +163,21 @@ default void writeOutputStream(final String filepath, final OutputStream data) {
163163
// Converts it to bytearray respectively
164164
byte[] rawBytes = null;
165165
try {
166-
if( data instanceof ByteArrayOutputStream ) {
167-
rawBytes = ((ByteArrayOutputStream)data).toByteArray();
166+
if (data instanceof ByteArrayOutputStream) {
167+
rawBytes = ((ByteArrayOutputStream) data).toByteArray();
168168
} else {
169169
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
170170
buffer.writeTo(data);
171171
rawBytes = buffer.toByteArray();
172172
}
173-
} catch(IOException e) {
173+
} catch (IOException e) {
174174
throw new RuntimeException(e);
175175
}
176-
176+
177177
// Does the bytearray writes
178178
writeByteArray(filepath, rawBytes);
179179
}
180180

181-
182181
//
183182
// Folder Pathing support
184183
//--------------------------------------------------------------------------

src/main/java/picoded/dstack/core/Core_FileWorkspaceMap.java

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -183,10 +183,10 @@ public void setupWorkspace(String oid) {
183183
public InputStream backend_fileReadInputStream(final String oid, final String filepath) {
184184
// Get the byte data
185185
byte[] rawBytes = backend_fileRead(oid, filepath);
186-
if( rawBytes == null ) {
186+
if (rawBytes == null) {
187187
return null;
188188
}
189-
return new ByteArrayInputStream( rawBytes );
189+
return new ByteArrayInputStream(rawBytes);
190190
}
191191

192192
/**
@@ -201,27 +201,28 @@ public InputStream backend_fileReadInputStream(final String oid, final String fi
201201
* @param filepath to use for the workspace
202202
* @param data to write the file with
203203
**/
204-
public void backend_fileWriteOutputStream(final String oid, final String filepath, final OutputStream data) {
205-
204+
public void backend_fileWriteOutputStream(final String oid, final String filepath,
205+
final OutputStream data) {
206+
206207
// forward the null, and let the error handling below settle it
207-
if( data == null ) {
208+
if (data == null) {
208209
backend_fileWrite(oid, filepath, null);
209210
}
210-
211+
211212
// Converts it to bytearray respectively
212213
byte[] rawBytes = null;
213214
try {
214-
if( data instanceof ByteArrayOutputStream ) {
215-
rawBytes = ((ByteArrayOutputStream)data).toByteArray();
215+
if (data instanceof ByteArrayOutputStream) {
216+
rawBytes = ((ByteArrayOutputStream) data).toByteArray();
216217
} else {
217218
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
218219
buffer.writeTo(data);
219220
rawBytes = buffer.toByteArray();
220221
}
221-
} catch(IOException e) {
222+
} catch (IOException e) {
222223
throw new RuntimeException(e);
223224
}
224-
225+
225226
// Does the bytearray writes
226227
backend_fileWrite(oid, filepath, rawBytes);
227228
}

src/main/java/picoded/dstack/file/simple/FileSimple_FileWorkspaceMap.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import java.nio.file.Files;
1010
import java.util.HashSet;
1111
import java.util.Set;
12+
1213
/**
1314
* Reference class for Core_FileWorkspaceMap
1415
* Provide Crud operation backed by actual files

src/main/java/picoded/dstack/mongodb/MongoDB_DataObjectMap.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,13 +90,13 @@ public void systemSetup() {
9090
IndexOptions opt = new IndexOptions();
9191
opt = opt.unique(true);
9292
opt = opt.name("_oid");
93-
93+
9494
// Due to the need for _oid to ensure consistency, we would not be creating it in the background
9595
// opt = opt.background(true);
96-
96+
9797
// Lets create the index
9898
collection.createIndex(Indexes.ascending("_oid"), opt);
99-
99+
100100
//
101101
// Wildcard indexing
102102
//

src/main/java/picoded/dstack/stack/Stack_FileWorkspaceMap.java

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public CommonStructure[] commonStructureStack() {
7979
// [Internal use, to be extended in future implementation]
8080
//
8181
//--------------------------------------------------------------------------
82-
82+
8383
// Workspace operations
8484
//--------------------------------------------------------------------------
8585

@@ -194,20 +194,20 @@ public void backend_fileWrite(String oid, String filepath, byte[] data) {
194194
**/
195195
@Override
196196
public InputStream backend_fileReadInputStream(final String oid, final String filepath) {
197-
197+
198198
// Due to the behaviour of how the file data needs to be handled across multiple layers
199199
// we only use an optimized "readStream" call if the filesystem is a single stack layer
200-
if( dataLayers.length == 1 ) {
200+
if (dataLayers.length == 1) {
201201
return dataLayers[0].backend_fileReadInputStream(oid, filepath);
202202
}
203-
203+
204204
// Fallback behaviour, polyfill the byte[] implementation
205205
//------------------------------------------------------------
206206
byte[] rawBytes = backend_fileRead(oid, filepath);
207-
if( rawBytes == null ) {
207+
if (rawBytes == null) {
208208
return null;
209209
}
210-
return new ByteArrayInputStream( rawBytes );
210+
return new ByteArrayInputStream(rawBytes);
211211
}
212212

213213
/**
@@ -218,37 +218,38 @@ public InputStream backend_fileReadInputStream(final String oid, final String fi
218218
* @param data to write the file with
219219
**/
220220
@Override
221-
public void backend_fileWriteOutputStream(final String oid, final String filepath, final OutputStream data) {
222-
221+
public void backend_fileWriteOutputStream(final String oid, final String filepath,
222+
final OutputStream data) {
223+
223224
// Due to the behaviour of how the file data needs to be handled across multiple layers
224225
// we only use an optimized "readStream" call if the filesystem is a single stack layer
225-
if( dataLayers.length == 1 ) {
226+
if (dataLayers.length == 1) {
226227
dataLayers[0].backend_fileWriteOutputStream(oid, filepath, data);
227228
return;
228229
}
229-
230+
230231
// Fallback behaviour, polyfill the byte[] implementation
231232
//------------------------------------------------------------
232-
233+
233234
// forward the null, and let the error handling below settle it
234-
if( data == null ) {
235+
if (data == null) {
235236
backend_fileWrite(oid, filepath, null);
236237
}
237-
238+
238239
// Converts it to bytearray respectively
239240
byte[] rawBytes = null;
240241
try {
241-
if( data instanceof ByteArrayOutputStream ) {
242-
rawBytes = ((ByteArrayOutputStream)data).toByteArray();
242+
if (data instanceof ByteArrayOutputStream) {
243+
rawBytes = ((ByteArrayOutputStream) data).toByteArray();
243244
} else {
244245
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
245246
buffer.writeTo(data);
246247
rawBytes = buffer.toByteArray();
247248
}
248-
} catch(IOException e) {
249+
} catch (IOException e) {
249250
throw new RuntimeException(e);
250251
}
251-
252+
252253
// Does the bytearray writes
253254
backend_fileWrite(oid, filepath, rawBytes);
254255
}

src/test/java/picoded/dstack/struct/simple/StructSimple_FileWorkspaceMap_test.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -336,10 +336,10 @@ public void readNonExistenceFile() {
336336
public void writeAndReadToFile_stream() throws Exception {
337337
// Output stream to use for content
338338
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
339-
buffer.write( "data to write".getBytes() );
340-
339+
buffer.write("data to write".getBytes());
340+
341341
FileWorkspace fileWorkspace = testObj.newEntry();
342-
fileWorkspace.writeOutputStream("testPath", buffer );
342+
fileWorkspace.writeOutputStream("testPath", buffer);
343343
assertNotNull(testObj.get(fileWorkspace._oid()).readByteArray("testPath"));
344344

345345
InputStream readData = testObj.get(fileWorkspace._oid()).readInputStream("testPath");

0 commit comments

Comments
 (0)