Class XMLListHandler


  • @Immutable
    public final class XMLListHandler
    extends Object
    Simple class that reads a list from an XML input stream.
    The XML file needs to look as follows:
     <list>
       <item value="..."/>
       <item value="..."/>
       ...
     </list>
     
    Author:
    Philip Helger
    • Method Detail

      • readList

        @Nullable
        @ReturnsMutableCopy
        public static com.helger.commons.collection.impl.ICommonsList<String> readList​(@Nonnull
                                                                                       com.helger.commons.io.IHasInputStream aISP)
      • readList

        @Nullable
        @ReturnsMutableCopy
        public static com.helger.commons.collection.impl.ICommonsList<String> readList​(@Nonnull @WillClose
                                                                                       InputStream aIS)
        Read a predefined XML file that contains list items.
        Parameters:
        aIS - The input stream to read from. May not be null. Automatically closed no matter whether reading succeeded or not.
        Returns:
        null if reading fails - all list items otherwise.
      • readList

        @Nonnull
        public static com.helger.commons.state.ESuccess readList​(@Nonnull @WillClose
                                                                 InputStream aIS,
                                                                 @Nonnull
                                                                 Collection<String> aTargetList)
        Read a predefined XML file that contains list items.
        Parameters:
        aIS - The input stream to read from. May not be null. Automatically closed no matter whether reading succeeded or not.
        aTargetList - The target collection to be filled. May not be null.
        Returns:
        ESuccess.SUCCESS if reading succeeded, ESuccess.FAILURE if the input stream is no valid XML or any other error occurred.
      • writeList

        @Nonnull
        public static com.helger.commons.state.ESuccess writeList​(@Nonnull
                                                                  Collection<String> aCollection,
                                                                  @Nonnull @WillClose
                                                                  OutputStream aOS)
        Write the passed collection to the passed output stream using the predefined XML layout.
        Parameters:
        aCollection - The map to be written. May not be null.
        aOS - The output stream to write to. The stream is closed independent of success or failure. May not be null.
        Returns:
        ESuccess.SUCCESS when everything went well, ESuccess.FAILURE otherwise.