You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by fm...@apache.org on 2007/08/06 10:05:18 UTC
svn commit: r563060 - in /felix/sandbox/fmeschbe/configdamin_bundled_config:
README.txt
src/main/java/org/apache/felix/cm/impl/ConfigurationFileInputStream.java
Author: fmeschbe
Date: Mon Aug 6 01:05:17 2007
New Revision: 563060
URL: http://svn.apache.org/viewvc?view=rev&rev=563060
Log:
ConfigurationFile Input stream class and README for this sandbox
Added:
felix/sandbox/fmeschbe/configdamin_bundled_config/README.txt
felix/sandbox/fmeschbe/configdamin_bundled_config/src/main/java/org/apache/felix/cm/impl/ConfigurationFileInputStream.java
Added: felix/sandbox/fmeschbe/configdamin_bundled_config/README.txt
URL: http://svn.apache.org/viewvc/felix/sandbox/fmeschbe/configdamin_bundled_config/README.txt?view=auto&rev=563060
==============================================================================
--- felix/sandbox/fmeschbe/configdamin_bundled_config/README.txt (added)
+++ felix/sandbox/fmeschbe/configdamin_bundled_config/README.txt Mon Aug 6 01:05:17 2007
@@ -0,0 +1,7 @@
+This code is an extension to the Apache Felix Configuration Admin
+with prototype implementation for support of bundling configuration
+data with bundles.
+
+This code somewhat duplicates the work of the OSGi Auto Configuration
+Specification and therefore will probably not make it into the
+trunk code. Still, I do want to keep the code for the moment.
Added: felix/sandbox/fmeschbe/configdamin_bundled_config/src/main/java/org/apache/felix/cm/impl/ConfigurationFileInputStream.java
URL: http://svn.apache.org/viewvc/felix/sandbox/fmeschbe/configdamin_bundled_config/src/main/java/org/apache/felix/cm/impl/ConfigurationFileInputStream.java?view=auto&rev=563060
==============================================================================
--- felix/sandbox/fmeschbe/configdamin_bundled_config/src/main/java/org/apache/felix/cm/impl/ConfigurationFileInputStream.java (added)
+++ felix/sandbox/fmeschbe/configdamin_bundled_config/src/main/java/org/apache/felix/cm/impl/ConfigurationFileInputStream.java Mon Aug 6 01:05:17 2007
@@ -0,0 +1,219 @@
+/*
+ * $Url: $
+ * $Id: $
+ *
+ * Copyright 1997-2005 Day Management AG
+ * Barfuesserplatz 6, 4001 Basel, Switzerland
+ * All Rights Reserved.
+ *
+ * This software is the confidential and proprietary information of
+ * Day Management AG, ("Confidential Information"). You shall not
+ * disclose such Confidential Information and shall use it only in
+ * accordance with the terms of the license agreement you entered into
+ * with Day.
+ */
+package org.apache.felix.cm.impl;
+
+import java.awt.image.ImagingOpException;
+import java.io.FilterInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+
+/**
+ * The <code>ConfigurationFileInputStream</code> TODO
+ */
+class ConfigurationFileInputStream extends FilterInputStream
+{
+
+ boolean isEof;
+ boolean ignoreEol;
+ boolean lastWasEol;
+ String nextEntry;
+ int unread;
+
+ /**
+ * @param in
+ */
+ public ConfigurationFileInputStream( InputStream in )
+ {
+ super( in );
+
+ // initial settings
+ isEof = false;
+ ignoreEol = false;
+ lastWasEol = true;
+ nextEntry = null;
+ unread = -1;
+ }
+
+ String getNextEntry() throws IOException {
+
+ // if we did not yet exhaust the previous section, force skipping to
+ // next section and reading the section. Otherwise the section
+ // will already have been read when EOF was signalled
+ if (!isEof) {
+ nextEntry = null;
+ findNextEntry();
+ }
+
+ isEof = false; // not eof, entry might/will contain data
+ lastWasEol = true; // force starting on new line after section heading
+
+ return nextEntry;
+ }
+
+ public int read() throws IOException
+ {
+ // have reached eof, need to getNextEntry first
+ if (isEof) {
+ return -1;
+ }
+
+ int c = doRead();
+ if (c < 0) {
+ return c;
+ }
+
+ boolean isEol = c == '\n';
+
+ if (c == '\\') {
+ ignoreEol = true;
+ return c;
+ }
+
+ if (isEol) {
+ if (!ignoreEol) {
+ lastWasEol = true;
+ }
+ return c;
+ }
+
+ ignoreEol = false;
+
+ if (lastWasEol) {
+ lastWasEol = false;
+
+ // ignore a comment line first
+ if (c == '#') {
+ // ignore comment up to end of line
+
+ // read up to end of line
+ while (c >= 0 && c != '\n') {
+ c = doRead();
+ }
+
+ // read end of line
+ if (c == '\n') {
+ c = doRead();
+ }
+ }
+
+ // now, we will be on a line start, which may be a section
+ if (c == '[') {
+ // read entry tag
+ readNextEntry();
+
+ // eof on start of next entry
+ isEof = true;
+ return -1;
+ }
+
+ }
+
+ return c;
+ }
+
+ public int read( byte[] b, int off, int len ) throws IOException
+ {
+ if ( b == null )
+ {
+ throw new NullPointerException();
+ }
+ else if ( ( off < 0 ) || ( off > b.length ) || ( len < 0 ) || ( ( off + len ) > b.length )
+ || ( ( off + len ) < 0 ) )
+ {
+ throw new IndexOutOfBoundsException();
+ }
+ else if ( len == 0 )
+ {
+ return 0;
+ }
+
+ int c = read();
+ if ( c == -1 )
+ {
+ return -1;
+ }
+ b[off] = ( byte ) c;
+
+ int i = 1;
+ try
+ {
+ for ( ; i < len; i++ )
+ {
+ c = read();
+ if ( c == -1 )
+ {
+ break;
+ }
+ if ( b != null )
+ {
+ b[off + i] = ( byte ) c;
+ }
+ }
+ }
+ catch ( IOException ee )
+ {
+ }
+ return i;
+ }
+
+ private void findNextEntry() throws IOException {
+ int c = read();
+ while (c >= 0 && nextEntry == null) {
+ c = read();
+ }
+ }
+
+ private int doRead() throws IOException {
+ int c = (unread < 0) ? super.read() : unread;
+
+ unread = -1;
+
+ if (c == '\n' || c == '\r') {
+ int next = super.read();
+ if (next != c && (next == '\n' || next == '\r')) {
+ // this was CR-LF or LF-CR
+ // this next is simply ignored
+ } else {
+ // fold \r into \n
+ if (next == c) {
+ c = next = '\n';
+ }
+
+ // new line of same kind or any other character
+ unread = next;
+ }
+ }
+
+ return c;
+ }
+
+ private void readNextEntry() throws IOException {
+ // next read will return the first character of the section name
+
+ StringBuffer nameBuffer = new StringBuffer();
+ int c = doRead();
+ while (c >= 0 && c != '\n' && c!= ']') {
+ nameBuffer.append((char) c);
+ c = doRead();
+ }
+
+ // find end of line
+ while (c >= 0 && c != '\n') {
+ c = doRead();
+ }
+
+ nextEntry = (nameBuffer.length() > 0) ? nameBuffer.toString() : null;
+ }
+}