You are viewing a plain text version of this content. The canonical link for it is here.
Posted to slide-dev@jakarta.apache.org by re...@locus.apache.org on 2000/12/04 02:59:48 UTC

cvs commit: jakarta-slide/src/stores/slidestore/file FileContentStoreNoVersioning.java

remm        00/12/03 17:59:48

  Modified:    src/stores/slidestore/file FileContentStoreNoVersioning.java
  Log:
  - Update the default content store according to the requirements regarding
    the handling of content length.
  
  Revision  Changes    Path
  1.3       +40 -17    jakarta-slide/src/stores/slidestore/file/FileContentStoreNoVersioning.java
  
  Index: FileContentStoreNoVersioning.java
  ===================================================================
  RCS file: /home/cvs/jakarta-slide/src/stores/slidestore/file/FileContentStoreNoVersioning.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- FileContentStoreNoVersioning.java	2000/10/08 22:49:30	1.2
  +++ FileContentStoreNoVersioning.java	2000/12/04 01:59:47	1.3
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-slide/src/stores/slidestore/file/FileContentStoreNoVersioning.java,v 1.2 2000/10/08 22:49:30 remm Exp $
  - * $Revision: 1.2 $
  - * $Date: 2000/10/08 22:49:30 $
  + * $Header: /home/cvs/jakarta-slide/src/stores/slidestore/file/FileContentStoreNoVersioning.java,v 1.3 2000/12/04 01:59:47 remm Exp $
  + * $Revision: 1.3 $
  + * $Date: 2000/12/04 01:59:47 $
    *
    * ====================================================================
    *
  @@ -76,7 +76,7 @@
    * Filesystem implementation of ContentStore.
    * 
    * @author <a href="mailto:remm@apache.org">Remy Maucherat</a>
  - * @version $Revision: 1.2 $
  + * @version $Revision: 1.3 $
    */
   public class FileContentStoreNoVersioning extends ServiceImpl 
       implements ContentStore {
  @@ -213,7 +213,6 @@
               result.setContent(reader);
               result.setContent(is);
   	} catch (FileNotFoundException e) {
  -            e.printStackTrace();
               throw new RevisionNotFoundException(uri.toString(), 
                                                   revisionNumber);
           } catch (IOException e) {
  @@ -260,23 +259,33 @@
                   long position = 0;
                   long contentLength = revisionDescriptor.getContentLength();
                   
  -                int nChar = 0;
  -                while (position < contentLength) {
  -                    nChar = is.read(buffer, 0, BUFFER_SIZE);
  +                while (true) {
  +                    int nChar = is.read(buffer);
                       if (nChar == -1) {
                           break;
                       }
                       os.write(buffer, 0, nChar);
                       position = position + nChar;
                   }
  -                is.close();
                   os.close();
  -                
  -                if (position < contentLength) {
  -                    // Not enough bytes read !!!
  -                    throw new IOException("Not enough bytes read");
  +
  +                if (contentLength != -1) {
  +                    if (position != contentLength) {
  +                        if (position < contentLength) {
  +                            // Not enough bytes read !!!
  +                            throw new IOException("Not enough bytes read");
  +                        }
  +                        if (position > contentLength) {
  +                            // Not enough bytes read !!!
  +                            throw new IOException("Too many bytes read");
  +                        }
  +                        // FIXME : Delete the file
  +                    }
  +                } else {
  +                    revisionDescriptor.setContentLength(position);
                   }
               } else {
  +                // FIXME : Use a Reader
               }
               
           } catch (IOException e) {
  @@ -323,17 +332,31 @@
                   long position = 0;
                   long contentLength = revisionDescriptor.getContentLength();
                   
  -                int nChar = 0;
  -                while (position < contentLength) {
  -                    nChar = is.read(buffer, 0, BUFFER_SIZE);
  +                while (true) {
  +                    int nChar = is.read(buffer);
                       if (nChar == -1) {
                           break;
                       }
                       os.write(buffer, 0, nChar);
                       position = position + nChar;
                   }
  -                is.close();
                   os.close();
  +                
  +                if (contentLength != -1) {
  +                    if (position != contentLength) {
  +                        if (position < contentLength) {
  +                            // Not enough bytes read !!!
  +                            throw new IOException("Not enough bytes read");
  +                        }
  +                        if (position > contentLength) {
  +                            // Not enough bytes read !!!
  +                            throw new IOException("Too many bytes read");
  +                        }
  +                        // FIXME : Delete the file
  +                    }
  +                } else {
  +                    revisionDescriptor.setContentLength(position);
  +                }
                   
                   if (position < contentLength) {
                       // Not enough bytes read !!!