SLING-5190 factor out of SlingSettingsServiceImpl a Sling ID util

* move readSlingId(File, int):String and writeSlingId(File, String):void from SlingSettingsServiceImpl to new class SlingIdUtil

git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1710166 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/src/main/java/org/apache/sling/settings/impl/SlingIdUtil.java b/src/main/java/org/apache/sling/settings/impl/SlingIdUtil.java
new file mode 100644
index 0000000..95032c2
--- /dev/null
+++ b/src/main/java/org/apache/sling/settings/impl/SlingIdUtil.java
@@ -0,0 +1,85 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.apache.sling.settings.impl;
+
+import java.io.DataInputStream;
+import java.io.DataOutputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.util.UUID;
+
+public class SlingIdUtil {
+
+    /**
+     * Read the id from a file.
+     */
+    static String readSlingId(final File idFile, int maxLength) {
+        if (idFile.exists() && idFile.length() >= maxLength) {
+            DataInputStream dis = null;
+            try {
+                final byte[] rawBytes = new byte[maxLength];
+                dis = new DataInputStream(new FileInputStream(idFile));
+                dis.readFully(rawBytes);
+                final String rawString = new String(rawBytes, "ISO-8859-1");
+
+                // roundtrip to ensure correct format of UUID value
+                final String id = UUID.fromString(rawString).toString();
+                // logger.debug("Got Sling ID {} from file {}", id, idFile);
+
+                return id;
+            } catch (final Throwable t) {
+                // logger.error("Failed reading UUID from id file " + idFile
+                //        + ", creating new id", t);
+            } finally {
+                if (dis != null) {
+                    try {
+                        dis.close();
+                    } catch (IOException ignore){}
+                }
+            }
+        }
+        return null;
+    }
+
+    /**
+     * Write the sling id file.
+     */
+    static void writeSlingId(final File idFile, final String id) {
+        idFile.delete();
+        idFile.getParentFile().mkdirs();
+        DataOutputStream dos = null;
+        try {
+            final byte[] rawBytes = id.getBytes("ISO-8859-1");
+            dos = new DataOutputStream(new FileOutputStream(idFile));
+            dos.write(rawBytes, 0, rawBytes.length);
+            dos.flush();
+        } catch (final Throwable t) {
+            // logger.error("Failed writing UUID to id file " + idFile, t);
+        } finally {
+            if (dos != null) {
+                try {
+                    dos.close();
+                } catch (IOException ignore) {}
+            }
+        }
+    }
+
+}
diff --git a/src/main/java/org/apache/sling/settings/impl/SlingSettingsServiceImpl.java b/src/main/java/org/apache/sling/settings/impl/SlingSettingsServiceImpl.java
index 56448c5..1899aa3 100644
--- a/src/main/java/org/apache/sling/settings/impl/SlingSettingsServiceImpl.java
+++ b/src/main/java/org/apache/sling/settings/impl/SlingSettingsServiceImpl.java
@@ -18,8 +18,6 @@
  */
 package org.apache.sling.settings.impl;
 
-import java.io.DataInputStream;
-import java.io.DataOutputStream;
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.FileOutputStream;
@@ -129,12 +127,12 @@
             // the osgi framework does not support storing something in the file system
             throw new RuntimeException("Unable to read from bundle data file.");
         }
-        this.slingId = this.readSlingId(idFile, SLING_ID_LENGTH);
+        this.slingId = SlingIdUtil.readSlingId(idFile, SLING_ID_LENGTH);
 
         // no sling id yet or failure to read file: create an id and store
         if (slingId == null) {
             slingId = UUID.randomUUID().toString();
-            this.writeSlingId(idFile, this.slingId);
+            SlingIdUtil.writeSlingId(idFile, this.slingId);
         }
     }
 
@@ -290,60 +288,6 @@
     }
 
     /**
-     * Read the id from a file.
-     */
-    String readSlingId(final File idFile, int maxLength) {
-        if (idFile.exists() && idFile.length() >= maxLength) {
-            DataInputStream dis = null;
-            try {
-                final byte[] rawBytes = new byte[maxLength];
-                dis = new DataInputStream(new FileInputStream(idFile));
-                dis.readFully(rawBytes);
-                final String rawString = new String(rawBytes, "ISO-8859-1");
-
-                // roundtrip to ensure correct format of UUID value
-                final String id = UUID.fromString(rawString).toString();
-                logger.debug("Got Sling ID {} from file {}", id, idFile);
-
-                return id;
-            } catch (final Throwable t) {
-                logger.error("Failed reading UUID from id file " + idFile
-                        + ", creating new id", t);
-            } finally {
-                if (dis != null) {
-                    try {
-                        dis.close();
-                    } catch (IOException ignore){}
-                }
-            }
-        }
-        return null;
-    }
-
-    /**
-     * Write the sling id file.
-     */
-    void writeSlingId(final File idFile, final String id) {
-        idFile.delete();
-        idFile.getParentFile().mkdirs();
-        DataOutputStream dos = null;
-        try {
-            final byte[] rawBytes = id.getBytes("ISO-8859-1");
-            dos = new DataOutputStream(new FileOutputStream(idFile));
-            dos.write(rawBytes, 0, rawBytes.length);
-            dos.flush();
-        } catch (final Throwable t) {
-            logger.error("Failed writing UUID to id file " + idFile, t);
-        } finally {
-            if (dos != null) {
-                try {
-                    dos.close();
-                } catch (IOException ignore) {}
-            }
-        }
-    }
-
-    /**
      * @see org.apache.sling.settings.SlingSettingsService#getAbsolutePathWithinSlingHome(String)
      */
     public String getAbsolutePathWithinSlingHome(final String relativePath) {
diff --git a/src/test/java/org/apache/sling/settings/impl/SlingSettingsServiceImplTest.java b/src/test/java/org/apache/sling/settings/impl/SlingSettingsServiceImplTest.java
index 81e3dd1..732f69b 100644
--- a/src/test/java/org/apache/sling/settings/impl/SlingSettingsServiceImplTest.java
+++ b/src/test/java/org/apache/sling/settings/impl/SlingSettingsServiceImplTest.java
@@ -108,13 +108,13 @@
     private String readSlingId(File slingIdFile, File optionsFile, int maxLength)
             throws IOException {
         SlingSettingsServiceImpl settings = getSlingSettings(slingIdFile, optionsFile);
-        return settings.readSlingId(slingIdFile, maxLength);
+        return SlingIdUtil.readSlingId(slingIdFile, maxLength);
     }
 
     private void writeSlingId(File slingIdFile, File optionsFile, String slingId)
             throws IOException {
         SlingSettingsServiceImpl settings = getSlingSettings(slingIdFile, optionsFile);
-        settings.writeSlingId(slingIdFile, slingId);
+        SlingIdUtil.writeSlingId(slingIdFile, slingId);
     }
 
     private SlingSettingsServiceImpl getSlingSettings(File slingIdFile, File optionsFile)