Commits

Anonymous committed 9370c12

Added method createValueModification

  • Participants
  • Parent commits 916b618

Comments (0)

Files changed (10)

File ecat-io/src/main/java/org/nrg/ecat/MatrixData.java

 
 
 import org.nrg.IOUtils;
+import org.nrg.ProgressListener;
 import org.nrg.ecat.var.Variable;
 
 /**
 	
 	
 	public static void copyWithModifications(final OutputStream out, final InputStream in,
-			final Collection modifications)
+			final Collection modifications, final ProgressListener progress)
 			throws IOException {
 		final Map m = sortModifications(modifications);
 		
 		
 		// TODO: directory list
 		// TODO: matrices
-		IOUtils.copy(out, in);
+		IOUtils.copy(out, in, progress);
 	}
 	
 	
 	public static void copyClearing(final OutputStream out, final InputStream in,
-			final Collection variables) throws IOException {
+			final Collection variables, final ProgressListener progress) throws IOException {
 		final Collection mods = new ArrayList(variables.size());
 		for (final Iterator i = variables.iterator(); i.hasNext(); ) {
 			mods.add(((Variable)i.next()).createClearModification());
 		}
-		copyWithModifications(out, in, mods);
+		copyWithModifications(out, in, mods, progress);
 	}
 	
 	

File ecat-io/src/main/java/org/nrg/ecat/var/AbstractVariable.java

 			}
 		};
 	}
-
 }

File ecat-io/src/main/java/org/nrg/ecat/var/CharacterVariable.java

 
 import java.io.IOException;
 import java.io.InputStream;
+import java.io.OutputStream;
 
+import org.nrg.ecat.AbstractHeaderModification;
 import org.nrg.ecat.HeaderModification;
 import org.nrg.ecat.Header.Type;
 
 	public HeaderModification createClearModification() {
 		return createClearModification(size);
 	}
+	
+	
+	/*
+	 * (non-Javadoc)
+	 * @see org.nrg.ecat.var.Variable#createValueModification(java.lang.Object)
+	 */
+	public HeaderModification createValueModification(final Object value) {
+		final byte[] bytes = new byte[size];
+		if (null != value) {
+			final String v = value.toString();
+			System.arraycopy(v.getBytes(), 0, bytes, 0, Math.min(size, v.length()));
+		}
+		
+		return new AbstractHeaderModification(getHeaderType(), getOffset()) {
+			public int modify(OutputStream to, InputStream from) throws IOException {
+				readFull(from, size);
+				to.write(bytes);
+				return size;
+			}
+		};
+	}
 }

File ecat-io/src/main/java/org/nrg/ecat/var/DateTimeVariable.java

 	public HeaderModification createClearModification() {
 		return createClearModification(4);
 	}
+	
+	
+	/*
+	 * (non-Javadoc)
+	 * @see org.nrg.ecat.var.Variable#createValueModification(java.lang.Object)
+	 */
+	public HeaderModification createValueModification(final Object value) {
+		throw new UnsupportedOperationException();	// TODO: implement
+	}
 }

File ecat-io/src/main/java/org/nrg/ecat/var/RealListVariable.java

 	public HeaderModification createClearModification() {
 		return createClearModification(4*length);
 	}
+	
+	
+	/*
+	 * (non-Javadoc)
+	 * @see org.nrg.ecat.var.Variable#createValueModification(java.lang.Object)
+	 */
+	public HeaderModification createValueModification(final Object value) {
+		throw new UnsupportedOperationException();	// TODO: implement
+	}
 }

File ecat-io/src/main/java/org/nrg/ecat/var/RealVariable.java

 	public HeaderModification createClearModification() {
 		return createClearModification(4);
 	}
+	
+	
+	/*
+	 * (non-Javadoc)
+	 * @see org.nrg.ecat.var.Variable#createValueModification(java.lang.Object)
+	 */
+	public HeaderModification createValueModification(final Object value) {
+		throw new UnsupportedOperationException();	// TODO: implement
+	}
 }

File ecat-io/src/main/java/org/nrg/ecat/var/ShortListVariable.java

 	public HeaderModification createClearModification() {
 		return createClearModification(2*length);
 	}
+	
+	
+	/*
+	 * (non-Javadoc)
+	 * @see org.nrg.ecat.var.Variable#createValueModification(java.lang.Object)
+	 */
+	public HeaderModification createValueModification(final Object value) {
+		throw new UnsupportedOperationException();	// TODO: implement
+	}
 }

File ecat-io/src/main/java/org/nrg/ecat/var/ShortVariable.java

 	public HeaderModification createClearModification() {
 		return createClearModification(2);
 	}
+	
+	/*
+	 * (non-Javadoc)
+	 * @see org.nrg.ecat.var.Variable#createValueModification(java.lang.Object)
+	 */
+	public HeaderModification createValueModification(final Object value) {
+		throw new UnsupportedOperationException();	// TODO: implement
+	}
 }

File ecat-io/src/main/java/org/nrg/ecat/var/Variable.java

 	String getName();
 	Object readValue(InputStream in) throws IOException;
 	HeaderModification createClearModification();
+	HeaderModification createValueModification(Object value);
 }

File ecat-io/src/test/java/org/nrg/ecat/var/AbstractVariableTest.java

 		public HeaderModification createClearModification() {
 			return createClearModification(4);
 		}
+		
+		public HeaderModification createValueModification(final Object value) {
+			throw new UnsupportedOperationException();	// TODO: implement
+		}
 	}
 	
 	/**