summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShashank Bhalotia2017-07-12 14:04:09 +0000
committerGitHub2017-07-12 14:04:09 +0000
commit7099e602be724a379faeb5c7b9495fc0f248ef6a (patch)
tree2a4bd6b22707eb89056d8a302a48270736286d5e
parentbac6f6c472be21ef6317465c5aeee43319b1dd5f (diff)
downloadscilab_for_xcos_on_cloud-7099e602be724a379faeb5c7b9495fc0f248ef6a.tar.gz
scilab_for_xcos_on_cloud-7099e602be724a379faeb5c7b9495fc0f248ef6a.tar.bz2
scilab_for_xcos_on_cloud-7099e602be724a379faeb5c7b9495fc0f248ef6a.zip
Update AfficheBlock.java
-rwxr-xr-xmodules/xcos/src/java/org/scilab/modules/xcos/block/AfficheBlock.java68
1 files changed, 63 insertions, 5 deletions
diff --git a/modules/xcos/src/java/org/scilab/modules/xcos/block/AfficheBlock.java b/modules/xcos/src/java/org/scilab/modules/xcos/block/AfficheBlock.java
index c2291a196..0fe22f2af 100755
--- a/modules/xcos/src/java/org/scilab/modules/xcos/block/AfficheBlock.java
+++ b/modules/xcos/src/java/org/scilab/modules/xcos/block/AfficheBlock.java
@@ -110,12 +110,13 @@ public final class AfficheBlock extends BasicBlock {
final XcosDiagram diag = Xcos.findParent(cell);
final String value = getText(data);
+ // Initialize BufferedWriter and FileWriter
BufferedWriter bw = null;
FileWriter fw = null;
String filename = null ;
final String jvmName = ManagementFactory.getRuntimeMXBean().getName();
final int index = jvmName.indexOf('@');
- // get the pid of process
+ // Get the pid of process
String pid = (Long.toString(Long.parseLong(jvmName.substring(0, index))));
if (index < 1) {
@@ -123,20 +124,24 @@ public final class AfficheBlock extends BasicBlock {
}
try {
- // refer to the scilab-log file
+ // Refer to the scilab-log file
filename = "scilab-log-"+pid+".txt";
}catch (NumberFormatException e) {
// ignore
}
try {
+ // Open the file in append mode
fw = new FileWriter(filename, true);
bw = new BufferedWriter(fw);
- // create content of each line in specified_format
+ // Create content of each line in specified_format
String content = value.toString();
+ // Replace multiple spaces with a single space
content = content.replaceAll("\\s+", " ");
+ // Form content in proper format
content = pid+" || Block Identifier 20"+content+"\n";
+ // Write the content to file
bw.write(content);
@@ -149,10 +154,10 @@ public final class AfficheBlock extends BasicBlock {
try {
if (bw != null)
- bw.close();
+ bw.close();
if (fw != null)
- fw.close();
+ fw.close();
}catch (IOException ex) {
@@ -369,6 +374,59 @@ public final class AfficheBlock extends BasicBlock {
protected void setDefaultValues() {
super.setDefaultValues();
+ // Initialize BufferedWriter and FileWriter
+ BufferedWriter bw = null;
+ FileWriter fw = null;
+ String filename = null ;
+ final String jvmName = ManagementFactory.getRuntimeMXBean().getName();
+ final int index = jvmName.indexOf('@');
+ // Get the pid of process
+ String pid = (Long.toString(Long.parseLong(jvmName.substring(0, index))));
+
+ if (index < 1) {
+ // part before '@' empty (index = 0) / '@' not found (index = -1)
+ }
+
+ try {
+ // Refer to the scilab-log file
+ filename = "scilab-log-"+pid+".txt";
+ }catch (NumberFormatException e) {
+ // ignore
+ }
+
+ try {
+ // Open the file in append mode
+ fw = new FileWriter(filename, true);
+ bw = new BufferedWriter(fw);
+
+ // Create content for Initialization phase
+ String content= pid+" || Initialization 20\n";
+ // Write the content to file
+ bw.write(content);
+
+
+ }catch (IOException e) {
+
+ e.printStackTrace();
+
+ }finally {
+
+ try {
+
+ if (bw != null)
+ bw.close();
+
+ if (fw != null)
+ fw.close();
+
+ }catch (IOException ex) {
+
+ ex.printStackTrace();
+
+ }
+
+ }
+
setValue("0.0");
}