Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Copyright 2005,2009 Ivan SZKIBA
   *
   * 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.
  */
 package org.ini4j;
 
 import java.io.Reader;
 
 import java.net.URL;
 
 import java.util.List;
 
 public class IniPreferences extends AbstractPreferences
 {

    
frequently used empty String array
 
     private static final String[] EMPTY = {};

    
underlaying Ini implementation
 
     private final Ini _ini;

    
Constructs a new preferences node on top of Ini instance.

Parameters:
ini underlaying Ini instance
 
     public IniPreferences(Ini ini)
     {
         super(null"");
          = ini;
     }

    
Constructs a new preferences node based on newly loaded Ini instance. This is just a helper constructor, to make simpler constructing IniPreferences directly from Reader.

Parameters:
input the Reader containing Ini data
Throws:
java.io.IOException if an I/O error occured
InvalidFileFormatException if Ini parsing error occured
 
     public IniPreferences(Reader inputthrows IOExceptionInvalidFileFormatException
     {
         super(null"");
          = new Ini(input);
     }

    
Constructs a new preferences node based on newly loaded Ini instance. This is just a helper constructor, to make simpler constructing IniPreferences directly from InputStream.

Parameters:
input the InputStream containing Ini data
Throws:
java.io.IOException if an I/O error occured
InvalidFileFormatException if Ini parsing error occured
 
     {
         super(null"");
          = new Ini(input);
     }

    
Constructs a new preferences node based on newly loaded Ini instance. This is just a helper constructor, to make simpler constructing IniPreferences directly from URL.

Parameters:
input the URL containing Ini data
Throws:
java.io.IOException if an I/O error occured
InvalidFileFormatException if Ini parsing error occured
 
     public IniPreferences(URL inputthrows IOExceptionInvalidFileFormatException
     {
         super(null"");
          = new Ini(input);
     }

    
Provide access to underlaying Ini implementation.

Returns:
Ini implementation
    protected Ini getIni()
    {
        return ;
    }

    
Implements the getSpi method as per the specification in java.util.prefs.AbstractPreferences.getSpi(java.lang.String). This implementation doesn't support this operation, so allways throws UnsupportedOperationException.

Parameters:
key key to getvalue for
Returns:
if the value associated with the specified key at this preference node, or null if there is no association for this key, or the association cannot be determined at this time.
Throws:
java.lang.UnsupportedOperationException this implementation allways throws this exception
    @Override protected String getSpi(String keythrows UnsupportedOperationException
    {
        throw new UnsupportedOperationException();
    }

    
Implements the childrenNamesSpi method as per the specification in java.util.prefs.AbstractPreferences.childrenNamesSpi().

Returns:
an array containing the names of the children of this preference node.
Throws:
java.util.prefs.BackingStoreException if this operation cannot be completed due to a failure in the backing store, or inability to communicate with it.
    @Override protected String[] childrenNamesSpi() throws BackingStoreException
    {
        List<Stringnames = new ArrayList<String>();
        for (String name : .keySet())
        {
            if (name.indexOf(.getPathSeparator()) < 0)
            {
                names.add(name);
            }
        }
        return names.toArray();
    }

    
Implements the childSpi method as per the specification in java.util.prefs.AbstractPreferences.childSpi(java.lang.String).

Parameters:
name child name
Returns:
child node
    @Override protected SectionPreferences childSpi(String name)
    {
        Ini.Section sec = .get(name);
        boolean isNew = sec == null;
        if (isNew)
        {
            sec = .add(name);
        }
        return new SectionPreferences(thissecisNew);
    }

    
Implements the flushSpi method as per the specification in java.util.prefs.AbstractPreferences.flushSpi(). This implementation does nothing.

Throws:
java.util.prefs.BackingStoreException if this operation cannot be completed due to a failure in the backing store, or inability to communicate with it.
    @Override protected void flushSpi() throws BackingStoreException
    {
        assert true;
    }

    
Implements the keysSpi method as per the specification in java.util.prefs.AbstractPreferences.keysSpi(). This implementation allways return an empty array.

Returns:
an empty array.
Throws:
java.util.prefs.BackingStoreException if this operation cannot be completed due to a failure in the backing store, or inability to communicate with it.
    @Override protected String[] keysSpi() throws BackingStoreException
    {
        return ;
    }

    
Implements the putSpi method as per the specification in java.util.prefs.AbstractPreferences.putSpi(java.lang.String,java.lang.String). This implementation doesn;t support this operation, so allways throws UnsupportedOperationException.

Parameters:
key key to set value for
value new value for key
Throws:
java.lang.UnsupportedOperationException this implementation allways throws this exception
    @Override protected void putSpi(String keyString valuethrows UnsupportedOperationException
    {
        throw new UnsupportedOperationException();
    }

    
Implements the removeNodeSpi method as per the specification in java.util.prefs.AbstractPreferences.removeNodeSpi(). This implementation doesn;t support this operation, so allways throws UnsupportedOperationException.

Throws:
java.lang.UnsupportedOperationException this implementation allways throws this exception
java.util.prefs.BackingStoreException this implementation never throws this exception
    {
        throw new UnsupportedOperationException();
    }

    
Implements the removeSpi method as per the specification in java.util.prefs.AbstractPreferences.removeSpi(java.lang.String).

Parameters:
key key to remove
Throws:
java.lang.UnsupportedOperationException this implementation allways throws this exception
    @Override protected void removeSpi(String keythrows UnsupportedOperationException
    {
        throw new UnsupportedOperationException();
    }

    
Implements the syncSpi method as per the specification in java.util.prefs.AbstractPreferences.syncSpi(). This implementation does nothing.

Throws:
java.util.prefs.BackingStoreException if this operation cannot be completed due to a failure in the backing store, or inability to communicate with it.
    @Override protected void syncSpi() throws BackingStoreException
    {
        assert true;
    }
    protected class SectionPreferences extends AbstractPreferences
    {

        
underlaying Section implementation
        private final Ini.Section _section;

        
Constructs a new SectionPreferences instance on top of Ini.Section instance.

Parameters:
parent parent preferences node
isNew indicate is this a new node or already existing one
Parem:
section underlaying Ini.Section instance
        SectionPreferences(AbstractPreferences parentIni.Section sectionboolean isNew)
        {
            super(parentsection.getSimpleName());
             = section;
             = isNew;
        }

        
Implements the flush method as per the specification in java.util.prefs.Preferences.flush(). This implementation just call parent's flush() method.

Throws:
java.util.prefs.BackingStoreException if this operation cannot be completed due to a failure in the backing store, or inability to communicate with it.
        @Override public void flush() throws BackingStoreException
        {
            parent().flush();
        }

        
Implements the sync method as per the specification in java.util.prefs.Preferences.sync(). This implementation just call parent's sync() method.

Throws:
java.util.prefs.BackingStoreException if this operation cannot be completed due to a failure in the backing store, or inability to communicate with it.
        @Override public void sync() throws BackingStoreException
        {
            parent().sync();
        }

        
Implements the getSpi method as per the specification in java.util.prefs.AbstractPreferences.getSpi(java.lang.String).

Parameters:
key key to getvalue for
Returns:
if the value associated with the specified key at this preference node, or null if there is no association for this key, or the association cannot be determined at this time.
        @Override protected String getSpi(String key)
        {
            return .fetch(key);
        }

        
Implements the childrenNamesSpi method as per the specification in java.util.prefs.AbstractPreferences.childrenNamesSpi(). This implementation allways returns an empty array.

Returns:
an emty array.
Throws:
java.util.prefs.BackingStoreException if this operation cannot be completed due to a failure in the backing store, or inability to communicate with it.
        @Override protected String[] childrenNamesSpi() throws BackingStoreException
        {
            return .childrenNames();
        }

        
Implements the childSpi method as per the specification in java.util.prefs.AbstractPreferences.childSpi(java.lang.String). This implementation doesn't support this operation.

Parameters:
name child name
Returns:
child node
Throws:
java.lang.UnsupportedOperationException this implementation allways throws this exception
        @Override protected SectionPreferences childSpi(String namethrows UnsupportedOperationException
        {
            Ini.Section child = .getChild(name);
            boolean isNew = child == null;
            if (isNew)
            {
                child = .addChild(name);
            }
            return new SectionPreferences(thischildisNew);
        }

        
Implements the flushSpi method as per the specification in java.util.prefs.AbstractPreferences.flushSpi(). This implementation does nothing.

Throws:
java.util.prefs.BackingStoreException if this operation cannot be completed due to a failure in the backing store, or inability to communicate with it.
        @Override protected void flushSpi() throws BackingStoreException
        {
            assert true;
        }

        
Implements the keysSpi method as per the specification in java.util.prefs.AbstractPreferences.keysSpi().

Returns:
an array of the keys that have an associated value in this preference node.
Throws:
java.util.prefs.BackingStoreException if this operation cannot be completed due to a failure in the backing store, or inability to communicate with it.
        @Override protected String[] keysSpi() throws BackingStoreException
        {
            return .keySet().toArray();
        }

        
Implements the putSpi method as per the specification in java.util.prefs.AbstractPreferences.putSpi(java.lang.String,java.lang.String).

Parameters:
key key to set value for
value new value of key
        @Override protected void putSpi(String keyString value)
        {
            .put(keyvalue);
        }

        
Implements the removeNodeSpi method as per the specification in java.util.prefs.AbstractPreferences.removeNodeSpi().

Throws:
java.util.prefs.BackingStoreException if this operation cannot be completed due to a failure in the backing store, or inability to communicate with it.
        @Override protected void removeNodeSpi() throws BackingStoreException
        {
            .remove();
        }

        
Implements the removeSpi method as per the specification in java.util.prefs.AbstractPreferences.removeSpi(java.lang.String).

Parameters:
key key to remove
        @Override protected void removeSpi(String key)
        {
            .remove(key);
        }

        
Implements the syncSpi method as per the specification in java.util.prefs.AbstractPreferences.syncSpi(). This implementation does nothing.

Throws:
java.util.prefs.BackingStoreException if this operation cannot be completed due to a failure in the backing store, or inability to communicate with it.
        @Override protected void syncSpi() throws BackingStoreException
        {
            assert true;
        }
    }
New to GrepCode? Check out our FAQ X