sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From o...@apache.org
Subject svn commit: r1710243 - in /sling/trunk/bundles/extensions/settings/src: main/java/org/apache/sling/settings/impl/ test/java/org/apache/sling/settings/impl/
Date Fri, 23 Oct 2015 15:37:01 GMT
Author: olli
Date: Fri Oct 23 15:37:01 2015
New Revision: 1710243

URL: http://svn.apache.org/viewvc?rev=1710243&view=rev
Log:
SLING-5190 factor out of SlingSettingsServiceImpl a Sling ID util

* make the Sling ID length an internal of SlingIdUtil

Modified:
    sling/trunk/bundles/extensions/settings/src/main/java/org/apache/sling/settings/impl/SlingIdUtil.java
    sling/trunk/bundles/extensions/settings/src/main/java/org/apache/sling/settings/impl/SlingSettingsServiceImpl.java
    sling/trunk/bundles/extensions/settings/src/test/java/org/apache/sling/settings/impl/SlingSettingsServiceImplTest.java

Modified: sling/trunk/bundles/extensions/settings/src/main/java/org/apache/sling/settings/impl/SlingIdUtil.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/settings/src/main/java/org/apache/sling/settings/impl/SlingIdUtil.java?rev=1710243&r1=1710242&r2=1710243&view=diff
==============================================================================
--- sling/trunk/bundles/extensions/settings/src/main/java/org/apache/sling/settings/impl/SlingIdUtil.java
(original)
+++ sling/trunk/bundles/extensions/settings/src/main/java/org/apache/sling/settings/impl/SlingIdUtil.java
Fri Oct 23 15:37:01 2015
@@ -28,6 +28,9 @@ import java.util.UUID;
 
 public class SlingIdUtil {
 
+    /** The length in bytes of a sling identifier */
+    private static final int SLING_ID_LENGTH = 36;
+
     public static String createSlingId() {
         return UUID.randomUUID().toString();
     }
@@ -35,11 +38,11 @@ public class SlingIdUtil {
     /**
      * Read the id from a file.
      */
-    public static String readSlingId(final File idFile, int maxLength) throws IOException
{
-        if (idFile.exists() && idFile.length() >= maxLength) {
+    public static String readSlingId(final File idFile) throws IOException {
+        if (idFile.exists() && idFile.length() >= SLING_ID_LENGTH) {
             DataInputStream dis = null;
             try {
-                final byte[] rawBytes = new byte[maxLength];
+                final byte[] rawBytes = new byte[SLING_ID_LENGTH];
                 dis = new DataInputStream(new FileInputStream(idFile));
                 dis.readFully(rawBytes);
                 final String rawString = new String(rawBytes, "ISO-8859-1");

Modified: sling/trunk/bundles/extensions/settings/src/main/java/org/apache/sling/settings/impl/SlingSettingsServiceImpl.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/settings/src/main/java/org/apache/sling/settings/impl/SlingSettingsServiceImpl.java?rev=1710243&r1=1710242&r2=1710243&view=diff
==============================================================================
--- sling/trunk/bundles/extensions/settings/src/main/java/org/apache/sling/settings/impl/SlingSettingsServiceImpl.java
(original)
+++ sling/trunk/bundles/extensions/settings/src/main/java/org/apache/sling/settings/impl/SlingSettingsServiceImpl.java
Fri Oct 23 15:37:01 2015
@@ -76,9 +76,6 @@ public class SlingSettingsServiceImpl
     /** The name of the data file holding install run mode options */
     private static final String OPTIONS_FILE = "sling.options.file";
 
-    /** The length in bytes of a sling identifier */
-    private static final int SLING_ID_LENGTH = 36;
-
     /** The properties for name, description. */
     private final Map<String, String> slingProps = new HashMap<String, String>();
 
@@ -128,7 +125,7 @@ public class SlingSettingsServiceImpl
         }
 
         try {
-            slingId = SlingIdUtil.readSlingId(idFile, SLING_ID_LENGTH);
+            slingId = SlingIdUtil.readSlingId(idFile);
             logger.info("Read Sling ID {} from file {}", slingId, idFile);
         } catch (final Throwable t) {
             logger.error("Failed reading Sling ID from file " + idFile, t);

Modified: sling/trunk/bundles/extensions/settings/src/test/java/org/apache/sling/settings/impl/SlingSettingsServiceImplTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/settings/src/test/java/org/apache/sling/settings/impl/SlingSettingsServiceImplTest.java?rev=1710243&r1=1710242&r2=1710243&view=diff
==============================================================================
--- sling/trunk/bundles/extensions/settings/src/test/java/org/apache/sling/settings/impl/SlingSettingsServiceImplTest.java
(original)
+++ sling/trunk/bundles/extensions/settings/src/test/java/org/apache/sling/settings/impl/SlingSettingsServiceImplTest.java
Fri Oct 23 15:37:01 2015
@@ -69,7 +69,7 @@ public class SlingSettingsServiceImplTes
     @Test
     public void testGenerateSlingId()
             throws IOException {
-        String slingId =  readSlingId(slingIdFile, optionsFile, SLING_ID.length());
+        String slingId =  readSlingId(slingIdFile, optionsFile);
         Assert.assertNotNull(slingId);
     }
 
@@ -77,10 +77,10 @@ public class SlingSettingsServiceImplTes
     public void testGetSlingId()
             throws IOException {
         writeSlingId(slingIdFile, optionsFile, SLING_ID);
-        String generated =  readSlingId(slingIdFile, optionsFile, SLING_ID.length());
+        String generated =  readSlingId(slingIdFile, optionsFile);
         Assert.assertNotNull(generated);
         Assert.assertEquals(SLING_ID, generated);
-        String slingId = readSlingId(slingIdFile, optionsFile, SLING_ID.length());
+        String slingId = readSlingId(slingIdFile, optionsFile);
         Assert.assertNotNull(slingId);
         Assert.assertEquals(generated, slingId);
     }
@@ -90,7 +90,7 @@ public class SlingSettingsServiceImplTes
             throws IOException {
         String data = SLING_ID + RandomStringUtils.randomAscii(1024 * 1024); // 1MB long
random String
         writeSlingId(slingIdFile, optionsFile, data);
-        String slingId =  readSlingId(slingIdFile, optionsFile, SLING_ID.length());
+        String slingId =  readSlingId(slingIdFile, optionsFile);
         Assert.assertNotNull(slingId);
         Assert.assertEquals(SLING_ID, slingId);
     }
@@ -100,15 +100,15 @@ public class SlingSettingsServiceImplTes
             throws IOException {
         String data = RandomStringUtils.randomAscii(8); // 8 byte long string
         writeSlingId(slingIdFile, optionsFile, data);
-        String slingId =  readSlingId(slingIdFile, optionsFile, SLING_ID.length());
+        String slingId =  readSlingId(slingIdFile, optionsFile);
         Assert.assertNotNull(slingId);
         Assert.assertNotEquals(SLING_ID, slingId);
     }
 
-    private String readSlingId(File slingIdFile, File optionsFile, int maxLength)
+    private String readSlingId(File slingIdFile, File optionsFile)
             throws IOException {
         SlingSettingsServiceImpl settings = getSlingSettings(slingIdFile, optionsFile);
-        return SlingIdUtil.readSlingId(slingIdFile, maxLength);
+        return SlingIdUtil.readSlingId(slingIdFile);
     }
 
     private void writeSlingId(File slingIdFile, File optionsFile, String slingId)



Mime
View raw message