Skip to content

Commit 73d8a31

Browse files
Guy K. Klossagirbal
authored andcommitted
further attempt to be more white space and wildcard import compatible
1 parent a45c3bf commit 73d8a31

2 files changed

Lines changed: 38 additions & 44 deletions

File tree

src/main/com/mongodb/gridfs/GridFSInputFile.java

Lines changed: 34 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,14 @@
1818

1919
package com.mongodb.gridfs;
2020

21-
import java.io.IOException;
22-
import java.io.InputStream;
23-
import java.io.OutputStream;
24-
import java.security.MessageDigest;
25-
import java.util.Date;
21+
import java.io.*;
22+
import java.security.*;
23+
import java.util.*;
2624

27-
import org.bson.types.ObjectId;
25+
import org.bson.types.*;
2826

29-
import com.mongodb.BasicDBObject;
30-
import com.mongodb.BasicDBObjectBuilder;
31-
import com.mongodb.DBObject;
32-
import com.mongodb.MongoException;
33-
import com.mongodb.util.SimplePool;
34-
import com.mongodb.util.Util;
27+
import com.mongodb.*;
28+
import com.mongodb.util.*;
3529

3630
/**
3731
* Class implementation for writing data to GridFS.
@@ -51,7 +45,7 @@ public class GridFSInputFile extends GridFSFile {
5145
* @param filename
5246
* Name of the file to be created.
5347
*/
54-
GridFSInputFile(GridFS fs , InputStream in , String filename) {
48+
GridFSInputFile( GridFS fs , InputStream in , String filename ) {
5549
_fs = fs;
5650
_in = in;
5751
_filename = filename;
@@ -75,7 +69,7 @@ public class GridFSInputFile extends GridFSFile {
7569
* @param filename
7670
* Name of the file to be created.
7771
*/
78-
GridFSInputFile(GridFS fs , String filename) {
72+
GridFSInputFile( GridFS fs , String filename ) {
7973
this( fs , null , filename );
8074
}
8175

@@ -87,7 +81,7 @@ public class GridFSInputFile extends GridFSFile {
8781
* @param fs
8882
* The GridFS connection handle.
8983
*/
90-
GridFSInputFile(GridFS fs) {
84+
GridFSInputFile( GridFS fs ) {
9185
this( fs , null , null );
9286
}
9387

@@ -97,7 +91,7 @@ public class GridFSInputFile extends GridFSFile {
9791
* @see com.mongodb.gridfs.GridFSFile#getMetaData()
9892
*/
9993
public DBObject getMetaData() {
100-
if (_metadata == null) {
94+
if ( _metadata == null ) {
10195
_metadata = new BasicDBObject();
10296
}
10397
return _metadata;
@@ -109,7 +103,7 @@ public DBObject getMetaData() {
109103
* @param fn
110104
* File name.
111105
*/
112-
public void setFilename(String fn) {
106+
public void setFilename( String fn ) {
113107
_filename = fn;
114108
}
115109

@@ -119,7 +113,7 @@ public void setFilename(String fn) {
119113
* @param ct
120114
* Content type.
121115
*/
122-
public void setContentType(String ct) {
116+
public void setContentType( String ct ) {
123117
_contentType = ct;
124118
}
125119

@@ -138,16 +132,16 @@ public void save() {
138132
* @param chunkSize
139133
* Size of chunks for file in bytes.
140134
*/
141-
public void save(int chunkSize) {
135+
public void save( int chunkSize ) {
142136
if (!_saved) {
143137
try {
144138
saveChunks( chunkSize );
145-
} catch (IOException ioe) {
139+
} catch ( IOException ioe ) {
146140
throw new MongoException( "couldn't save chunks" , ioe );
147141
}
148142
}
149143

150-
if (_outputStream == null) {
144+
if ( _outputStream == null ) {
151145
_close();
152146
}
153147
}
@@ -183,27 +177,27 @@ public int saveChunks() throws IOException {
183177
* on problems reading the new entry's
184178
* {@link java.io.InputStream}.
185179
*/
186-
public int saveChunks(int chunkSize) throws IOException {
187-
if (_chunkSize != chunkSize) {
180+
public int saveChunks( int chunkSize ) throws IOException {
181+
if ( _chunkSize != chunkSize ) {
188182
_chunkSize = chunkSize;
189183
_buffer = new byte[(int) _chunkSize];
190184
}
191-
if (_saved) {
185+
if ( _saved ) {
192186
throw new RuntimeException( "already saved!" );
193187
}
194188

195-
if (chunkSize > 3.5 * 1000 * 1000) {
189+
if ( chunkSize > 3.5 * 1000 * 1000 ) {
196190
throw new RuntimeException( "chunkSize must be less than 3.5MiB!" );
197191
}
198192

199193
int bytesRead = 0;
200-
while (bytesRead >= 0) {
194+
while ( bytesRead >= 0 ) {
201195
_currentBufferPosition = 0;
202196
bytesRead = _readStream2Buffer();
203197
_dumpBuffer( _outputStream == null );
204198
}
205199

206-
if (_outputStream == null) {
200+
if ( _outputStream == null ) {
207201
_close();
208202
}
209203
return _currentChunkNumber;
@@ -223,7 +217,7 @@ public int saveChunks(int chunkSize) throws IOException {
223217
* @return Writable stream object.
224218
*/
225219
public OutputStream getOutputStream() {
226-
if (_outputStream == null) {
220+
if ( _outputStream == null ) {
227221
_outputStream = new MyOutputStream();
228222
}
229223
return _outputStream;
@@ -238,13 +232,13 @@ public OutputStream getOutputStream() {
238232
* @param writePartial
239233
* Write also partial buffers full.
240234
*/
241-
private void _dumpBuffer(boolean writePartial) {
242-
if ((_currentBufferPosition < _chunkSize) && !writePartial) {
235+
private void _dumpBuffer( boolean writePartial ) {
236+
if ( ( _currentBufferPosition < _chunkSize ) && !writePartial ) {
243237
// Bail out, nothing to write (yet).
244238
return;
245239
}
246240
byte[] writeBuffer = _buffer;
247-
if (_currentBufferPosition != _chunkSize) {
241+
if ( _currentBufferPosition != _chunkSize ) {
248242
writeBuffer = new byte[_currentBufferPosition];
249243
System.arraycopy( _buffer, 0, writeBuffer, 0, _currentBufferPosition );
250244
}
@@ -269,12 +263,12 @@ private void _dumpBuffer(boolean writePartial) {
269263
*/
270264
private int _readStream2Buffer() throws IOException {
271265
int bytesRead = 0;
272-
while (_currentBufferPosition < _chunkSize && bytesRead >= 0) {
266+
while ( _currentBufferPosition < _chunkSize && bytesRead >= 0 ) {
273267
bytesRead = _in.read( _buffer, _currentBufferPosition,
274268
(int) _chunkSize - _currentBufferPosition );
275-
if (bytesRead > 0) {
269+
if ( bytesRead > 0 ) {
276270
_currentBufferPosition += bytesRead;
277-
} else if (bytesRead == 0) {
271+
} else if ( bytesRead == 0 ) {
278272
throw new RuntimeException( "i'm doing something wrong" );
279273
}
280274
}
@@ -317,7 +311,7 @@ private void _close() {
317311
protected MessageDigest createNew() {
318312
try {
319313
return MessageDigest.getInstance( "MD5" );
320-
} catch (java.security.NoSuchAlgorithmException e) {
314+
} catch ( java.security.NoSuchAlgorithmException e ) {
321315
throw new RuntimeException( "your system doesn't have md5!" );
322316
}
323317
}
@@ -337,7 +331,7 @@ class MyOutputStream extends OutputStream {
337331
* @see java.io.OutputStream#write(int)
338332
*/
339333
@Override
340-
public void write(int b) throws IOException {
334+
public void write( int b ) throws IOException {
341335
byte[] byteArray = new byte[1];
342336
byteArray[0] = (byte) (b & 0xff);
343337
write( byteArray, 0, 1 );
@@ -349,20 +343,20 @@ public void write(int b) throws IOException {
349343
* @see java.io.OutputStream#write(byte[], int, int)
350344
*/
351345
@Override
352-
public void write(byte[] b , int off , int len) throws IOException {
346+
public void write( byte[] b , int off , int len ) throws IOException {
353347
int offset = off;
354348
int length = len;
355349
int toCopy = 0;
356-
while (length > 0) {
350+
while ( length > 0 ) {
357351
toCopy = length;
358-
if (toCopy > _chunkSize - _currentBufferPosition) {
352+
if ( toCopy > _chunkSize - _currentBufferPosition ) {
359353
toCopy = (int) _chunkSize - _currentBufferPosition;
360354
}
361355
System.arraycopy( b, offset, _buffer, _currentBufferPosition, toCopy );
362356
_currentBufferPosition += toCopy;
363357
offset += toCopy;
364358
length -= toCopy;
365-
if (_currentBufferPosition == _chunkSize) {
359+
if ( _currentBufferPosition == _chunkSize ) {
366360
_dumpBuffer( false );
367361
}
368362
}

src/test/com/mongodb/gridfs/GridFSTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ public void testBig()
9898
testInOut( s );
9999
}
100100

101-
void testOutStream(String s) throws Exception {
101+
void testOutStream( String s ) throws Exception {
102102

103103
int[] start = _get();
104104

@@ -107,8 +107,8 @@ void testOutStream(String s) throws Exception {
107107
writeStream.write( s.getBytes(), 0, s.length() );
108108
writeStream.close();
109109
GridFSDBFile out = _fs.findOne( new BasicDBObject( "_id" , in.getId() ) );
110-
assert (out.getId().equals( in.getId() ));
111-
assert (out.getChunkSize() == (long) GridFS.DEFAULT_CHUNKSIZE);
110+
assert ( out.getId().equals( in.getId() ) );
111+
assert ( out.getChunkSize() == (long) GridFS.DEFAULT_CHUNKSIZE );
112112

113113
ByteArrayOutputStream bout = new ByteArrayOutputStream();
114114
out.writeTo( bout );
@@ -130,7 +130,7 @@ public void testOutStreamSmall() throws Exception {
130130
public void testOutStreamBig() throws Exception {
131131
int target = (int) (GridFS.DEFAULT_CHUNKSIZE * 3.5);
132132
StringBuilder buf = new StringBuilder( target );
133-
while (buf.length() < target) {
133+
while ( buf.length() < target ) {
134134
buf.append( "asdasdkjasldkjasldjlasjdlajsdljasldjlasjdlkasjdlaskjdlaskjdlsakjdlaskjdasldjsad" );
135135
}
136136
String s = buf.toString();

0 commit comments

Comments
 (0)