I am trying to get the data from inputstream. I am getting it with gdrive HttpResponse. Plz check it in code below.
HttpResponse resp = service.getRequestFactory().buildGetRequest(
new GenericUrl(file.getDownloadUrl())).execute();
BufferedReader output = new BufferedReader(
new InputStreamReader(resp.getContent()));
System.out.println("Shorten Response: ");
for (String line = output.readLine(); line != null; line = output.readLine()) {
System.out.println(line);
}
I am reading .doc file and i am getting the output like a decoded form:-
��ࡱ� � & ]� � �
How to read it as string? plz help me to resolve this.
Related
We are trying to correct the spelling of words in a TextArea
We have tried two methods onRemoveTwo failed with an IndexOutOfBoundsException
The other method onRemove works but it does a replaceAll we use replace in our code
Here are the results from both methods
Results from using onRemoveTwo
Initial text Take = Cariage NOT ME Carriag add missing voel to Carriage
Request was to correct "Cariage"
First correction results Take = Carriage NOT ME Carriag add missing voel to Carriage
With sb = sb.replace(from, to);
Request was to correct "Carriag"
Second correction results Take = Carriagee NOT MEg add missing voel to Carriage
We have this error Caused by: java.lang.IndexOutOfBoundsException
Caused by this line of code which we understand
while is finding two occurrence of the word
txaInput.replaceText(match.start(),match.end(),txtReplacementWord.getText());
Results from using onRemove
Initial text Take = Cariage NOT ME Carriag add missing voel to Carriage
Request was to correct "Cariage"
First correction results Take = Carriage NOT ME Carriag add missing voel to Carriage
Request was to correct "Carriag"
Second correction results Take = Carriagee NOT ME Carriage add missing voel to Carriagee
Notice both "Carriage" were changed to "Carriagee"
So our question is how to be more specific about the word to be corrected?
private void onRemoveTwo(){
if(txtReplacementWord.getText().isEmpty()){
txtMessage.setText("No Replacement Word");
return;
}
cboMisspelledWord.getItems().remove(txtWordToReplace.getText());
// Line Above Removes misspelled word from cboSelect
// ==================================================
String text = txaInput.getText();
String wordToFind = txtWordToReplace.getText();
Pattern word = Pattern.compile(wordToFind);
Matcher match = word.matcher(text);
while(match.find()){
///System.out.println("Found "+word+" "+ match.start() +" - "+ (match.end()-1));
String from = word.toString();
String to = txtReplacementWord.getText();
String sb = txaInput.getText();
sb = sb.replace(from, to);
txaInput.replaceText(match.start(),match.end(),txtReplacementWord.getText());
txtMessage.setText("");
txtReplacementWord.setText("");
txtWordToReplace.setText("");
cboCorrectSpelling.getItems().clear();
cboMisspelledWord.requestFocus();
// Code above replaces misspelled word with correct spelling in TextArea
// =====================================================================
int SIZE = cboMisspelledWord.getItems().size();
if(SIZE == 0){
onCheckSpelling();
}
}
}
Workable method but changes multiple words
#FXML
private void onReplace(){
if(txtReplacementWord.getText().isEmpty()){
txtMessage.setText("No Replacement Word");
return;
}
cboMisspelledWord.getItems().remove(txtWordToReplace.getText());
// Line Above Removes misspelled word from cboSelect
// ==================================================
String from = txtWordToReplace.getText();
String to = txtReplacementWord.getText();
String sb = txaInput.getText();
sb = sb.replace(from, to);
//sb = sb.replaceAll(from,to);
txaInput.setText("");
txaInput.setText(sb);
txtMessage.setText("");
txtReplacementWord.setText("");
txtWordToReplace.setText("");
cboCorrectSpelling.getItems().clear();
cboMisspelledWord.requestFocus();
// Code above replaces misspelled word with correct spelling in TextArea
// =====================================================================
int SIZE = cboMisspelledWord.getItems().size();
if(SIZE == 0){
onCheckSpelling();
}
}
Well #Grendel I have no idea why this question is voted down. I have been working on a similar project with a TextArea and liked your code and like you found it frustrating that the StringBuilder finds any occurrence of the characters. So here is an answer the code is not real neat you will need to clean it up. I was unhappy that I had to go to a String[] array then to a ArrayList will keep working on this issue
In spite of the down votes enjoy the code
Send the check to 90.83.140.38
#FXML
private void onReplace(){
if(txtReplacementWord.getText().isEmpty()){
txtMessage.setText("No Replacement Word");
return;
}
cboMisspelledWord.getItems().remove(txtWordToReplace.getText());
// Line Above Removes misspelled word from cboMisspelledWord
// ==========================================================
String line = txaInput.getText();
oneA = line.split("\\s");
List<String> list = new ArrayList<>(Arrays.asList(oneA));
int theIndex = list.indexOf(txtWordToReplace.getText());
String gotME = list.get(theIndex);
list.remove(theIndex);
list.add(theIndex,txtReplacementWord.getText());
sb = new StringBuilder();
for (String addWord : list) {
sb.append(addWord);
sb.append(" ");
}
txaInput.setText(sb.toString());
txtMessage.setText("");
txtReplacementWord.setText("");
txtWordToReplace.setText("");
cboCorrectSpelling.getItems().clear();
cboMisspelledWord.requestFocus();
// Code above replaces misspelled word with correct spelling in TextArea
// =====================================================================
if(cboMisspelledWord.getItems().isEmpty()){
onCheckSpelling();
}
}
I've written some codes to send fax using faxcomlib. it work fine when running code in my windows application but i want to use my sending fax code in a windows service,the problem is go here when i try to send fax by using windows service, my problem is that when i sending text files,or pdf or word document it work fine,but when sending any image format like .jpg,.tiff,... i face to operation failed error and my service get hanged,i try this ways but unfortunately i didn't get any right anwser :
1- i get all permissions to my service and related folders
2- i try to convert images to the same format and size that fax printer use it ( CCITT T6 - 1740*2400)
3- i try to convert my images to pdf files and then send it but i cann't, despite already i did send pdf files without any errors.
and here is my codes for sendig fax :
if (ImageExtensions.Contains(System.IO.Path.GetExtension(tempFileName).ToUpperInvariant().Trim()))
{
string newFileName = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) + #"\Temp\" + System.IO.Path.GetFileNameWithoutExtension(currentAttachment) + ".tif";
Toranj.Base.Graphic.Imaging.SaveTiff(tempFileName, newFileName);
Bitmap tempImage = new Bitmap(tempFileName);
System.Drawing.Image newImage = Toranj.Base.Graphic.Imaging.Resize(tempImage, 1728, 2200, RotateFlipType.RotateNoneFlipXY, 204, 196);
tempImage.Dispose();
System.IO.File.Delete(tempFileName);
newImage.Save(tempFileName);
newImage.Dispose();
Toranj.Base.Graphic.Imaging.SaveTiff(tempFileName, newFileName);
//PdfDocument doc = new PdfDocument();
//doc.Pages.Add(new PdfPage());
//XGraphics xgr = XGraphics.FromPdfPage(doc.Pages[0]);
//XImage img = XImage.FromFile(tempFileName);
//xgr.DrawImage(img, 0, 0);
//doc.Save(newFileName);
//doc.Close();
fileList.Add(newFileName);
System.IO.File.Delete(tempFileName);
}
else
fileList.Add(tempFileName);
}
FAXCOMEXLib.FaxDocument currentDocument = new FAXCOMEXLib.FaxDocument();
string[] attachList = fileList.ToArray();
currentDocument.Bodies = attachList;
ShamsiDate curretnDate = new ShamsiDate(DateTime.Now);
currentDocument.DocumentName = "fax:" + curretnDate.PerSimpleDate();
currentDocument.Priority = FAXCOMEXLib.FAX_PRIORITY_TYPE_ENUM.fptHIGH;
currentDocument.Recipients.Add(currentRow["faxNumber"].ToString(), currentRow["RecipientName"].ToString());
currentDocument.AttachFaxToReceipt = true;
currentDocument.Sender.Title = "xxxxx";
currentDocument.Sender.Name = "";
currentDocument.Sender.City = "xxxxx";
currentDocument.Sender.Company = "xxxxx";
currentDocument.Sender.Country = "xxxxx";
currentDocument.Sender.Email = "xxxxx";
currentDocument.Sender.FaxNumber = "";
currentDocument.Sender.HomePhone = "";
currentDocument.Sender.TSID = "";
currentDocument.Sender.SaveDefaultSender();
object jobsId = new object();
currentDocument.ConnectedSubmit2(sendServer, out jobsId);
string[] jobID = (string[])jobsId;
can anyone help me?
in above code, if my files was image format files, i'll first change size,and save them az tiff format and convert it to the pdf format file to sending by fax but there is no change!!!
using (WebClient client = new WebClient())
{
result = client.DownloadString(TextBox1.Text );
}
literal.text=result;
how can Unicode the result;
utf-8
2.
If www.google.com in the address bar to enter the page. loading speed is equal when the code is written(result)
how can faster this way.(result)
3.
literal.text=result
sqy error:Microsoft JScript runtime error: 'document.f.q' is null or not an object
result="....."
i think this error for <html></htm> and <body></body>
byte[] byteA = new byte[99999];
using (WebClient client = new WebClient())
{
byteA = client.DownloadData(TextBox1.Text );
}
DownloadData resolve utf-8
This will convert the result to UTF-8:
System.Text.Encoding.UTF8.GetBytes(result)
i have written the code of jsp,servlet for uploading the Doc file in database.
here is my code,but i am getting the error like this==java.io.FileNotFoundException: insert into resume(resume) values(?) (The filename, directory name, or volume label syntax is incorrect) .please help me how to remove this error???
try
{
Class.forName("net.sourceforge.jtds.jdbc.Driver").newInstance();
con=DriverManager.getConnection("jdbc:jtds:sqlserver://W2K8SERVER:1433/career","sa","Alpha#123" );
pst = con.prepareStatement("select * from data1 where email=? and password=?");
pst = con.prepareStatement
("insert into resume(resume) "+ "values(?)");
File re = new File("" + pst);
fis = new FileInputStream(re);
pst.setBinaryStream(3, (InputStream)fis, (int)(re.length()));
pst.setString (1,upload);
//rs = pst.executeQuery();
while (rs.next())
cnt ++;
int s = pst.executeUpdate();
if(s>0) {
System.out.println("Uploaded successfully !");
}
else {
System.out.println("unsucessfull to upload image.");
}
rs.close();
pst.close();
con.close();
}
It is because insert into resume(resume) values(?) is probably not the name of a file on your disk.
pst = con.prepareStatement ("insert into resume(resume) "+ "values(?)");
File re = new File("" + pst);
You are creating a File from ""+ pst, which is the result of toString() being called on a PreparedStatement. Did you put in the "" to get rid of the informative compilation error?
You probably have the real filename in some other variable.
File re = new File(theRealFileNameVariable);
File re = new File("" + pst);
please make sure the "pst" value is a valid file path, apparently the value "insert into resume(resume) values(?)" is not a valid file path
The java.io.File class has four (4) constructors
File(File parent, String child)
File(String pathname)
File(String parent, String child)
File(URI uri)
In your case you are trying to pass to the constructor an object or type java.sql.PreparedStatement that you trying to cast into a String. I don't see how (even if you arrived to convert pst into a string) pst will reference a path to a file. Please go back and read a little bit about java.io.
.
I am working on a Japanese File and I have no knowledge of the language. The file is encoded in S-JIS. Now, I am supposed to convert the contents into UTF-8 so that the content looks like Japanese. And here I am completely blank. I tried the following code that I found somewhere on Internet but no luck:
byte[] arrByte = Encoding.UTF8.GetBytes(arrActualData[x]);
string str = ASCIIEncoding.ASCII.GetString(arrByte);
Can anyone help me with this?
Thanks in advance
Kunal
In C#, the following code works for me.
I wanted to try this out so evidence of my results below:
public void Convert()
{
using (TextReader input = new StreamReader(
new FileStream("shift-jis.txt", FileMode.Open),
Encoding.GetEncoding("shift-jis")))
{
using (TextWriter output = new StreamWriter(
new FileStream("utf8.txt", FileMode.Create), Encoding.UTF8))
{
var buffer = new char[512];
int len;
while ((len = input.Read(buffer, 0, 512)) > 0)
{
output.Write(buffer, 0, len);
}
}
}
}
Shown here is the file encoded in shift-jis (or SJIS/Shift_JIS they are the same), using JEdit to verify the encoding (the word in the file is the japanese text テスト meaning test):
After running the code & opening the file written to (utf8.txt) :
But it should be said that such a file conversion does not strictly require knowledge of any language.