Tally not importing data from XML - java

I am developing tally application in swing. Now I want integrate with the Tally.
If I import the data to Tally I am getting error like this.
Importing Data from 'New.xml' on 13-Apr-2016 at 14:11:51
Importing Data to company: 'Technologies Pvt Ltd'
ERROR: Voucher: ID:<REMOTEID:face3a8f-f920-4781-a14b-ed095d0b0145-00000006>, Voucher Type: Payment, Source Voucher Number: 203, Voucher Number: , Date:
Import Summary
Created : 0
Altered : 0
Deleted : 0
Combined: 0
Ignored : 0
Errors : 1
----------------------------------------------
This is my XML file.
<ENVELOPE>
<HEADER>
<TALLYREQUEST>Import Data</TALLYREQUEST>
</HEADER>
<BODY>
<IMPORTDATA>
<REQUESTDESC>
<REPORTNAME>Vouchers</REPORTNAME>
<STATICVARIABLES>
<SVCURRENTCOMPANY>Technologies Pvt Ltd</SVCURRENTCOMPANY>
</STATICVARIABLES>
</REQUESTDESC>
<REQUESTDATA>
<TALLYMESSAGE xmlns:UDF="TallyUDF">
<VOUCHER REMOTEID="face3a8f-f920-4781-a14b-ed095d0b0145-00000006" VCHKEY="face3a8f-f920-4781-a14b-ed095d0b0145-0000a748:000000061" VCHTYPE="Payment" ACTION="Create" OBJVIEW="Accounting Voucher View">
<OLDAUDITENTRYIDS.LIST TYPE="Number">
<OLDAUDITENTRYIDS>-1</OLDAUDITENTRYIDS>
</OLDAUDITENTRYIDS.LIST>
<DATE>20160413</DATE>
<GUID>face3a8f-f920-4781-a14b-ed095d0b0145-00000006</GUID>
<NARRATION>100</NARRATION>
<VOUCHERTYPENAME>Payment</VOUCHERTYPENAME>
<VOUCHERNUMBER>203</VOUCHERNUMBER>
<PARTYLEDGERNAME>Cash</PARTYLEDGERNAME>
<CSTFORMISSUETYPE/>
<CSTFORMRECVTYPE/>
<FBTPAYMENTTYPE>Default</FBTPAYMENTTYPE>
<PERSISTEDVIEW>Accounting Voucher View</PERSISTEDVIEW>
<VCHGSTCLASS/>
<DIFFACTUALQTY>No</DIFFACTUALQTY>
<ISMSTFROMSYNC>No</ISMSTFROMSYNC>
<ASORIGINAL>No</ASORIGINAL>
<AUDITED>No</AUDITED>
<FORJOBCOSTING>No</FORJOBCOSTING>
<ISOPTIONAL>No</ISOPTIONAL>
<EFFECTIVEDATE>20170331</EFFECTIVEDATE>
<USEFOREXCISE>No</USEFOREXCISE>
<ISFORJOBWORKIN>No</ISFORJOBWORKIN>
<ALLOWCONSUMPTION>No</ALLOWCONSUMPTION>
<USEFORINTEREST>No</USEFORINTEREST>
<USEFORGAINLOSS>No</USEFORGAINLOSS>
<USEFORGODOWNTRANSFER>No</USEFORGODOWNTRANSFER>
<USEFORCOMPOUND>No</USEFORCOMPOUND>
<USEFORSERVICETAX>No</USEFORSERVICETAX>
<ISEXCISEVOUCHER>No</ISEXCISEVOUCHER>
<EXCISETAXOVERRIDE>No</EXCISETAXOVERRIDE>
<USEFORTAXUNITTRANSFER>No</USEFORTAXUNITTRANSFER>
<EXCISEOPENING>No</EXCISEOPENING>
<USEFORFINALPRODUCTION>No</USEFORFINALPRODUCTION>
<ISTDSOVERRIDDEN>No</ISTDSOVERRIDDEN>
<ISTCSOVERRIDDEN>No</ISTCSOVERRIDDEN>
<ISTDSTCSCASHVCH>No</ISTDSTCSCASHVCH>
<INCLUDEADVPYMTVCH>No</INCLUDEADVPYMTVCH>
<ISSUBWORKSCONTRACT>No</ISSUBWORKSCONTRACT>
<ISVATOVERRIDDEN>No</ISVATOVERRIDDEN>
<IGNOREORIGVCHDATE>No</IGNOREORIGVCHDATE>
<ISSERVICETAXOVERRIDDEN>No</ISSERVICETAXOVERRIDDEN>
<ISISDVOUCHER>No</ISISDVOUCHER>
<ISEXCISEOVERRIDDEN>No</ISEXCISEOVERRIDDEN>
<ISEXCISESUPPLYVCH>No</ISEXCISESUPPLYVCH>
<ISVATPRINCIPALACCOUNT>No</ISVATPRINCIPALACCOUNT>
<ISSHIPPINGWITHINSTATE>No</ISSHIPPINGWITHINSTATE>
<ISCANCELLED>No</ISCANCELLED>
<HASCASHFLOW>Yes</HASCASHFLOW>
<ISPOSTDATED>No</ISPOSTDATED>
<USETRACKINGNUMBER>No</USETRACKINGNUMBER>
<ISINVOICE>No</ISINVOICE>
<MFGJOURNAL>No</MFGJOURNAL>
<HASDISCOUNTS>No</HASDISCOUNTS>
<ASPAYSLIP>No</ASPAYSLIP>
<ISCOSTCENTRE>No</ISCOSTCENTRE>
<ISSTXNONREALIZEDVCH>No</ISSTXNONREALIZEDVCH>
<ISEXCISEMANUFACTURERON>No</ISEXCISEMANUFACTURERON>
<ISBLANKCHEQUE>No</ISBLANKCHEQUE>
<ISVOID>No</ISVOID>
<ISONHOLD>No</ISONHOLD>
<ORDERLINESTATUS>No</ORDERLINESTATUS>
<VATISAGNSTCANCSALES>No</VATISAGNSTCANCSALES>
<VATISPURCEXEMPTED>No</VATISPURCEXEMPTED>
<ISVATRESTAXINVOICE>No</ISVATRESTAXINVOICE>
<ISDELETED>No</ISDELETED>
<CHANGEVCHMODE>No</CHANGEVCHMODE>
<ALTERID/>
<MASTERID/>
<VOUCHERKEY>183927679483912</VOUCHERKEY>
<EXCLUDEDTAXATIONS.LIST/>
<OLDAUDITENTRIES.LIST/>
<ACCOUNTAUDITENTRIES.LIST/>
<AUDITENTRIES.LIST/>
<DUTYHEADDETAILS.LIST/>
<SUPPLEMENTARYDUTYHEADDETAILS.LIST/>
<INVOICEDELNOTES.LIST/>
<INVOICEORDERLIST.LIST/>
<INVOICEINDENTLIST.LIST/>
<ATTENDANCEENTRIES.LIST/>
<ORIGINVOICEDETAILS.LIST/>
<INVOICEEXPORTLIST.LIST/>
<ALLLEDGERENTRIES.LIST>
<OLDAUDITENTRYIDS.LIST TYPE="Number">
<OLDAUDITENTRYIDS>-1</OLDAUDITENTRYIDS>
</OLDAUDITENTRYIDS.LIST>
<LEDGERNAME>WATER EXP</LEDGERNAME>
<GSTCLASS/>
<ISDEEMEDPOSITIVE>Yes</ISDEEMEDPOSITIVE>
<LEDGERFROMITEM>No</LEDGERFROMITEM>
<REMOVEZEROENTRIES>No</REMOVEZEROENTRIES>
<ISPARTYLEDGER>No</ISPARTYLEDGER>
<ISLASTDEEMEDPOSITIVE>Yes</ISLASTDEEMEDPOSITIVE>
<AMOUNT>-100.00</AMOUNT>
<SERVICETAXDETAILS.LIST/>
<BANKALLOCATIONS.LIST/>
<BILLALLOCATIONS.LIST/>
<INTERESTCOLLECTION.LIST/>
<OLDAUDITENTRIES.LIST/>
<ACCOUNTAUDITENTRIES.LIST/>
<AUDITENTRIES.LIST/>
<INPUTCRALLOCS.LIST/>
<DUTYHEADDETAILS.LIST/>
<EXCISEDUTYHEADDETAILS.LIST/>
<SUMMARYALLOCS.LIST/>
<STPYMTDETAILS.LIST/>
<EXCISEPAYMENTALLOCATIONS.LIST/>
<TAXBILLALLOCATIONS.LIST/>
<TAXOBJECTALLOCATIONS.LIST/>
<TDSEXPENSEALLOCATIONS.LIST/>
<VATSTATUTORYDETAILS.LIST/>
<COSTTRACKALLOCATIONS.LIST/>
<REFVOUCHERDETAILS.LIST/>
<INVOICEWISEDETAILS.LIST/>
<VATITCDETAILS.LIST/>
</ALLLEDGERENTRIES.LIST>
<ALLLEDGERENTRIES.LIST>
<OLDAUDITENTRYIDS.LIST TYPE="Number">
<OLDAUDITENTRYIDS>-1</OLDAUDITENTRYIDS>
</OLDAUDITENTRYIDS.LIST>
<LEDGERNAME>Cash</LEDGERNAME>
<GSTCLASS/>
<ISDEEMEDPOSITIVE>No</ISDEEMEDPOSITIVE>
<LEDGERFROMITEM>No</LEDGERFROMITEM>
<REMOVEZEROENTRIES>No</REMOVEZEROENTRIES>
<ISPARTYLEDGER>Yes</ISPARTYLEDGER>
<ISLASTDEEMEDPOSITIVE>No</ISLASTDEEMEDPOSITIVE>
<AMOUNT>100.00</AMOUNT>
<SERVICETAXDETAILS.LIST/>
<BANKALLOCATIONS.LIST>
<DATE>20170331</DATE>
<INSTRUMENTDATE>20170331</INSTRUMENTDATE>
<NAME>d29faa3c-2cb8-429e-9d50-cb4243b68a8d</NAME>
<TRANSACTIONTYPE>Cheque</TRANSACTIONTYPE>
<PAYMENTFAVOURING>Water Exp</PAYMENTFAVOURING>
<CHEQUECROSSCOMMENT>A/c Payee</CHEQUECROSSCOMMENT>
<UNIQUEREFERENCENUMBER>3CODSsNV01ippV7T</UNIQUEREFERENCENUMBER>
<STATUS>No</STATUS>
<PAYMENTMODE>Transacted</PAYMENTMODE>
<BANKPARTYNAME>Water Exp</BANKPARTYNAME>
<ISCONNECTEDPAYMENT>No</ISCONNECTEDPAYMENT>
<ISSPLIT>No</ISSPLIT>
<ISCONTRACTUSED>No</ISCONTRACTUSED>
<AMOUNT>1000.00</AMOUNT>
<CONTRACTDETAILS.LIST/>
</BANKALLOCATIONS.LIST>
<BILLALLOCATIONS.LIST/>
<INTERESTCOLLECTION.LIST/>
<OLDAUDITENTRIES.LIST/>
<ACCOUNTAUDITENTRIES.LIST/>
<AUDITENTRIES.LIST/>
<INPUTCRALLOCS.LIST/>
<DUTYHEADDETAILS.LIST/>
<EXCISEDUTYHEADDETAILS.LIST/>
<SUMMARYALLOCS.LIST/>
<STPYMTDETAILS.LIST/>
<EXCISEPAYMENTALLOCATIONS.LIST/>
<TAXBILLALLOCATIONS.LIST/>
<TAXOBJECTALLOCATIONS.LIST/>
<TDSEXPENSEALLOCATIONS.LIST/>
<VATSTATUTORYDETAILS.LIST/>
<COSTTRACKALLOCATIONS.LIST/>
<REFVOUCHERDETAILS.LIST/>
<INVOICEWISEDETAILS.LIST/>
<VATITCDETAILS.LIST/>
</ALLLEDGERENTRIES.LIST>
<PAYROLLMODEOFPAYMENT.LIST></PAYROLLMODEOFPAYMENT.LIST>
<ATTDRECORDS.LIST></ATTDRECORDS.LIST>
</VOUCHER>
</TALLYMESSAGE>
</REQUESTDATA>
</IMPORTDATA>
</BODY>
</ENVELOPE>
Is there any error in my xml file,
please help me. there is no enough document in online.

#shimbu shambu, I also faced the same problem and resolved it by changing the date value in DATE tag. This issue occured due to the variation in the date that of passing in the xml and the current date in tally.If you are using the educational version of tally then you can't change the date in the tally. You have to change it in the xml file.

Try passing invalid XML data like this: <![CDATA[ {INVALID XML}]]>

I saw this post when I was trying to the same task which you are doing, wish to share somethings what I did for solving this may be it will help you to proceed further..
java code is as bellow
TallyRequest.java
package tallyrequest;
import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLConnection;
public class TallyRequest {
public String CreateRequest() {
String TXML = null;
TXML = "<ENVELOPE>"
+ "<HEADER><TALLYREQUEST>Import Data</TALLYREQUEST></HEADER>"
+ "<BODY>"
+ "<IMPORTDATA>"
+ "<REQUESTDESC><REPORTNAME>Vouchers</REPORTNAME><STATICVARIABLES><SVCURRENTCOMPANY>Crane</SVCURRENTCOMPANY></STATICVARIABLES></REQUESTDESC>"
+ "<REQUESTDATA>"
+ "<TALLYMESSAGE xmlns:UDF=\"TallyUDF\">"
+ "<VOUCHER REMOTEID=\"00000001\" VCHTYPE=\"Receipt\" ACTION=\"Create\" OBJVIEW=\"Accounting Voucher View\">"
+ "<DATE>20160701</DATE>"
+ "<VOUCHERTYPENAME>Receipt</VOUCHERTYPENAME>"
+ "<VOUCHERNUMBER>3</VOUCHERNUMBER>"
+ "<PARTYLEDGERNAME>Cash</PARTYLEDGERNAME>"
+ "<PERSISTEDVIEW>Accounting Voucher View</PERSISTEDVIEW>"
+ "<ALLLEDGERENTRIES.LIST>"
+ "<LEDGERNAME>Mahes</LEDGERNAME>"
+ "<ISDEEMEDPOSITIVE>No</ISDEEMEDPOSITIVE>"
+ "<AMOUNT>0</AMOUNT>"
+ "</ALLLEDGERENTRIES.LIST>"
+ "<ALLLEDGERENTRIES.LIST>"
+ "<LEDGERNAME>Cash</LEDGERNAME>"
+ "<ISDEEMEDPOSITIVE>Yes</ISDEEMEDPOSITIVE>"
+ "<AMOUNT>-150000.00</AMOUNT>"
+ "</ALLLEDGERENTRIES.LIST>"
+ "</VOUCHER>"
+ "</TALLYMESSAGE>"
+ "</REQUESTDATA>"
+ "</IMPORTDATA>"
+ "</BODY>"
+ "</ENVELOPE>";
return TXML;
}
public void SendToTally() throws Exception {
String Url = "http://127.0.0.1:9000/";
String SOAPAction = "";
String Voucher = this.CreateRequest();
// Create the connection where we're going to send the file.
URL url = new URL(Url);
URLConnection connection = url.openConnection();
HttpURLConnection httpConn = (HttpURLConnection) connection;
ByteArrayInputStream bin = new ByteArrayInputStream(Voucher.getBytes());
ByteArrayOutputStream bout = new ByteArrayOutputStream();
// Copy the SOAP file to the open connection.
copy(bin, bout);
byte[] b = bout.toByteArray();
// Set the appropriate HTTP parameters.
httpConn.setRequestProperty("Content-Length", String.valueOf(b.length));
httpConn.setRequestProperty("Content-Type", "text/xml; charset=utf-8");
httpConn.setRequestProperty("SOAPAction", SOAPAction);
httpConn.setRequestMethod("POST");
httpConn.setDoOutput(true);
httpConn.setDoInput(true);
// Everything's set up; send the XML that was read in to b.
OutputStream out = httpConn.getOutputStream();
out.write(b);
out.close();
// Read the response and write it to standard out.
InputStreamReader isr = new InputStreamReader(httpConn.getInputStream());
BufferedReader in = new BufferedReader(isr);
String inputLine;
while ((inputLine = in.readLine()) != null) {
System.out.println(inputLine);
}
in.close();
}
public static void copy(InputStream in, OutputStream out)
throws IOException {
// do not allow other threads to read from the
// input or write to the output while copying is
// taking place
synchronized (in) {
synchronized (out) {
byte[] buffer = new byte[256];
while (true) {
int bytesRead = in.read(buffer);
if (bytesRead == -1) {
break;
}
out.write(buffer, 0, bytesRead);
}
}
}
}
public static void main(String[] args) throws Exception {
TallyRequest r = new TallyRequest();
r.SendToTally();
}
}
here this send the xml output as bellow
XML Message as below
<ENVELOPE>
<HEADER>
<TALLYREQUEST>Import Data</TALLYREQUEST>
</HEADER>
<BODY>
<IMPORTDATA>
<REQUESTDESC>
<REPORTNAME>Vouchers</REPORTNAME>
<STATICVARIABLES>
<SVCURRENTCOMPANY>Crane</SVCURRENTCOMPANY>
</STATICVARIABLES>
</REQUESTDESC>
<REQUESTDATA>
<TALLYMESSAGE xmlns:UDF="TallyUDF">
<VOUCHER REMOTEID="00000001" VCHTYPE="Receipt" ACTION="Create" OBJVIEW="Accounting Voucher View">
<DATE>20160701</DATE>
<VOUCHERTYPENAME>Receipt</VOUCHERTYPENAME>
<VOUCHERNUMBER>3</VOUCHERNUMBER>
<PARTYLEDGERNAME>Cash</PARTYLEDGERNAME>
<PERSISTEDVIEW>Accounting Voucher View</PERSISTEDVIEW>
<ALLLEDGERENTRIES.LIST>
<LEDGERNAME>Mahes</LEDGERNAME>
<ISDEEMEDPOSITIVE>No</ISDEEMEDPOSITIVE>
<AMOUNT>0</AMOUNT>
</ALLLEDGERENTRIES.LIST>
<ALLLEDGERENTRIES.LIST>
<LEDGERNAME>Cash</LEDGERNAME>
<ISDEEMEDPOSITIVE>Yes</ISDEEMEDPOSITIVE>
<AMOUNT>-150000.00</AMOUNT>
</ALLLEDGERENTRIES.LIST>
</VOUCHER>
</TALLYMESSAGE>
</REQUESTDATA>
</IMPORTDATA>
</BODY>
</ENVELOPE>
the above code will indicate the ledger and the bill passed from java to tally for the company name, when XML message is be passed to tally make sure that tally is having the same arguments which is passed or modify where ever necessary otherwise message will not pass and you will get a error which can be seen in java Console as well as in tally.imp file on Tally.ERP9 root folder. For doubt regarding the tally XML message structure from your tally just fetch the backup of the Ledger or any other which ever you need to send data to get the format.. or refer the links which was useful for me to send a correct format of XML.
Full reference to Tally and Java integration based on SOAP
Architecture Reference
For further quires pleased do comment elaborating your needs so that I will try to help you!

Remove the remote ID in the voucher TAG and the ID in the GUID tag. Keep the tags, though and see if the voucher is created in the response.

You are probably using the educational version of Tally.
Tally hasn't handled the XML error response for Date not being accessible in Tally - this happens only in the educational version where only the 1st, 2nd and end of month are available to work on.
Try changing the date to 20160401 (you could also play around with the date format-year first, month first or day first).

the one and the only reason for this error is the coding data.
Just remove or delete the data from inverted comma in this 2 lines -
<VOUCHER REMOTEID="face3a8f-f920-4781-a14b-ed095d0b0145-00000006"
VCHKEY="face3a8f-f920-4781-a14b-ed095d0b0145-0000a748:000000061"
and in this line too
<GUID>face3a8f-f920-4781-a14b-ed095d0b0145-00000006</GUID>
remove only
" face3a8f-f920-4781-a14b-ed095d0b0145-00000006 "
and problem solved. :D

Related

How can I access the text of the SMS sent thru Twilio to my Spring Boot Controller?

I'm trying to use Twilio to receive SMS messages, and use the body of the SMS to perform various DB functions. The part where I'm stuck is parsing the message that I get from Twilio when they receive a text message.
Here's the controller:
#RequestMapping(
value = "/incomingSMS",
method = RequestMethod.POST)
public void getPhrase(#RequestBody String request) {
System.out.println("***********************************");
System.out.println(request);
System.out.println("***********************************");
}
And here's what is getting printed out (with new lines added for readability, and some numbers censored.):
ToCountry=US&
ToState=statecode&
SmsMessageSid=smsMessageSid&
NumMedia=0&
ToCity=city&
FromZip=zipCode&
SmsSid=SmsSid&
FromState=statecode&
SmsStatus=received&
FromCity=city&
Body=Hello+it%27s+John+&
FromCountry=US&
To=%2B1toPhoneNumber&
ToZip=55401&
NumSegments=1&
MessageSid=messageSid&
AccountSid=accountSid&
From=%2B1fromPhoneNumber&
ApiVersion=2010-04-01
I can see in "Body" my message is hiding. I also see the phone number. Is there any way I can just parse this into a Twilio object that I don't know about, so I can use methods like getBody(), getFrom()?
You can easily manipulate it by using the good old java.util.Properties class.
For the example bellow, I'm using the Apache Common IO lib to transform the String into an InputStream witch is required by Properties class. After that, all you have to do is use getProperty method to get what you need.
package com.pipocandobits.maven;
import org.apache.commons.io.IOUtils;
import java.io.IOException;
import java.util.Properties;
public class App {
public static void main( String[] args ) throws IOException {
System.out.println( "Hello World!" );
String source = "ToCountry=US&\n" +
"ToState=statecode&\n" +
"SmsMessageSid=smsMessageSid&\n" +
"NumMedia=0&\n" +
"ToCity=city&\n" +
"FromZip=zipCode&\n" +
"SmsSid=SmsSid&\n" +
"FromState=statecode&\n" +
"SmsStatus=received&\n" +
"FromCity=city&\n" +
"Body=Hello+it%27s+John+&\n" +
"FromCountry=US&\n" +
"To=%2B1toPhoneNumber&\n" +
"ToZip=55401&\n" +
"NumSegments=1&\n" +
"MessageSid=messageSid&\n" +
"AccountSid=accountSid&\n" +
"From=%2B1fromPhoneNumber&\n" +
"ApiVersion=2010-04-01";
Properties properties = new Properties();
properties.load(IOUtils.toInputStream(source, "UTF-8"));
System.out.println("Message body = " + properties.getProperty("Body"));
}
}
For more on how to use the java.util.Properties class check this link https://www.tutorialspoint.com/java/java_properties_class.htm

Attaching xml file to mimeentity crashes Notes server

In an Java agent I generate a mail. When I send this only with text then the mail is sent to the recipient. I also want to attach an xml file to the mail. If I attach it my notes server crashes.
I think my code is wrong, this is the part where I want to add the attachment to the mail:
mime = mimeRoot.createChildEntity();
MIMEHeader hdr = mime.createHeader("Content-Disposition");
hdr.setHeaderValAndParams("attachment; filename=" + OrderFilePath);
Stream stream = session.createStream();
System.out.println("Open stream");
//AT THIS IF IT WILL CRASH THE SERVER
if (stream.open(OrderFilePath, "binary")){
System.out.println("in eerste if");
if (stream.getBytes() != 0) {
System.out.println("getbytes !0 ");
mime.setContentFromBytes(stream, "application/octet-stream",MIMEEntity.ENC_IDENTITY_BINARY);
}
else System.out.println
(OrderFilePath + "has no content or is not working");
}
I have some working LotusScript code that does almost the same, with the exception of two lines:
hdr.setHeaderValAndParams("attachment; filename=\\"" + OrderFilePath + "\\"");
and
mime.setContentFromBytes(stream, "application/octet-stream; name=\\"" + OrderFilePath + "\\"",MIMEEntity.ENC_IDENTITY_BINARY);
My LS code, so yo can see for yourself:
ForAll att In attachments
disposition= "attachment"
If att.isInLine Then disposition= "inline"
Set sect = body.createChildEntity()
Call sect.CreateHeader("Content-Disposition").SetHeaderValAndParams(disposition + {; filename="} & att.attName & {";"} )
Call sect.CreateHeader("Content-ID").SetHeaderVal( |<| & ListTag(att) & |>| )
Set stream = session.CreateStream
If stream.Open(att.attFile) Then
Call sect.SetContentFromBytes(stream, strContentType & {; name="} & att.attName & {"}, ENC_IDENTITY_BINARY)
Call stream.Close
End If
End Forall
attachments is a list of Attachment objects that contain only the name and the filepath of an attachment; it isn't a full Notes attachment embedded object thing.

Download csv file from link with java

I'm creating a csv file with data saved to it. The next thing i wanna do is that any person can download that file from a link in a HTML page.
The problem is I've never worked before with Java and I've searched for some good options but non of them seems to work. I hope any one can help me with this.
This is how is save to my CSV file
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
public class Logbook {
public Logbook() {
super();
}
/**
* #param date
* #param memoryMax
* #param memoryCommitted
* #param memoryUsed
* #param JvmUpTimeH
* #param JvmUpTimeD
* #param JvmUpTimeM
* #param JvmUpTimeS
*/
public void writeLog(String date, Long memoryMax, Long memoryCommitted, Long memoryUsed, String TotalTime) {
File Logbook = new File("C:/Logbook/Logbook.csv");
try (PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(Logbook, true)))) {
out.println(date + " , " + memoryMax + " b" + " , " + memoryCommitted + " b" + " , " + memoryUsed + " b" + " , " + TotalTime);
} catch (IOException e) {
// exception handling left as an exercise for the reader
}
}
}
After this I have a new page were it refreshes the page every sec my code to write it in the file is here
Long memoryUsed=agent.readMemoryUsed();
Long memoryCommitted=agent.readMemoryCommitted();
Long memoryMax=agent.readMemoryMax();
Date today2 = new Date();
SimpleDateFormat savedLog = new SimpleDateFormat("dd/MM/YY kk:mm:ss");
String date = savedLog.format(today2);
Logbook logBook = new Logbook();
logBook.writeLog(date, memoryMax,memoryCommitted,memoryUsed, TotalTime);
All I want now is to download the file with that information into it for any person that wanna download it.
Probably the easiest way to address this is to write the file to a location under your web server's file directory. You can serve this file statically - you don't need it to go through a webapp to provide it.
You don't mention what web server you're using, or even if you're using an application server on top of it, so we really can't help you that much more. If your question is actually about how to setup a web server - that gets beyond the scope of StackOverflow.

Protocol message contained an invalid tag (zero)

I'm working with pbf files from the open street maps
I want to parse node, relations, and ways.
when I try to parse nodes I get that message.
The code looks like
package myCode;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.List;
import protpbufCode.OsmPbf;
import protpbufCode.OsmPbf.Node;
import protpbufCode.OsmPbf.PrimitiveGroup;
public class ReadingPBF
{
public static void print(PrimitiveGroup node)
{
for (Node m: node.getNodesList())
{
System.out.print("Person ID: " + m.getId() + " ");
System.out.print(" Lat: " + m.getLat()+ " ");
System.out.print(" Long: "+ m.getLon()+ " ");
System.out.println("");
}
}
public static void main (String args[])
{
try
{
PrimitiveGroup newNode = PrimitiveGroup.parseFrom(new FileInputStream(new File("isle.pbf")));
print(newNode);
}
catch (IOException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
System.out.println(e.getMessage());
System.out.println(e.getCause());
}
}
}
the OsmPbf is java class that created using the protobuf compiler.
and that what gets printed.
com.google.protobuf.InvalidProtocolBufferException: Protocol message contained an invalid tag (zero).
at com.google.protobuf.InvalidProtocolBufferException.invalidTag(InvalidProtocolBufferException.java:89)
at com.google.protobuf.CodedInputStream.readTag(CodedInputStream.java:158)
at protpbufCode.OsmPbf$PrimitiveGroup.<init>(OsmPbf.java:5230)
at protpbufCode.OsmPbf$PrimitiveGroup.<init>(OsmPbf.java:5219)
at protpbufCode.OsmPbf$PrimitiveGroup$1.parsePartialFrom(OsmPbf.java:5329)
at protpbufCode.OsmPbf$PrimitiveGroup$1.parsePartialFrom(OsmPbf.java:1)
at com.google.protobuf.AbstractParser.parsePartialFrom(AbstractParser.java:192)
at com.google.protobuf.AbstractParser.parseFrom(AbstractParser.java:209)
at com.google.protobuf.AbstractParser.parseFrom(AbstractParser.java:215)
at com.google.protobuf.AbstractParser.parseFrom(AbstractParser.java:49)
at protpbufCode.OsmPbf$PrimitiveGroup.parseFrom(OsmPbf.java:5627)
at myCode.ReadingPBF.main(ReadingPBF.java:33)
Protocol message contained an invalid tag (zero).
null
OpenStreetMap .pbf files are not simple protobufs. See the documentation here:
http://wiki.openstreetmap.org/wiki/PBF_Format
Under the section "File format", you'll see this:
The format is a repeating sequence of:
int4: length of the BlobHeader message in network byte order
serialized BlobHeader message
serialized Blob message (size is given in the header)
That is, the file starts out with a 4-byte integer before the first protobuf message. Since this integer is probably smaller than 2^24, the first byte will of course be zero, which explains the exact exception you are seeing.
You will need to read this 4-byte value manually, then make sure to read only that many bytes and parse them as a BlobHeader, and so on.
Personally I'd recommend looking for a PBF decoder library that already handles this for you. There must be a few out there.

Creating a UTF-8 File in Java

I'm currently making a program that saves Chinese Words onto a text file. I create the text file in java, and then try and write words to it. However, the text file I create is never encoded in UTF-8. This is the code I'm using, why doesn't it work? I was told that there was a bug inherent in Java but I have no idea how to get around it.
public void createFile(String name) {
try {
BufferedWriter out = new BufferedWriter(new OutputStreamWriter(
new FileOutputStream(name +".txt"), "UTF-8"));
out.write("");
}
catch(java.io.IOException e) {
System.err.println("Something went wrong.");
}
}
Also, do I have another option aside from text files with which I could still use UTF encoding?
Also I'm testing its encoding by opening the TextEdit application and trying to write Chinese characters. Could this also be a problem?
First, files themselves don't have encodings. They're a bunch of 0s and 1s. If you write "asdf" in utf-8, it's completely indistinguishable from plain old ascii7.
If you were writing in, say, utf-16, then the byte-order mark (BOM) would be a pretty clear indication that it's written in utf-16, even with an empty string, but utf-8 does not require such a marker to be present.
Therefore, your editor has no way of knowing that this file is supposed to be written in utf-8. You could write utf-8's BOM to your file by:
out.write(0xEFBBBF);
However, in this case, outwould have to be an OutputStream, such as the FileOutputStream. (BufferedWriter and OutputStreamWriter do not accept byte arrays for input.)
This may be a TextEdit usage issue.
If there are no non-ASCII characters in the file you're writing, TextEdit's algorithm to determine encoding will likely land on ASCII or a Latin-1 variant.
You can specify a text file's encoding in the File->Open dialog. I'm not sure whether TextEdit remembers this decision on future double-clicks of this file.
Try the following code. It worked for me. The file was written out as UTF-8. I was able to open it with Notepad++, which verified that the encoding was UTF-8. The characters encoded correctly. I got the characters from http://www.khngai.com/chinese/charmap/tbluni.php.
package testutf8;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.UnsupportedEncodingException;
import java.io.Writer;
public class TestUTF8 {
public static void main(String[] args) throws FileNotFoundException, UnsupportedEncodingException, IOException {
String str = "Unicode Character Map, 0x4E00 - 0x4FFF\n" +
"4E00 一 丁 丂 七 丄 丅 丆 万 丈 三 上 下 丌 不 与 丏\n" +
"4E10 丐 丑 丒 专 且 丕 世 丗 丘 丙 业 丛 东 丝 丞 丟\n" +
"4E20 丠 両 丢 丣 两 严 並 丧 丨 丩 个 丫 丬 中 丮 丯\n" +
"4E30 丰 丱 串 丳 临 丵 丶 丷 丸 丹 为 主 丼 丽 举 丿\n" +
"4E40 乀 乁 乂 乃 乄 久 乆 乇 么 义 乊 之 乌 乍 乎 乏\n" +
"4E50 乐 乑 乒 乓 乔 乕 乖 乗 乘 乙 乚 乛 乜 九 乞 也\n" +
"4E60 习 乡 乢 乣 乤 乥 书 乧 乨 乩 乪 乫 乬 乭 乮 乯\n" +
"4E70 买 乱 乲 乳 乴 乵 乶 乷 乸 乹 乺 乻 乼 乽 乾 乿\n" +
"4E80 亀 亁 亂 亃 亄 亅 了 亇 予 争 亊 事 二 亍 于 亏\n" +
"4E90 亐 云 互 亓 五 井 亖 亗 亘 亙 亚 些 亜 亝 亞 亟\n" +
"4EA0 亠 亡 亢 亣 交 亥 亦 产 亨 亩 亪 享 京 亭 亮 亯\n" +
"4EB0 亰 亱 亲 亳 亴 亵 亶 亷 亸 亹 人 亻 亼 亽 亾 亿\n" +
"4EC0 什 仁 仂 仃 仄 仅 仆 仇 仈 仉 今 介 仌 仍 从 仏\n" +
"4ED0 仐 仑 仒 仓 仔 仕 他 仗 付 仙 仚 仛 仜 仝 仞 仟\n" +
"4EE0 仠 仡 仢 代 令 以 仦 仧 仨 仩 仪 仫 们 仭 仮 仯\n" +
"4EF0 仰 仱 仲 仳 仴 仵 件 价 仸 仹 仺 任 仼 份 仾 仿\n" +
"4F00 伀 企 伂 伃 伄 伅 伆 伇 伈 伉 伊 伋 伌 伍 伎 伏\n" +
"4F10 伐 休 伒 伓 伔 伕 伖 众 优 伙 会 伛 伜 伝 伞 伟\n" +
"4F20 传 伡 伢 伣 伤 伥 伦 伧 伨 伩 伪 伫 伬 伭 伮 伯\n" +
"4F30 估 伱 伲 伳 伴 伵 伶 伷 伸 伹 伺 伻 似 伽 伾 伿\n" +
"4F40 佀 佁 佂 佃 佄 佅 但 佇 佈 佉 佊 佋 佌 位 低 住\n" +
"4F50 佐 佑 佒 体 佔 何 佖 佗 佘 余 佚 佛 作 佝 佞 佟\n" +
"4F60 你 佡 佢 佣 佤 佥 佦 佧 佨 佩 佪 佫 佬 佭 佮 佯\n" +
"4F70 佰 佱 佲 佳 佴 併 佶 佷 佸 佹 佺 佻 佼 佽 佾 使\n" +
"4F80 侀 侁 侂 侃 侄 侅 來 侇 侈 侉 侊 例 侌 侍 侎 侏\n" +
"4F90 侐 侑 侒 侓 侔 侕 侖 侗 侘 侙 侚 供 侜 依 侞 侟\n" +
"4FA0 侠 価 侢 侣 侤 侥 侦 侧 侨 侩 侪 侫 侬 侭 侮 侯\n" +
"4FB0 侰 侱 侲 侳 侴 侵 侶 侷 侸 侹 侺 侻 侼 侽 侾 便\n" +
"4FC0 俀 俁 係 促 俄 俅 俆 俇 俈 俉 俊 俋 俌 俍 俎 俏\n" +
"4FD0 俐 俑 俒 俓 俔 俕 俖 俗 俘 俙 俚 俛 俜 保 俞 俟\n" +
"4FE0 俠 信 俢 俣 俤 俥 俦 俧 俨 俩 俪 俫 俬 俭 修 俯\n" +
"4FF0 俰 俱 俲 俳 俴 俵 俶 俷 俸 俹 俺 俻 俼 俽 俾 俿\n";
FileOutputStream fos = new FileOutputStream("tmp.txt");
Writer out = new OutputStreamWriter(fos, "UTF-8");
out.write(str);
out.close();
}
}
Try UTF-8 instead of UTF8. This might solve your problem.
I noticed that you didn't close your stream:
out.close();
Of course you didn't include the code that wrote the actual characters either...

Categories