Buffered Input stream that increases internal buffer dynamically
I need to parse an input stream until I find a <META> tag with character encoding. I then need to reset to the beginning of the input stream and start parsing the stream again with the correct character encoding.
BufferedInputStream provides mark() and reset() methods which can be used to accomplish this task. However, the input stream data can be 1MB size and the only way I can think of forcing the BufferedInputStream to hold that content size is by specifying the size during construction.
I don't want to initialize the content size during construction of the BufferedStream for every data file I parse because some documents could have the tag in the beginning of the file and it could be waste of memory.
Question: Is there already a class which allows to set the maximum buffer size and which grows gradually to that size rather than during construction.
Thanks for any help.
DrClap, I connect to a webserver and request a file. I just use the InputStream returned by the HttpResponse object to read the file. So, the answer to your question is I can't close and reopen the file.
Jawahar
Similar Messages
-
Buffered Input stream - data corruption
Hi
I'm using the following code to transfer data to a file
BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(
new StringBuffer(path).append(part.getFileName()).toString()));
BufferedInputStream in = new BufferedInputStream(part.getInputStream());
while (in.available() > 0) {
out.write(in.read());
out.close();
in.close();It write the image and text files properly
But all the application based data like zip files,.doc files are getting corrupted
How do I solve it? What is the problem with the code?
Help plsWhat a waste of buffers that code is.
We don't know how you might be corrupting the data
coming in because you haven't show us what that code
is like. All we see is part.getInputStream which is
hardly enough to make a diagnosis.OOps
private void writeAttachment(BodyPart part, String path) throws
MessagingException,
FileNotFoundException, IOException {
//Make new dir
new File(path).mkdirs();
if (this.EnsileCall)
this.log("Ensile writing <<" + part.getFileName() + ">> of size = " + part.getSize());
// Write to file
BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(
new StringBuffer(path).append(part.getFileName()).toString()));
BufferedInputStream in = new BufferedInputStream(part.getInputStream());
while (in.available() > 0) {
out.write(in.read());
out.close();
in.close();
part.getInputStream() Part corresponds to a message body part in a mail(The attachment)
I'm getting the mail attachment's input stream and writing it to a file. -
Input Stream available() vs read(buffer, int, int)
I hope this isn't too stupid a question. I was doing some debugging recently and found this. I have a PushbackInputStream. Iask what's available(). It says, "950". I say read(buffer, int1, int2) it says, "I read 155".
That seems odd to me. If there are X available why does it read less than X?
Thanks
STOK. Thanks for the reply. So are you saying that
available() can never be trusted? All it says is now many bytes might be read without blocking but it does not say that you can read that many bytes.
Is this a bug? No! Just a feature.
I
could understand if available() always returns less
than is truly there but not the other way around.I agree but that is not how it works.
>
Thoughts?Don't use it. -
Will increasing the buffer size make flash streaming video stop stalling?
I have surmised all this on my own so it could be just a fantasy, but:
I am often the victim of slow internet connections. This means that when I try and watch streaming video it constantly pauses. It's my understanding that increasing the buffer size of flash would help prevent this but I can't figure out how to do that.
ThanksYou can pause the video just long enough for the player to load enough content. Most Flash player show a loading bar if you hover the player. For short pieces you can load the entire content before starting the play.
-
Problem reading input stream of urlconnection within portal
Hi,
This may be a generic server issue rather than portal but since it's my portal app that's displaying the problem I'll post it here.
Part of my Portal attempts to POST to a remote server to retrieve some search results.
In environments A & B (both standalone instances) this works fine.
In environment C this works on the managed instances in the cluster but not the admin instance.
In environment D (again standalone) it fails, but if I add a managed instance it works from the managed instance.
The problem I'm seeing is that I get a stuck thread and the thread dump shows it is blocked attempting to read the resulting input from a urlconnection. (Using a buffered input stream).
I've copied the code to a standalone class that runs fine from the same server(s). I've pasted this code below, the contents of the test() method were copied directly from my webapp (urls changed here for clarity).
Does anyone know of any securitymanager issues that may cause this?
Or anything else for that matter?
Code sample:
package src.samples;
import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
public class POSTTest {
public static boolean test()
URL url = null;
try {
url = new URL
("http://hostx:80/myapp/search.html");
catch (MalformedURLException e)
e.printStackTrace();
return false;
URLConnection urlConn;
DataOutputStream printout;
BufferedReader input;
urlConn = null;
try {
urlConn = url.openConnection();
catch (IOException e)
e.printStackTrace();
return false;
// Let the run-time system (RTS) know that we want input.
urlConn.setDoInput (true);
// Let the RTS know that we want to do output.
urlConn.setDoOutput (true);
// No caching, we want the real thing.
urlConn.setUseCaches (false);
// Specify the content type.
urlConn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
// Send POST output (this is a POST because we write then read as per the JDK Javadoc)
printout = null;
String body = "";
try {
System.out.println("url=" + url.toString());
printout = new DataOutputStream (urlConn.getOutputStream ());
String content = "param1=A¶m2=B¶m3=C¶m4=D¶m5=E";
System.out.println("urlParams= " + content);
printout.writeBytes (content);
System.out.println("written parameters");
printout.flush ();
System.out.println("flushed parameters");
printout.close ();
System.out.println("closed parameter stream");
// <b>Get response data - this is where it blocks indefinitely</b>
input = new BufferedReader(new InputStreamReader(urlConn.getInputStream()));
System.out.println("got input");
String str;
while (null != ((str = input.readLine()))) {
body = body + str + "\n";
System.out.println("read input:");
System.out.println(body);
input.close ();
System.out.println("closed input stream");
catch (IOException e) {
System.out.println("IOException caught: read failed");
e.printStackTrace();
return false;
return true;
* @param args
public static void main(String[] args) {
System.out.println("Test result= " + test());In your recuperar() method, read the FTP input stream into a byte array. (You can do that by copying it to a ByteArrayOutputStream and then getting the byte array from that object.) Then, return a ByteArrayInputStream based on those bytes. After you call completePendingCommand(), of course.
That's one way.
PC² -
Is there any way to mark/reset (or something comparable) an input stream that does not support the actual mark/reset methods? I'm using a DataInputStream, which contains a FileInputStream, and I've gotten an IOException saying mark/reset is not supported. Is there any other way to do it?
I'm basically just reading bytes of binary data from a file, and I want to include a feature to reset and start reading again from the beginning. here's some of my code:
public static void readWithDelay() {
byte buf[] = new byte[100000];
byte skipbytes[] = new byte[2];
int length = 0, prevtime, time, lastprevtime=0, num=0, timecheck,skiplength=0;
long period, filesize=0, bytecount = 0;
double val = 0.0;
try {
begin = System.currentTimeMillis();
// open the .pgem file stream
try {
binfile = new DataInputStream(new FileInputStream(getFname()));
} catch (Exception e) {
JOptionPane.showMessageDialog(new JFrame(), "File not Found. Try Again.", "Open File error", JOptionPane.ERROR_MESSAGE);
try {
File file = new File(getFname());
filesize = file.length();
} catch (Exception e) {
e.printStackTrace();
try {
// open the socket to socket on localhost
Socket socket = new Socket(getText(), port); // 1222 is TagBrowsers port
socket.setTcpNoDelay(true); // Disable TCP Nagle algorithm
socketOutputStream = new DataOutputStream(socket.getOutputStream());
} catch (UnknownHostException u) {
JOptionPane.showMessageDialog(new JFrame(), "Host Not Found. Defaulting to localhost", "Socket error", JOptionPane.ERROR_MESSAGE);
Socket socket = new Socket("localhost", 1222); // 1222 is TagBrowsers port
socket.setTcpNoDelay(true); // Disable TCP Nagle algorithm
socketOutputStream = new DataOutputStream(socket.getOutputStream());
bos = new BufferedOutputStream(socketOutputStream, 10000);
// loop copying file to output buffer until endfile
rate=rate/10;
start();
begin = System.currentTimeMillis();
//binfile.mark(500000000); <<<<<Tried to mark it here>>>>
for (int i=0;i<24;i++) {
buf[i] = binfile.readByte();
bytecount++;
time = ((buf[6] & 0xff) << 24) | ((buf[7] & 0xff) << 16) | ((buf[8] & 0xff) << 8) | (buf[9] & 0xff);
length = ((buf[14] & 0xff) << 8) | (buf[15] & 0xff);
for (int i=24;i<24+length;i++) {
buf[i] = binfile.readByte();
bytecount++;
prevtime = time;
try { // While !end of file
while (true && !stopXfer) {
while (prevtime == time) {
while (pause)
Thread.sleep(15);
bos.write(buf,0,24 + length);
prevtime = time;
for (int i=0;i<24;i++) {
buf[i] = binfile.readByte();
bytecount++;
time = ((buf[6] & 0xff) << 24) | ((buf[7] & 0xff) << 16) | ((buf[8] & 0xff) << 8) | (buf[9] & 0xff);
length = ((buf[14] & 0xff) << 8) | (buf[15] & 0xff);
for (int i=24;i<24+length;i++) {
buf[i] = binfile.readByte();
bytecount++;
/* if (rewind) {
binfile.reset(); <<<<Reset here>>>>>
rewind = false;
while (fastforward) {
binfile.skip(14);
bytecount+=24;
skipbytes[0] = binfile.readByte();
skipbytes[1] = binfile.readByte();
skiplength = ((skipbytes[0] & 0xff) << 8) | (skipbytes[1] & 0xff);
binfile.skip(8+skiplength);
bytecount+=10+length;
val = (double)(bytecount)/(double)(filesize);
updateDelayProgress((int)(val*100));
//System.out.println(bytecount);
// if times are out of order, flush buffer right away
if (time < prevtime || time==lastprevtime) {
period = 0;
bos.flush();
timecheck = prevtime;
prevtime = time;
if (lastprevtime > prevtime)
prevtime = lastprevtime;
period = (long) (time - prevtime);
try {
bos.flush();
stop();
if (period < elapsedTime || period > 750)
period=elapsedTime;
val = (double)(bytecount)/(double)(filesize);
updateDelayProgress((int)(val*100));
Thread.sleep((int)(rate*(period - elapsedTime)));
reset();
start();
} catch(InterruptedException ie){
System.out.println("Problem with thread");
System.exit(1);
prevtime = time;
lastprevtime = time;
timecheck = time;
} catch (EOFException e) {
} catch (SocketException s) {
System.out.println("Transmission ended");
} catch (Exception e) {
e.printStackTrace();
// Close input stream and display dialog with total duration of the read and transfer
try {
minutes = (((System.currentTimeMillis() - begin)/1000) / 60);
seconds = (((System.currentTimeMillis() - begin)/1000) % 60);
binfile.close();
bos.close();
JOptionPane.showMessageDialog(new TBCGUI(), "Read completed in " + minutes + " minutes, " + seconds + " seconds");
getFrame().validate();
} catch (Exception e) {
System.err.println(e);
e.printStackTrace();
} catch (Exception e) {}
} -
Buffered input/output stream
How the buffereing is done in buffered input/output streams?
From the API doc I got to know that they use internal buffer to store bytes before they can be read or written. But i found that File input/output stream also have methods like read(byte[]) or write(byte[]). So what is extra in buffered input/ouput streams? Does the phrase "buffered" suggests that bytes can be read from an array or be written to an array? Am i thinking the right way?How the buffereing is done in buffered input/output
streams?
From the API doc I got to know that they use internal
buffer to store bytes before they can be read or
written. But i found that File input/output stream
also have methods like read(byte[]) or write(byte[]).Thouse are your buffer, not the streams'.
So what is extra in buffered input/ouput streams?
Does the phrase "buffered" suggests that bytes can be
read from an array or be written to an array? Am i
thinking the right way?No. It means that the stream either prefetches some data even if it's not requested yet, or that it withholds data that it's supposed to write until it's flushed or gets a larger chunk. -
Storing input stream in a buffer
Hi, what is the best way to read an input stream and save it into a buffer?
Thanks,
AndreaNot sure if any of the following are an improvement or not. But here are just a few thoughts. Why handle all the byte array allocation yourself? IMO, it would be easier to simply use a ByteArrayOutputStream at that point. The listeners can call toByteArray() and be passed an offset and length of what was read.
Now that I think about it, you could probably make it a bit more generic even than that. For example, here is a class I end up using all the time:
public final class Pipe
/** Buffer size to read in and output. */
private static final int DEFAULT_BUFFER_SIZE = 2048;
* Private constructor. Use public static facade methods instead.
private Pipe()
super();
* Pipes the specified binary data to the specified output stream.
* @param target Binary data to output
* @param out Stream to write
* @throws IOException
public static final void pipe(final byte[] target, final OutputStream out)
throws IOException
assert (target != null) : "Missing byte array";
assert (out != null) : "Missing output stream";
pipe(new ByteArrayInputStream(target), out, true);
* Reads from the specified input stream and returns all data as an in-memory.
* binary array. Note: Since streams may be of any arbitrary size, this
* method requires that you wrap your original stream in a {@link FiniteInputStream}.
* Please ensure that this method is only used to read in data under, say, 2mB.
* @param in Stream to read
* @return byte[] Binary data read
* @throws IOException
public static final byte[] pipe(final FiniteInputStream in)
throws IOException
ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
pipe(in, byteOut, true);
return byteOut.toByteArray();
* Reads from the specified input stream and outputs immediately to the specified.
* output stream. <br>
* <br>
* If you have any confusion about which <code>Pipe</code> method to use, choose
* this one. It has the lowest memory overhead and is the most efficient. Always
* choose this method when streaming large amounts of data or content.
* @param in Input stream to read
* @param out Output stream to write
* @param close Close both stream if true
* @return long Byte count piped
* @throws IOException
public static final long pipe(final InputStream in, final OutputStream out, final boolean close)
throws IOException
assert (in != null) : "Missing input stream";
assert (out != null) : "Missing output stream";
long bytesPiped = 0L;
byte[] buffer = new byte[DEFAULT_BUFFER_SIZE];
try
int bytesRead = in.read(buffer);
while (bytesRead >= 0)
if (bytesRead > 0)
out.write(buffer, 0, bytesRead);
bytesPiped = bytesPiped + bytesRead;
bytesRead = in.read(buffer);
out.flush();
return bytesPiped;
finally
if (close)
IoHelper.close(in);
IoHelper.close(out);
}You simply could add the listener feature (which I do think is useful and elegant). Note the FiniteInputStream and FiniteOutputStream are just sub-classes of FilterInputStream and FilterOutputStream that allow you to limit how many bytes are piped, if desired.
- Saish -
How to increase the length of internal table dynamically
How to increase the length of internal table dynamically depending on the number of fields fetched into the internal table ?
The requirement code :
types: begin of t_data,
form like zscr_data_hdr-form,
werks like zscr_data_hdr-werks,
matnr like zscr_data_hdr-matnr,
verid like zscr_data_hdr-verid,
lot like zscr_data_hdr-lot,
lot_qty like zscr_data_hdr-lot_qty,
udate like zscr_data_hdr-udate,
utime like zscr_data_hdr-utime,
zuser like zscr_data_hdr-zuser,
processed like zscr_data_hdr-processed,
defect like zscr_defect_data-defect,
vornr like zscr_route_data-vornr,
fld1 like zscr_defect_data-defect_val,
fld2 like zscr_defect_data-defect_val,
fld3 like zscr_defect_data-defect_val,
fld4 like zscr_defect_data-defect_val,
fld5 like zscr_defect_data-defect_val,
fld6 like zscr_defect_data-defect_val,
fld7 like zscr_defect_data-defect_val,
fld8 like zscr_defect_data-defect_val,
fld9 like zscr_defect_data-defect_val,
fld10 like zscr_defect_data-defect_val,
fld11 like zscr_defect_data-defect_val,
fld12 like zscr_defect_data-defect_val,
fld13 like zscr_defect_data-defect_val,
fld14 like zscr_defect_data-defect_val,
fld15 like zscr_defect_data-defect_val,
fld16 like zscr_defect_data-defect_val,
fld17 like zscr_defect_data-defect_val,
fld18 like zscr_defect_data-defect_val,
fld19 like zscr_defect_data-defect_val,
fld20 like zscr_defect_data-defect_val,
fld21 like zscr_defect_data-defect_val,
fld22 like zscr_defect_data-defect_val,
fld23 like zscr_defect_data-defect_val,
fld24 like zscr_defect_data-defect_val,
fld25 like zscr_defect_data-defect_val,
fld26 like zscr_defect_data-defect_val,
fld27 like zscr_defect_data-defect_val,
fld28 like zscr_defect_data-defect_val,
fld29 like zscr_defect_data-defect_val,
fld30 like zscr_defect_data-defect_val,
fld31 like zscr_defect_data-defect_val,
fld32 like zscr_defect_data-defect_val,
fld33 like zscr_defect_data-defect_val,
fld34 like zscr_defect_data-defect_val,
fld35 like zscr_defect_data-defect_val,
fld36 like zscr_defect_data-defect_val,
fld37 like zscr_defect_data-defect_val,
fld38 like zscr_defect_data-defect_val,
fld39 like zscr_defect_data-defect_val,
fld40 like zscr_defect_data-defect_val,
fld41 like zscr_defect_data-defect_val,
fld42 like zscr_defect_data-defect_val,
fld43 like zscr_defect_data-defect_val,
fld44 like zscr_defect_data-defect_val,
fld45 like zscr_defect_data-defect_val,
fld46 like zscr_defect_data-defect_val,
fld47 like zscr_defect_data-defect_val,
fld48 like zscr_defect_data-defect_val,
fld49 like zscr_defect_data-defect_val,
fld50 like zscr_defect_data-defect_val,
fld51 like zscr_defect_data-defect_val,
fld52 like zscr_defect_data-defect_val,
fld53 like zscr_defect_data-defect_val,
fld54 like zscr_defect_data-defect_val,
fld55 like zscr_defect_data-defect_val,
fld56 like zscr_defect_data-defect_val,
fld57 like zscr_defect_data-defect_val,
fld58 like zscr_defect_data-defect_val,
fld59 like zscr_defect_data-defect_val,
fld60 like zscr_defect_data-defect_val,
fld61 like zscr_defect_data-defect_val,
fld62 like zscr_defect_data-defect_val,
fld63 like zscr_defect_data-defect_val,
fld64 like zscr_defect_data-defect_val,
fld65 like zscr_defect_data-defect_val,
fld66 like zscr_defect_data-defect_val,
fld67 like zscr_defect_data-defect_val,
fld68 like zscr_defect_data-defect_val,
fld69 like zscr_defect_data-defect_val,
fld70 like zscr_defect_data-defect_val,
fld71 like zscr_defect_data-defect_val,
fld72 like zscr_defect_data-defect_val,
fld73 like zscr_defect_data-defect_val,
fld74 like zscr_defect_data-defect_val,
fld75 like zscr_defect_data-defect_val,
fld76 like zscr_defect_data-defect_val,
fld77 like zscr_defect_data-defect_val,
fld78 like zscr_defect_data-defect_val,
fld79 like zscr_defect_data-defect_val,
fld80 like zscr_defect_data-defect_val,
fld81 like zscr_defect_data-defect_val,
fld82 like zscr_defect_data-defect_val,
fld83 like zscr_defect_data-defect_val,
fld84 like zscr_defect_data-defect_val,
fld85 like zscr_defect_data-defect_val,
fld86 like zscr_defect_data-defect_val,
fld87 like zscr_defect_data-defect_val,
fld88 like zscr_defect_data-defect_val,
fld89 like zscr_defect_data-defect_val,
fld90 like zscr_defect_data-defect_val,
fld91 like zscr_defect_data-defect_val,
fld92 like zscr_defect_data-defect_val,
fld93 like zscr_defect_data-defect_val,
fld94 like zscr_defect_data-defect_val,
fld95 like zscr_defect_data-defect_val,
fld96 like zscr_defect_data-defect_val,
fld97 like zscr_defect_data-defect_val,
fld98 like zscr_defect_data-defect_val,
fld99 like zscr_defect_data-defect_val,
fld100 like zscr_defect_data-defect_val,
fld101 like zscr_defect_data-defect_val,
fld102 like zscr_defect_data-defect_val,
fld103 like zscr_defect_data-defect_val,
fld104 like zscr_defect_data-defect_val,
fld105 like zscr_defect_data-defect_val,
fld106 like zscr_defect_data-defect_val,
fld107 like zscr_defect_data-defect_val,
fld108 like zscr_defect_data-defect_val,
fld109 like zscr_defect_data-defect_val,
fld110 like zscr_defect_data-defect_val,
fld111 like zscr_defect_data-defect_val,
fld112 like zscr_defect_data-defect_val,
fld113 like zscr_defect_data-defect_val,
fld114 like zscr_defect_data-defect_val,
fld115 like zscr_defect_data-defect_val,
fld116 like zscr_defect_data-defect_val,
fld117 like zscr_defect_data-defect_val,
fld118 like zscr_defect_data-defect_val,
fld119 like zscr_defect_data-defect_val,
fld120 like zscr_defect_data-defect_val,
fld121 like zscr_defect_data-defect_val,
fld122 like zscr_defect_data-defect_val,
fld123 like zscr_defect_data-defect_val,
fld124 like zscr_defect_data-defect_val,
fld125 like zscr_defect_data-defect_val,
fld126 like zscr_defect_data-defect_val,
fld127 like zscr_defect_data-defect_val,
fld128 like zscr_defect_data-defect_val,
fld129 like zscr_defect_data-defect_val,
fld130 like zscr_defect_data-defect_val,
fld131 like zscr_defect_data-defect_val,
fld132 like zscr_defect_data-defect_val,
fld133 like zscr_defect_data-defect_val,
fld134 like zscr_defect_data-defect_val,
fld135 like zscr_defect_data-defect_val,
dayst like zscr_data_hdr-dayst,
end of t_data.
In this fld1 to fld135 are defined in internal table.
But if the number of fields are more than 135 then the program is going to short dump.
Some times fld1 to fid170 or more fields will be there in my internal table.
Please suggest me how to make my requirement dynamic and display this data fetched into this internal table onto a .XLS file in the presentation server ?Hi
You can try to use the type string:
form like zscr_data_hdr-form,
werks like zscr_data_hdr-werks,
matnr like zscr_data_hdr-matnr,
verid like zscr_data_hdr-verid,
lot like zscr_data_hdr-lot,
lot_qty like zscr_data_hdr-lot_qty,
udate like zscr_data_hdr-udate,
utime like zscr_data_hdr-utime,
zuser like zscr_data_hdr-zuser,
processed like zscr_data_hdr-processed,
defect like zscr_defect_data-defect,
vornr like zscr_route_data-vornr,
fieldxx type string,
dayst like zscr_data_hdr-dayst,
end of t_data.
So you can save you informations of every fld<n> concatenating their values into fieldxx.
Max -
Problem creating an internal table dynamically
Hi,
I'm trying to create an internal table dynamically as i would be able to determine the structure of the table based on the user input.
I've used the sample code from this forum ...
REPORT ZRICH_0003 .
type-pools: slis.
field-symbols: <dyn_table> type standard table,
<dyn_wa>,
<dyn_field>.
data: alv_fldcat type slis_t_fieldcat_alv,
it_fldcat type lvc_t_fcat.
type-pools : abap.
data : it_details type abap_compdescr_tab,
wa_details type abap_compdescr.
data : ref_descr type ref to cl_abap_structdescr.
data: new_table type ref to data,
new_line type ref to data,
wa_it_fldcat type lvc_s_fcat.
selection-screen begin of block b1 with frame title text.
parameters: p_table(30) type c.
selection-screen end of block b1.
Get the structure of the table.
ref_descr ?= cl_abap_typedescr=>describe_by_name( p_table ).
it_details[] = ref_descr->components[].
loop at it_details into wa_details.
clear wa_it_fldcat.
wa_it_fldcat-fieldname = wa_details-name .
wa_it_fldcat-datatype = wa_details-type_kind.
wa_it_fldcat-inttype = wa_details-type_kind.
wa_it_fldcat-intlen = wa_details-length.
wa_it_fldcat-decimals = wa_details-decimals.
append wa_it_fldcat to it_fldcat .
endloop.
Create dynamic internal table and assign to FS
call method cl_alv_table_create=>create_dynamic_table
exporting
it_fieldcatalog = it_fldcat
importing
ep_table = new_table.
assign new_table->* to <dyn_table>.
Create dynamic work area and assign to FS
create data new_line like line of <dyn_table>.
assign new_line->* to <dyn_wa>.
<b>* Select Data from table.
select * into table <dyn_table> from
(p_table).</b>
Write out data from table.
loop at <dyn_table> into <dyn_wa>.
do.
assign component sy-index of structure <dyn_wa> to <dyn_field>.
if sy-subrc <> 0.
exit.
endif.
if sy-index = 1.
write:/ <dyn_field>.
else.
write: <dyn_field>.
endif.
enddo.
endloop.
I'm able to get the structure of the table that i want, but when i'm trying to select data from the table into this internal table..as highlighted in the sample code above..i'm getting a short dump...saying that ' the database table is 600 bytes wide but the internal table is only 576 bytes wide.
The internal table is declared as
field-symbols: <dyn_table> type standard table..
Could anyone please tell me how to rectify this.
Thanks in advance,
Harsha.Hi Smitha,
I'm building the internal table by getting the structure using the method
cl_abap_typedescr=>describe_by_name( p_table ).
where p_table is the table name determined dynamically..
Now using this structure, i'm building an internal table by calling the method
call method cl_alv_table_create=>create_dynamic_table
I've checked all the fields after the internal table has been created .. and it contains all the fields of the table that i'm supplying initially..
But when i read data into that internal table, it gives me that dump..I've described it in this post earlier.
Any more suggestions would be very helpful.
Thanks,
Harsha -
How to create internal table dynamically based on a table entry
hi Experts,
I have table yprod_cat. It has product categories.
In my ABAP program I need to create internal table dynamically based on the number of entries in the table.
For example:
If the table has 3 entries for product category
1. Board
2. Micro
3. Syst
Then create three (3) internal tables.
i_board
i_micro
i_syst
How can we do this? Any sample code will be very usefull
Thanks & Regards
Gopal
Moderator Message: No sample codes can be given. Please search for them or work it!
Edited by: kishan P on Jan 19, 2011 4:22 PMOur APEX version is 4.2We are using below SQL query to display radio groups dynamically..
SELECT APEX_ITEM.RADIOGROUP (1,deptno,'20',dname) dt
FROM dept
ORDER BY 1;
Created a form using SQL type and given abouve SQL query as source.. But when we run the page, there were no radio groups displayed in the page..
Below is the output of the query..
<input type="radio" name="f01" value="10" />ACCOUNTING
<input type="radio" name="f01" value="20" checked="checked" />RESEARCH
<input type="radio" name="f01" value="30" />SALES
<input type="radio" name="f01" value="40" />OPERATIONS
>
If Tabular Form:
Edit Region > Report Attributes > Edit Column > Change the Column type to "Standard Report Column"
If normal Page Item:
Edit Page Item > Security > Escape special characters=No.
Pl read the help on that page item to understand the security risk associated with =NO.
Cheers,
Edited by: Prabodh on Dec 3, 2012 5:59 PM -
Hi,
I am getting the following exception when i trying to insert data in to a table through a stored procedure.
oracle.apps.fnd.framework.OAException: java.sql.SQLException: ORA-01801: date format is too long for internal buffer
when execute this stored procedure from ana anonymous block , it gets executed successfully, but i use a OracleCallableStatement to execute the procedure i am getting this error.
Please let me know how to resolve this error.
Is this error something to do with the Database Configuration ?
Thanks & Regards
MeenalI don't know if this will help, but we were getting this error in several of the standard OA framework pages and after much pain and aggravation it was determined that visiting the Sourcing Home Page was changing the timezone. For most pages this just changed the timezone that dates were displayed in, but some had this ORA-01801 error and some others had an ORA-01830 error (date format picture ends before converting entire input string). Unfortunately, if you are not using Sourcing at your site, this probably won't help, but if you are, have a look at patch # 4519817.
Note that to get the same error, try the following query (I got this error in 9.2.0.5 and 10.1.0.3):
select to_date('10-Mar-2006', 'DD-Mon-YYYY________________________________________________HH24:MI:SS') from dual;
It appears that you can't have a date format that is longer than 68 characters. -
Playing input stream audio in j2me
want to make a text-to-speech synthesizer for mobile phones.
for that i am using FreeTTS (text-to-speech synthesizer written in java)
so i have made a client-server model where i have a midp client which is sending text to the FreeTTS acting as a server.... for this i am using socket...
so basically -- client is sending text to server -- server processes the text and sends the audio stream back to client
the problem is i dont know how to play the audio stream received on client side
i tried to copy it in a buffer but its not working..
do i need to save the file in some format before playing it?
or can the player play the audio stream directly?
this is how i am copying the contents in the buffer
try
InputStream is = socketConnection.openInputStream();
byte[] buff = new byte[1024];
int bytesIn = is.read(buff, 0, 1024);
ByteArrayInputStream bis = new ByteArrayInputStream(buff);
player = Manager.createPlayer(bis, "audio/x-wav" );
player.start();
but it gives an error saying
javax.microedition.media.MediaException: Malformed wave media
i tried to display the contents of bis on console it reads
java.io.ByteArrayInputStream@d590dbc
i tried the same with the Free TTS client and got the same output.
so i think client socket is even receiving the audio stream properly...however, im not sure.
is the whole client-server using socket idea correct?
if yes, please tell me how to play this audio stream in j2me (the client)
if it is wrong then please tell me a correct way to do this.
can the input stream be stored as a WAV file and then played? if yes, then how can i store it as a WAV file? Can this be achieved by appending a WAV header?I once tried the similar thing, I ended up buffer all the content locally (from bluetooth), then play the wave file.
Maybe someone else has better idea. -
IOException: Connection reset by peer: JVM_recv in socket input stream read
hi
I encountered a problem : a program throw out an exception:java.io.IOException: Io exception:
Connection reset by peer: JVM_recv in socket input stream read.
I tried my best to resolve it ,but unfortunately,i didn't know what caused the exception.
the following is my application environment:
I have two PC(Win2000os),one is a server which installed oracle9.2.0.2 and jdeveloper9.0.3,the another is a
client which only intalled jdeveloper9.0.3.Two days ago,i performed a web application on my client with
jdeveloper,and it includes some JSP and a javabean files.JSP Page finished uploading client xml file to a
folder on server and the javabean finished loading the xml file into a xmltype column.I can make sure the
connection is established and the javabean is OK,beacause my some jsp page can successfully use
<jsp:usebean> tag and use the javabean's some other public interfaces,except the interface that finishs
loading the xml file into a xmltype(clob) column.
Then i do many tests!I changed the javabean to a java class incluse a main method beacause it is easy to
debug.Finally i found the following code caused the exception:
public CLOB writetoClob( CLOB clob, InputStream is )throws SQLException, IOException {
InputStreamReader reader = new InputStreamReader( is );
Writer writer = clob.getCharacterOutputStream( );
char[] buffer = new char[clob.getChunkSize( )];
int charsRead;
for ( charsRead = reader.read( buffer ); charsRead > -1;charsRead = reader.read( buffer ) ) {
writer.write( buffer, 0, charsRead );
writer.close();
return clob;
when it runs to writer.close(),the exception is caused!
Then i copy the java class to the server,it runs ok!
That is to say ,the same code,the different result!
But when i run my web application on server with jdeveloper Embedded OC4J Server and a jsp page loaded javabean
and run to mentioned code ,the same exception occured!
I checked the application log in event viewer,the descriptions was:
The data buffer created for the "AppleTalk" service in the "C:\WINNT\system32\atkctrs.dll" library is not
aligned on an 8-byte boundary. This may cause problems for applications that are trying to read the
performance data buffer. Contact the manufacturer of this library or service to have this problem corrected or
to get a newer version of this library.
I search some some resolution about this exception with web and someone sayed :
This basically means that a network error occurred while the client was receiving data from the server. But
what is really happening is that the server actually accepts the connection, processes the request, and sends a
reply to the client. However, when the server closes the socket, the client believes that the connection has
been terminated abnormally because the socket implementation sends a TCP reset segment telling the client to
throw away the data and report an error.
Sometimes, this problem is caused by not properly closing the input/output streams and the socket connection.
Make sure you close the input/output streams and socket connection properly. If everything is closed properly,
however, and the problem persists, you can work around it by adding Thread.sleep(1000) before closing the
streams and the socket. This technique, however, is not reliable and may not work on all systems.
In general,the following information is conclution:
Web application runs error both on client and on server.
If it was changed to a client java class,it only run ok on server!
i have done anything that i can do now,i feel depressed very much!
how can i resolve the problem!
Any a little help will be appreciated!
regards!
Thanks
Jiawei ZHAOHow can i solve the problem.
Thanks in advance!
Jiawei Zhao -
Java.lang.Process input stream waiting until process is complete to print
I have tried to simplify this problem as much as possible. Basically, I have a java.lang.Process which executes a simple C program.
test.c
#include <stdio.h>
#include <unistd.h>
int main()
printf("foo\n");
sleep(2);
printf("bar\n");
...The process has an input stream and error stream handler each on a separate thread. I have tried both buffered and unbuffered (BufferedReader, BufferedInputStream, InputStreamReader...) stream handlers. Both produce the same problem of waiting until the process has exited to receive anything from the process's streams.
The only time this does not happen is when I call fflush(stdout); after each printf(). This can't be a solution because the real application calls a massive C application which would require thousands of fflush()'s to be added. What is causing this to happen? This doesn't happen when the C program is executed from the shell. Is there a way the InputStream can be forced to extract from the stream?hi.....
I have closed the output stream of the process as you told me to do...
The hitch is that, if my program contains only printf() statements,it works fine
as soon as scanf() statement is encountered within the C code,it is totally neglected,and the output comes as if no scanf() statement existed in the C code.
Consequently the thread doesnt wait for input which was bound for scanf() from the thread
the code...
public void run()
try
PrintWriter out = new PrintWriter(socket.getOutputStream(),true);
BufferedReader in = new BufferedReader(
new InputStreamReader(
socket.getInputStream()));
try
Process p;
p=new ProcessBuilder("./a.out").start();
PrintWriter exOut=null;
BufferedReader exIn=null;
exOut = new PrintWriter(p.getOutputStream(),true);
exIn = new BufferedReader(
new InputStreamReader(
p.getInputStream()));
//String inputLine="", outputLine="";
String str="";
int c;
while(true)
//System.out.println("In While");
str="";exOut.close();
while((c=exIn.read())!=-1)
str=str+(char)(c);
System.out.print(str);
str=str+(char)(0);
System.out.print(str+"outside");
out.print(str);
sleep(100);
try
int x=p.exitValue();
out.print(str);
System.out.print("Bye 1");
String str1="Bye"+(char)(0);
out.println(str1);
break;
catch(IllegalThreadStateException e)
//System.out.println("The Process has not ended yet");
//str=str+((char)-1);
//System.out.print(str+"Control reaches here too");
str="";
exOut = new PrintWriter(p.getOutputStream(),true);//I have tried to run the program without this also but the effect is the same
while((c=in.read())!=-1)
str=str+(char)(c);
if(str.contentEquals(""))
System.out.print("Bye 2");
String str1="Bye"+(char)(0);
out.println(str1);
p.destroy();
exOut.close();
exIn.close();
out.close();
in.close();
socket.close();
break;
//str=str+(char)(0);
exOut.print(str);
try
int x=p.exitValue();
System.out.print("Bye 3");
String str1="Bye"+(char)(0);
out.println(str1);
break;
catch(IllegalThreadStateException e)
//System.out.println("The Process has not ended yet");
/*while ((inputLine = in.readLine()) != null)
exOut.println(inputLine);
outputLine=exIn.readLine();
//outputLine=inputLine;
//out.println(outputLine);}*/
exOut.close();
exIn.close();
catch(IOException e)
System.err.println("Accept failed."+e);
out.close();
in.close();
socket.close();
catch (Exception e)
e.printStackTrace();
}
Maybe you are looking for
-
Accessing BKPF table takes too long
Hi, Is there another way to have a faster and more optimized sql query that will access the table BKPF? Or other smaller tables that contain the same data? I'm using this: select bukrs gjahr belnr budat blart into corresponding fields of table
-
Samsung 640GB hard drive issues
Hi Everyone, This is my first post on these forums, but have browsed them lots before and have found quite a bit of help. Unfortunately I wasn't able to find a difinitive solution and was hoping someone might have an answer for me. In November of las
-
Hi, i just new installed my MacBook and tried to install Adobe Acrobat 9 Pro. It worked fine ... So just now I'm running on 9.0.0 I noticed that there is a problem with this version when running on mavericks. After I asked Google I found out that I s
-
Creating Apps in Flash that allows connection with any existing LMS
Hi Everyone, I am interested to create e-learning apps using Flash and then output it using AIR to a native extension as an .ipa or .apk format. Can you connect with any existing LMS using Actionscript 3.0? I am curious as I have been searching over
-
Is there any tools available that can convert the legacy oracle reports to jasper reports?