Skip to content

Commit

Permalink
remove temporary file writing when creating slurm submit script
Browse files Browse the repository at this point in the history
  • Loading branch information
jcschaff committed Aug 22, 2024
1 parent 30587dc commit ddd6f41
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 255 deletions.
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
package cbit.vcell.message.server.htc;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.CharBuffer;
import java.nio.channels.FileChannel;
import java.nio.charset.Charset;
import java.nio.charset.CharsetEncoder;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.Collection;
Expand All @@ -18,7 +17,6 @@

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.vcell.util.BeanUtils;
import org.vcell.util.document.KeyValue;
import org.vcell.util.exe.ExecutableException;

Expand Down Expand Up @@ -224,29 +222,22 @@ public static String createHtcSimJobName(SimTaskInfo simTaskInfo) {
return HTC_SIMULATION_JOB_NAME_PREFIX+simTaskInfo.simId.toString()+"_"+simTaskInfo.jobIndex+"_"+simTaskInfo.taskId;
}

public static void writeUnixStyleTextFile(File file, String javaString) throws IOException {
try (FileOutputStream fos = new FileOutputStream(file)) {
Charset asciiCharset = Charset.forName("US-ASCII");
CharsetEncoder encoder = asciiCharset.newEncoder();
CharBuffer unicodeCharBuffer = CharBuffer.wrap(javaString);
ByteBuffer asciiByteBuffer = encoder.encode(unicodeCharBuffer);
byte[] asciiArray = asciiByteBuffer.array();
ByteBuffer unixByteBuffer = ByteBuffer.allocate(asciiArray.length);
int count = 0;
for (int i=0;i<asciiArray.length;i++){
if (asciiArray[i] != 0x0d){ // skip \r character
unixByteBuffer.put(asciiArray[i]);
count++;
}
}
//do this to not write the zeros at the end of unixByteBuffer
ByteBuffer bb = ByteBuffer.wrap(unixByteBuffer.array(),0,count);

try (FileChannel fc = fos.getChannel()) {
fc.write(bb);
fc.close();
public static String toUnixStyleText(String javaString) throws IOException {
Charset asciiCharset = StandardCharsets.US_ASCII;
CharsetEncoder encoder = asciiCharset.newEncoder();
CharBuffer unicodeCharBuffer = CharBuffer.wrap(javaString);
ByteBuffer asciiByteBuffer = encoder.encode(unicodeCharBuffer);
byte[] asciiArray = asciiByteBuffer.array();
ByteBuffer unixByteBuffer = ByteBuffer.allocate(asciiArray.length);
int count = 0;
for (int i = 0; i < asciiArray.length; i++) {
if (asciiArray[i] != 0x0d) { // skip \r character
unixByteBuffer.put(asciiArray[i]);
count++;
}
}
ByteBuffer bb = ByteBuffer.wrap(unixByteBuffer.array(), 0, count);
return new String(bb.array(), 0, bb.limit(), asciiCharset);
}

public abstract String getSubmissionFileExtension();
Expand Down
Loading

0 comments on commit ddd6f41

Please sign in to comment.