Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
blueBill Core - open source birding Copyright (C) 2009-2011 by Tidalwave s.a.s. (http://www.tidalwave.it) Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. WWW: http://bluebill.tidalwave.it SCM: https://java.net/hg/bluebill~core-src /
 
 package it.tidalwave.mobile.io;
 
 import  javax.annotation.Nonnull;
 import java.io.File;
 import  it.tidalwave.util.StringValue;
 import java.util.List;

Author(s):
Fabrizio Giudici
Version:
$Id$ /
 
 public class StringsIO
   {
     public static interface Processor<T>
       {
         @Nonnull
         public T processString (@Nonnull String string);
       }
 
     private final static String CHARSET = "UTF-8";
     
     @Nonnull
     private final File file;
 
     public StringsIO (final @Nonnull File file)
       {
         this. = file;
       }

    
/
 
     public void store (final @Nonnull Iterable<? extends StringValue> stringValues)
       throws IOException
       {
         PrintWriter pw = null;
 
         try
           {
             pw = new PrintWriter(new OutputStreamWriter(new FileOutputStream(), ));
 
             for (final StringValue stringValue : stringValues)
               {
                 pw.println(stringValue.stringValue());
               }
           }
         finally
           {
             IoUtils.safeClose(pw);
           }
       }

    
/
 
     @Nonnull
     public <T> Collection<T> load (final @Nonnull Processor<T> processor)
       throws IOException
       {
         BufferedReader br = null;
 
         try
           {
             final List<T> result = new ArrayList<T>();
            br = new BufferedReader(new InputStreamReader(new FileInputStream(), ));
            for (;;)
              {
                final String string = br.readLine();
                if (string == null)
                  {
                    break;
                  }
                result.add(processor.processString(string));
              }
            return result;
          }
        finally
          {
            IoUtils.safeClose(br);
          }
      }
  }
New to GrepCode? Check out our FAQ X