Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Writing an Element object to file using java

I have a data of Element class. I'm trying to write its values to a file but I'm having trouble:

< Some process to acquire values into the variable "fieldData" >

// Prepare file output
FileWriter fstream = new FileWriter("C:/output.txt");
BufferedWriter out = new BufferedWriter(fstream);

Element field = fieldData.getElement(i);

out.write(field);  // DOESN'T WORK: The method write(int) in the type BufferedWriter is not applicable for the arguments (Element)
out.write(field.getValueAsString()); // DOESN'T WORK: Cannot convert SEQUENCE to String

Any suggestions on how I should handle this case? In addition, what is the best way for me to see (i.e. print out to screen) the available static variables and methods associated with an object? Thx.

More code snippets to help debug:

private static final Name SECURITY_DATA = new Name("securityData");
private static final Name FIELD_DATA = new Name("fieldData");

Element securityDataArray = msg.getElement(SECURITY_DATA); // msg is a Bloomberg desktop API object
Element securityData = securityDataArray.getValueAsElement(0);
Element fieldData = securityData.getElement(FIELD_DATA);
Element field = fieldData.getElement(0)
out.write(field);  // DOESN'T WORK: The method write(int) in the type BufferedWriter is not applicable for the arguments (Element)
out.write(field.getValueAsString()); // DOESN'T WORK: Cannot convert SEQUENCE to String
like image 581
Zhang18 Avatar asked Jan 27 '26 13:01

Zhang18


1 Answers

Turns out that this Bloomberg Prop data structure is long-winded to say the least:

private static final Name SECURITY_DATA = new Name("securityData");
private static final Name FIELD_DATA = new Name("fieldData");

Element securityDataArray = msg.getElement(SECURITY_DATA); // msg is a Bloomberg desktop API object
Element securityData = securityDataArray.getValueAsElement(0);
Element fieldData = securityData.getElement(FIELD_DATA);
Element field = fieldData.getElement(0); 

/* the above codes were known at the time of the question */
/* below is what I was shown by a bloomberg representative */

Element bulkElement = field.getValueAsElement(0);
Element elem = bulkElement.getElement(0);
out.write(elem.name() + "\t" + elem.getValueAsString() + "\n");

whew...I don't think they try to make it easy! I'm also curious as to if there was a way that I could have figure this out by having Java print out the right method to use to trace down the data structure?

like image 187
Zhang18 Avatar answered Jan 30 '26 02:01

Zhang18