Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package net.java.ao.db;
  
  
  import java.io.Closeable;
  import java.io.File;
 import java.io.Reader;
 import java.io.Writer;
 
 import static com.google.common.base.Suppliers.memoize;
 
 final class FileSystemUtils
 {
     private static final Supplier<BooleanCASE_SENSITIVE_SUPPLIER = memoize(new Supplier<Boolean>()
     {
         public Boolean get()
         {
             try
             {
                 final File tmp = File.createTempFile("active_objects""_case_tmp");
                 tmp.deleteOnExit();
 
                 final File tmpWithUpperCaseName = new File(tmp.getParent(), toUpperCase(tmp.getName()));
                 tmpWithUpperCaseName.deleteOnExit();
 
                 if (!tmpWithUpperCaseName.exists())
                 {
                     return false;
                 }
                 return !sameContent(tmptmpWithUpperCaseName);
             }
             catch (IOException e)
             {
                 throw new IllegalStateException(e);
             }
         }
     });
 
     static boolean isCaseSensitive()
     {
         return .get();
     }
 
     private static boolean sameContent(File tmpFile tmpWithUpperCaseNamethrows IOException
     {
         final String data = FileSystemUtils.class.getName();
         write(tmpdata);
         return read(tmpWithUpperCaseName).equals(data);
     }
 
     private static String toUpperCase(String name)
     {
         return name.toUpperCase(.);
     }
 
     // methods below have been "copied" from commons io 2.0.1
 
     private static void write(File fileCharSequence datathrows IOException
     {
         String str = data == null ? null : data.toString();
         writeStringToFile(filestr);
     }
 
     private static void writeStringToFile(File fileString datathrows IOException
     {
         OutputStream out = null;
         try
         {
             out = openOutputStream(file);
             out.write(data.getBytes());
         }
         finally
         {
             closeQuietly(out);
         }
     }
 
     private static String read(File filethrows IOException
     {
         InputStream in = null;
         try
         {
             in = openInputStream(file);
             return toString(in);
         }
         finally
         {
             closeQuietly(in);
         }
     }
    private static FileInputStream openInputStream(File filethrows IOException
    {
        if (file.exists())
        {
            if (file.isDirectory())
            {
                throw new IOException("File '" + file + "' exists but is a directory");
            }
            if (!file.canRead())
            {
                throw new IOException("File '" + file + "' cannot be read");
            }
        }
        else
        {
            throw new FileNotFoundException("File '" + file + "' does not exist");
        }
        return new FileInputStream(file);
    }
    private static String toString(InputStream inputthrows IOException
    {
        StringBuilderWriter sw = new StringBuilderWriter();
        copy(new InputStreamReader(input), sw);
        return sw.toString();
    }
    private static final int DEFAULT_BUFFER_SIZE = 1024 * 4;
    private static long copy(Reader inputWriter outputthrows IOException
    {
        char[] buffer = new char[];
        long count = 0;
        int n = 0;
        while (-1 != (n = input.read(buffer)))
        {
            output.write(buffer, 0, n);
            count += n;
        }
        return count;
    }
    private static FileOutputStream openOutputStream(File filethrows IOException
    {
        if (file.exists())
        {
            if (file.isDirectory())
            {
                throw new IOException("File '" + file + "' exists but is a directory");
            }
            if (!file.canWrite())
            {
                throw new IOException("File '" + file + "' cannot be written to");
            }
        }
        else
        {
            File parent = file.getParentFile();
            if (parent != null && !parent.exists())
            {
                if (!parent.mkdirs())
                {
                    throw new IOException("File '" + file + "' could not be created");
                }
            }
        }
        return new FileOutputStream(file);
    }
    private static void closeQuietly(Closeable closeable)
    {
        try
        {
            if (closeable != null)
            {
                closeable.close();
            }
        }
        catch (IOException ioe)
        {
            // ignore
        }
    }
    private static final class StringBuilderWriter extends Writer implements Serializable
    {
        private final StringBuilder builder;

        
Construct a new java.lang.StringBuilder instance with default capacity.
        public StringBuilderWriter()
        {
            this. = new StringBuilder();
        }

        
Construct a new java.lang.StringBuilder instance with the specified capacity.

Parameters:
capacity The initial capacity of the underlying java.lang.StringBuilder
        public StringBuilderWriter(int capacity)
        {
            this. = new StringBuilder(capacity);
        }

        
Construct a new instance with the specified java.lang.StringBuilder.

Parameters:
builder The String builder
        public StringBuilderWriter(StringBuilder builder)
        {
            this. = (builder != null ? builder : new StringBuilder());
        }

        
Append a single character to this Writer.

Parameters:
value The character to append
Returns:
This writer instance
        @Override
        public Writer append(char value)
        {
            .append(value);
            return this;
        }

        
Append a character sequence to this Writer.

Parameters:
value The character to append
Returns:
This writer instance
        @Override
        public Writer append(CharSequence value)
        {
            .append(value);
            return this;
        }

        
Append a portion of a character sequence to the java.lang.StringBuilder.

Parameters:
value The character to append
start The index of the first character
end The index of the last character + 1
Returns:
This writer instance
        @Override
        public Writer append(CharSequence valueint startint end)
        {
            .append(valuestartend);
            return this;
        }

        
Closing this writer has no effect.
        @Override
        public void close()
        {
        }

        
Flushing this writer has no effect.
        @Override
        public void flush()
        {
        }


        
Write a String to the java.lang.StringBuilder.

Parameters:
value The value to write
        @Override
        public void write(String value)
        {
            if (value != null)
            {
                .append(value);
            }
        }

        
Write a portion of a character array to the java.lang.StringBuilder.

Parameters:
value The value to write
offset The index of the first character
length The number of characters to write
        @Override
        public void write(char[] valueint offsetint length)
        {
            if (value != null)
            {
                .append(valueoffsetlength);
            }
        }

        
Return the underlying builder.

Returns:
The underlying builder
        public StringBuilder getBuilder()
        {
            return ;
        }

        
Returns java.lang.StringBuilder.toString().

Returns:
The contents of the String builder.
        @Override
        public String toString()
        {
            return .toString();
        }
    }
New to GrepCode? Check out our FAQ X