Strange issue with POF: byte array with the value 94
This is a somewhat strange issue we’ve managed to reduce to this test case. We’ve also seen similar issues with chars and shorts as well. It’s only a problem if the byte value inside the byte array is equal to 94! A value of 93, 95, etc, seems to be ok.
Given the below class, the byte values both in the array and the single byte value are wrong when deserializing. The value inside the byte array isn’t what we put in (get [75] instead of [94]) and the single byte value is null (not 114).
Pof object code:
package com.test;
import java.io.IOException;
import java.util.Arrays;
import com.tangosol.io.pof.PofReader;
import com.tangosol.io.pof.PofWriter;
import com.tangosol.io.pof.PortableObject;
public class PofObject1 implements PortableObject {
private byte[] byteArray;
private byte byteValue;
public void setValues() {
byteArray = new byte[] {94};
byteValue = 114;
@Override
public void readExternal(PofReader reader) throws IOException {
Object byteArray = reader.readObjectArray(0, null);
Object byteValue = reader.readObject(1);
System.out.println(Arrays.toString((Object[])byteArray));
System.out.println(byteValue);
if (byteValue == null) throw new IOException("byteValue is null!");
@Override
public void writeExternal(PofWriter writer) throws IOException {
writer.writeObject(0, byteArray);
writer.writeObject(1, byteValue);
Using writer.writeObjectArray(0, byteArray); instead of writer.writeObject(0, byteArray); doesn't help. In this case byteArray would be of type Object[] (as accessed through reflection).
This is simply put in to a distributed cache and then fetched back. No EPs, listeners or stuff like that involved:
public static void main(String... args) throws Exception {
NamedCache cache = CacheFactory.getCache("my-cache");
PofObject1 o = new PofObject1();
o.setValues();
cache.put("key1", o);
cache.get("key1");
Only tried it with Coherecne 3.7.1.3.
Cache config file:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE cache-config SYSTEM "cache-config.dtd">
<cache-config>
<caching-scheme-mapping>
<cache-mapping>
<cache-name>my-cache</cache-name>
<scheme-name>my-cache</scheme-name>
</cache-mapping>
</caching-scheme-mapping>
<caching-schemes>
<distributed-scheme>
<scheme-name>my-cache</scheme-name>
<service-name>my-cache</service-name>
<serializer>
<class-name>
com.tangosol.io.pof.ConfigurablePofContext
</class-name>
<init-params>
<init-param>
<param-type>string</param-type>
<param-value>pof-config.xml</param-value>
</init-param>
</init-params>
</serializer>
<lease-granularity>thread</lease-granularity>
<thread-count>10</thread-count>
<backing-map-scheme>
<local-scheme>
</local-scheme>
</backing-map-scheme>
<autostart>true</autostart>
</distributed-scheme>
</caching-schemes>
</cache-config>
POF config file:
<?xml version="1.0"?>
<pof-config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://xmlns.oracle.com/coherence/coherence-pof-config"
xsi:schemaLocation="http://xmlns.oracle.com/coherence/coherence-pof-config coherence-pof-config.xsd">
<user-type-list>
<!-- coherence POF user types -->
<include>coherence-pof-config.xml</include>
<user-type>
<type-id>1460</type-id>
<class-name>com.test.PofObject1</class-name>
</user-type>
</user-type-list>
</pof-config>
Hi,
POF uses certain byte values as an optimization to represent well known values of certain Object types - e.g. boolean True and False, some very small numbers, null etc... When you do read/write Object instead of using the correct method I suspect POF gets confused over the type and value that the field should be.
There are a number of cases where POF does not know what the type is - Numbers would be one of these, for example if I stored a long of value 10 on deserialization POF would not know if that was an int, long double etc... so you have to use the correct method to get it back. Collections are another - If you serialize a Set all POF knows is that you have serialized some sort of Collection so unless you are specific when deserializing you will get back a List.
JK
Similar Messages
-
I have a binary file to be read.I want to read the whole file into a byte array. But while doing so the values which are greater than 128 are read as negative values as we have Signedbyte in java(-127 to 128).
So I tried reading the bytes into the int array as shown in the below code.
int i = 0;
int content[]= new int[(int)size];
FileInputStream fstream = new FileInputStream(fileName);
DataInputStream in = new DataInputStream(fstream);
while(i<size)
content= in.readUnsignedByte();
i++;
The above function 'readUnsignedByte();' reads byte and stores it into an int array.....But since the file contains around 34000 bytes ....the loop runs 340000 times .....which is a performance hazard.
After googling for hours ....I could still not find any alternative ....
I want to read byte and want to store in int array but instead of loop, I want to read the file at once.
Or is there any way to implement Unsigned Byte in java so that I can read the entire file in byte array without corrupting the values which are greater than 128..
I have to deliver the code asap .....Please help me out with an alternative solution for this...
Thanks in advance....Thanks for replying ......
Actually, I need to take the bytes into an array(int or byte array) with decimal values and further process these decimal values.......
but while reading the file into a byte array the decimal values get corrupted(in case when I read a number greater than 128) but in this case I am able to read the whole file at once(without using any loop) as done by the following code
FileInputStream fstream = new FileInputStream(fileName);
DataInputStream in = new DataInputStream(fstream);
byte b[] = null;
in.readFully(b);
and while reading the file in int array as done in the below code is inefficient as the number of times the loop runs is more than 34000..... please suggest me some alternative.
int i = 0;
int content[]= new int[(int)size];
FileInputStream fstream = new FileInputStream(fileName);
DataInputStream in = new DataInputStream(fstream);
while(i<size)
content= in.readUnsignedByte();
i++; -
Strange issue - unable to establish PPP with Cisco 887 VAG router on one particular ADSL line
I have a strange problem that I’m struggling to get to the bottom of with my ISP and wondered if anyone could help.
We have a site with an older Cisco 877 ADSL router which was working happily until a few weeks ago when the connection dropped suddenly (out-of-hours at 2am if that’s of any significance – made me think most likely something carrier/ISP related?) When connectivity was lost, the router could sync with the BT exchange (we are in the UK) but could not establish PPP.
We logged fault with our ISP – after some to’ing and fro’ing, they passed it onto BT and their engineers visited site, they fixed “a line fault” (we don’t get much detail on what was actually fixed) but we still could not establish connectivity – same thing, solid CD light but no PPP.
So, we replaced the router with another 877 – same again, solid CD but no PPP. We replaced all the cables and microfilter etc but no difference.
We tried a different Cisco router (a newer Cisco 887VAG) which, as I understand, uses a different modem chipset but no matter – PPP could still not be established. We tested this router on another ADSL line with the same ISP and it worked without issue, using the same ADSL account details, it was able to establish connectivity. So we figured this must still be a BT/ISP issue.
Since then we’ve had BT out again twice but they say there is no fault. The ISP say there is no issue with them. But we still cannot establish ADSL connectivity on this line, despite having tried 3 different ADSL routers and despite the fact the routers work with the same account details on another ADSL line.
The 887VAG router we have currently connected has 3G backup so that is keeping us going in the meantime and also means I can login to the router remotely to check on the ADSL status.
But I’m struggling to pinpoint where the problem may lie. Strangely, if I turn on PPP negotiation and authentication debug then I’m not actually seeing any output from it at all?
Yet, the ATM interface is up and shows packets being sent and received:
ATM0 is up, line protocol is up
Hardware is MPC ATMSAR, address is bc16.6596.9b00 (bia bc16.6596.9b00)
MTU 1600 bytes, sub MTU 1600, BW 704 Kbit/sec, DLY 520 usec,
reliability 255/255, txload 1/255, rxload 1/255
Encapsulation ATM, loopback not set
Keepalive not supported
Encapsulation(s): AAL5
4 maximum active VCs, 1024 VCs per VP, 1 current VCCs
VC Auto Creation Disabled.
VC idle disconnect time: 300 seconds
Last input 00:00:28, output 00:00:07, output hang never
Last clearing of "show interface" counters 6d23h
Input queue: 0/75/0/0 (size/max/drops/flushes); Total output drops: 0
Queueing strategy: Per VC Queueing
5 minute input rate 0 bits/sec, 0 packets/sec
5 minute output rate 0 bits/sec, 0 packets/sec
23886 packets input, 1676964 bytes, 0 no buffer
Received 0 broadcasts (0 IP multicasts)
0 runts, 0 giants, 0 throttles
0 input errors, 0 CRC, 0 frame, 0 overrun, 0 ignored, 0 abort
56469 packets output, 4418592 bytes, 0 underruns
0 output errors, 0 collisions, 6 interface resets
0 unknown protocol drops
0 output buffer failures, 0 output buffers swapped out
Does anyone have any ideas on where the problem may be and what more I can do to troubleshoot and provide the relevant evidence to our ISP (assuming it is an ISP/BT issue though the fact the same router works ok with the exact same details etc would seem to indicate it must be their issue!)Hi Jody,
thanks for the suggestions. Here's what I see from the ppp debugs (but I'm not sure how to interpret?)
Jan 6 14:50:22.838: pppoe_send_padi:
contiguous pak, size 74
00 01 09 00 AA AA 03 00 80 C2 00 07 00 00 FF FF
FF FF FF FF BC 16 65 96 9B 00 88 63 11 09 00 00
00 10 01 01 00 00 01 03 00 08 0C 00 00 01 00 00
04 A3 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 ...
Jan 6 14:50:22.878: PPPoE 0: I PADO R:0030.8810.000b L:bc16.6596.9b00 0/38 ATM0.1
contiguous pak, size 71
BC 16 65 96 9B 00 00 30 88 10 00 0B 88 63 11 07
00 00 00 33 01 03 00 08 0C 00 00 01 00 00 04 A3
01 02 00 1F 62 72 61 73 2D 72 65 64 37 2E 6C 73
2D 62 61 73 2D 42 32 32 36 45 34 37 30 39 45 30
31 34 5A 01 01 00 00
Jan 6 14:50:24.885: OUT PADR from PPPoE Session
contiguous pak, size 85
00 01 09 00 AA AA 03 00 80 C2 00 07 00 00 00 30
88 10 00 0B BC 16 65 96 9B 00 88 63 11 19 00 00
00 33 01 03 00 08 0C 00 00 01 00 00 04 A3 01 02
00 1F 62 72 61 73 2D 72 65 64 37 2E 6C 73 2D 62
61 73 2D 42 32 32 36 45 ...
Jan 6 14:50:35.125: OUT PADR from PPPoE Session
contiguous pak, size 85
00 01 09 00 AA AA 03 00 80 C2 00 07 00 00 00 30
88 10 00 0B BC 16 65 96 9B 00 88 63 11 19 00 00
00 33 01 03 00 08 0C 00 00 01 00 00 04 A3 01 02
00 1F 62 72 61 73 2D 72 65 64 37 2E 6C 73 2D 62
61 73 2D 42 32 32 36 45 ...
Jan 6 14:50:45.364: OUT PADR from PPPoE Session
contiguous pak, size 85
00 01 09 00 AA AA 03 00 80 C2 00 07 00 00 00 30
88 10 00 0B BC 16 65 96 9B 00 88 63 11 19 00 00
00 33 01 03 00 08 0C 00 00 01 00 00 04 A3 01 02
00 1F 62 72 61 73 2D 72 65 64 37 2E 6C 73 2D 62
61 73 2D 42 32 32 36 45 ...
Jan 6 14:50:55.603: OUT PADR from PPPoE Session
contiguous pak, size 85
00 01 09 00 AA AA 03 00 80 C2 00 07 00 00 00 30
88 10 00 0B BC 16 65 96 9B 00 88 63 11 19 00 00
00 33 01 03 00 08 0C 00 00 01 00 00 04 A3 01 02
00 1F 62 72 61 73 2D 72 65 64 37 2E 6C 73 2D 62
61 73 2D 42 32 32 36 45 ...
Jan 6 14:51:05.843: OUT PADR from PPPoE Session
contiguous pak, size 85
00 01 09 00 AA AA 03 00 80 C2 00 07 00 00 00 30
88 10 00 0B BC 16 65 96 9B 00 88 63 11 19 00 00
00 33 01 03 00 08 0C 00 00 01 00 00 04 A3 01 02
00 1F 62 72 61 73 2D 72 65 64 37 2E 6C 73 2D 62
61 73 2D 42 32 32 36 45 ...
Jan 6 14:51:16.114: OUT PADR from PPPoE Session
contiguous pak, size 85
00 01 09 00 AA AA 03 00 80 C2 00 07 00 00 00 30
88 10 00 0B BC 16 65 96 9B 00 88 63 11 19 00 00
00 33 01 03 00 08 0C 00 00 01 00 00 04 A3 01 02
00 1F 62 72 61 73 2D 72 65 64 37 2E 6C 73 2D 62
61 73 2D 42 32 32 36 45 ...
Jan 6 14:51:26.353: [0]PPPoE 0: O PADT R:0000.0000.0000 L:0000.0000.0000 0/38 ATM0.1
contiguous pak, size 74
00 01 09 00 AA AA 03 00 80 C2 00 07 00 00 00 00
00 00 00 00 00 00 00 00 00 00 88 63 11 A7 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 ...
Jan 6 14:51:46.576: pppoe_send_padi:
contiguous pak, size 74
00 01 09 00 AA AA 03 00 80 C2 00 07 00 00 FF FF
FF FF FF FF BC 16 65 96 9B 00 88 63 11 09 00 00
00 10 01 01 00 00 01 03 00 08 0C 00 00 01 00 00
04 A3 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 ...
Jan 6 14:51:46.608: PPPoE 0: I PADO R:0030.8810.000b L:bc16.6596.9b00 0/38 ATM0.1
contiguous pak, size 71
BC 16 65 96 9B 00 00 30 88 10 00 0B 88 63 11 07
00 00 00 33 01 03 00 08 0C 00 00 01 00 00 04 A3
01 02 00 1F 62 72 61 73 2D 72 65 64 37 2E 6C 73
2D 62 61 73 2D 42 32 32 36 45 34 37 30 39 45 30
31 34 5A 01 01 00 00
Provider wouldn't have bumped us from ADSL to VDSL - but here's the output of show controller vdsl 0:
Controller VDSL 0 is UP
Daemon Status: Up
XTU-R (DS) XTU-C (US)
Chip Vendor ID: 'BDCM' 'IFTN'
Chip Vendor Specific: 0x0000 0x71C8
Chip Vendor Country: 0xB500 0xB500
Modem Vendor ID: 'CSCO' ' '
Modem Vendor Specific: 0x4602 0x0000
Modem Vendor Country: 0xB500 0x0000
Serial Number Near: FCZ1111C08V C887VAG 15.2(4)M
Serial Number Far:
Modem Version Near: 15.2(4)M
Modem Version Far: 0x71c8
Modem Status: TC Sync (Showtime!)
DSL Config Mode: AUTO
Trained Mode: G.992.1 (ADSL) Annex A
TC Mode: ATM
Selftest Result: 0x00
DELT configuration: disabled
DELT state: not running
Trellis: ON ON
SRA: disabled disabled
SRA count: 0 0
Bit swap: enabled enabled
Bit swap count: 1 8
Line Attenuation: 54.5 dB 31.5 dB
Signal Attenuation: 54.5 dB 0.0 dB
Noise Margin: 6.7 dB 11.0 dB
Attainable Rate: 2132 kbits/s 888 kbits/s
Actual Power: 16.7 dBm 12.7 dBm
Total FECC: 546 0
Total ES: 6 0
Total SES: 0 0
Total LOSS: 0 0
Total UAS: 486 486
Total LPRS: 0 0
Total LOFS: 0 0
Total LOLS: 0 0
Full inits: 14
Failed full inits: 1
Short inits: 0
Failed short inits: 1
Firmware Source File Name (version)
VDSL user config flash:vdsl.bin-A2pv6C035d_d23j (10)
Modem FW Version: 110802_1752-4.02L.03.A2pv6C035d.d23j
Modem PHY Version: A2pv6C035d.d23j
Vendor Version:
DS Channel1 DS Channel0 US Channel1 US Channel0
Speed (kbps): 0 1664 0 704
SRA Previous Speed: 0 0 0 0
Previous Speed: 0 1600 0 736
Total Cells: 0 2786872 0 0
User Cells: 0 68 0 0
Reed-Solomon EC: 0 546 0 0
CRC Errors: 0 9 0 0
Header Errors: 0 10 0 0
Interleave (ms): 0.00 8.00 0.00 8.00
Actual INP: 0.00 1.12 0.00 1.28
Training Log : Stopped
Training Log Filename : flash:vdsllog.bin
And here's the output from the ATM and dialer interfaces:
interface ATM0
no ip address
ip flow ingress
no atm ilmi-keepalive
end
interface ATM0.1 point-to-point
ip flow ingress
pvc 0/38
pppoe-client dial-pool-number 2
end
interface Dialer2
description OUTSIDE
ip address negotiated
ip access-group firewall in
ip mtu 1492
ip flow ingress
ip nat outside
ip inspect DEFAULT100 out
ip virtual-reassembly in
encapsulation ppp
dialer pool 2
dialer-group 2
ppp authentication chap callin
ppp chap hostname ###removed###
ppp chap password ###removed###
no cdp enable
crypto map dcvpn
end
As I say though, config-wise, everything should be correct - the same router works fine on another line (which should also confirm the authentication details are correct - at least in as far as it matches what the ISP have on their RADIUS)
Any further thoughts? -
How to encrypt byte array with out padding using RSA in Java?
I've modulus and public exponent as byte[] array, so I'm trying to convert into BigIntegers and then create public key and then Cipher. Here is the example code:
With this I'm always getting different encrypted bytes, is it because of padding. I dont want to use any padding so what parameter I need to pass along with RSA? I've modulus byte[] array size 64 bytes. I believe I'll get 64 encrypted bytes. I've content size of 32 bytes to be encrypted.
--------code begin ---------------------------
BigInteger bexponent = new BigInteger(pubExpo);
BigInteger bmodulus = new BigInteger(modulus);
KeyFactory keyFactory = KeyFactory.getInstance("RSA");
RSAPublicKeySpec pubKeySpec = new RSAPublicKeySpec(bmodulus, bexponent);
RSAPublicKey pubKey = (RSAPublicKey)keyFactory.generatePublic(pubKeySpec);
Cipher c = Cipher.getInstance("RSA");
c.init(Cipher.ENCRYPT_MODE, pubKey);
return c.doFinal(content);
--------code end---------------------------With this I'm always getting different encrypted
bytes, is it because of padding. Yes, if you're using PKCS1Padding (which is the default in SunJCE if you don't specify it). Have a look at the PKCS1 spec if you haven't seen it already.
http://www.rsasecurity.com/rsalabs/pkcs
Section 7.2.1 talks about type 2 padding, which uses random bytes as the PS string.
I dont want to use
any padding so what parameter I need to pass along
with RSA? NOPADDING. You should be able to find this out by look at the "Supported Paddings" parameter in your provider's database. Which of course, means you'll need to supply the right number of bytes to the Cipher. -
Display jpeg byte array with JSP !!
I am new in JSP area so maybe I ask a easy question !!
First, on the server side:I use a C++ program to stream sequence jpeg data out(FF D8 ~ FF D9).
Second, on the client side:I use jsp to open a socket and read
data to a byte array.
Can anyone tell me how to display the jpeg array on browser one by one ?um... like video frames, or just a single image? I wouldn't really use JSP for that, I'd use a servlet, set the content-type to image/jpeg and just write out the bytes. Unless you are talking about displaying the bytes themselves, in which case, a JSP page would be better. If it's video frames, I'm not sure how to have the browser do that, since most no longer support server push.
-
Creation of a Table Type value set with 'ALL' as one of the value
Gurus,
My requirement is to create [table type]value set which would show the [LOV]values in parameter of Conc Progr .
So far we have three such values to chose from ,they are, 'Frozen', 'Pending' and 'Testing'. I achieved it.
My question is ,
if user wants to choose 'ALL' three values , how shall I accommodate it in this table type value set?
Giving fourth option as ALL, which would eventually select 'ALL' three values 'Frozen', 'Pending' and 'Testing'.
thanks in advance.
-sDJYou can't have UNION in the value set.
Try creating a view, which is having UNION with ALL.
Check the following links.
Table Value Set.
ORA-00907 Missing Right Parenthesis in Value Set
By
Vamsi -
Format a number with a decimal to show the value but not the decimal point
I have a value of 129.50 in the DB. I'm using the htp.prn() function to export this value to a txt file. I have the field padded with leading 0s (so it looks like 0000129.50)
I need to keep the value for the .50 but don't want the decimal point to show up (so I need it to look like 000012950) but can't figure out how to make it keep the value for the .50 but not actually show the decimal point - any ideas? (APEX 4.0 11g)Multiply by 100 and remove the formatting. htp.prn (to_char (number_item, '99999999999'));
Edited by: Kleber M on Sep 14, 2011 5:10 AM -
Proving the Input values in a table with a dropdown and save the values
Hi Experts,
I have a requirement to create a table which is empty (in BSP)and I want to enter the values in a table, for eg: Unit , RegNo, Regvalidity date, item categories. are the coulum names.But I have to display the values in the categories column in dropdown.
Finally I enter the values in a table and select the values in a categorie column and save the values in a ztable.
Please provide me solution how to proceed with this requirement?.
Thanks ,
Regards,
KiranHi Kiran,
For creating blank tabel in BSP use the iterator. See the beolow link for information on creating balnk lines using iterator,
http://help.sap.com/saphelp_nw04/helpdata/en/2a/31b98a35a111d5992100508b6b8b11/frameset.htm
the code in render_cell_start method of iterator class should be something like,
initially you render all cells as blank so that the blank table is created in page.
when a row is selected you render unit, reg no., reg validity date as inputfield and categories as dropdown listbox.
Dropdown in Tableview
link might help you for DDLB in tableview.
Search the forum and blogs for more code samples.
Regards,
Anubhav -
Text Box issue - displays XML tag instead of the value in EBS
I need to use a textbox (or a autoshape with text) to place a data element in a specific position on the page in an RTF template. I tried using tables and it didn't help. This layout needs some elements to be placed at specific location and using an autoshape or a text box is easy. When I preview the pdf output on my desktop, it works fine. Once I upload the template into EBS XML Publisher, the value in the text box shows up as an XML Tag instead of the value in that tag. The same XML data when loaded and previewed locally shows the data instead of the tag.
Any thoughts on this? Is there a patch or something we might need for this in EBS?
Thanks,
VinayThanks Tim for the quick response.
Yes - the versions are same. Also, I tried giving the complete path. The issue is that it is not even reading the text in the text box as an XML tag. It seems to think the whole text box is an object and hence just display that text as is. If it was reading and not able to resolve it, I guess it would have displayed blank (and not the tag as is). Again as I mentioned it works fine in local preview on my machine. -
How to create PNG file from byte array of RGB value?
Hi
Here is my problem.
I have drawn some sketchs (through code in runtime) on canvas. I have grabbed the RGB information for the drwan image and converted to byte array.
I have to pass this byte array to server and generate a png file and save.
Please help.{color:#ff0000}Cross posted{color}
http://forum.java.sun.com/thread.jspa?threadID=5218093
{color:#000080}Cross posting is rude.
db{color} -
How to send byte array and String values to servlet from Swing application
Hi all,
I am new to swing, servlet, and socket connection.
I have swing application to draw images and some input data. I dont know to send to server.
byte[] buf = baos.toByteArray();
URL servletURL = new URL("http://10.70.70.1:8080/servlet/SaveImage)
URLConnection conn = servletURL.openConnection();
conn.setDoOutput(true);
BufferedWriter out = new BufferedWriter( new OutputStreamWriter( conn.getOutputStream() ) );
out.write(buf&a=aaaa&b=bbbbb);
out.flush();
out.close();
can I do like this. Strings are received in server side perfect. but i cant get byte array data. Please help me.
Thanks in advance.<img src="myservlet">
In your myservlet:
response.setContentType("image/jpeg");
then write your image date via ImageIO that uses response output stream. -
Need an ARRAY of the values for the user to see the array values
how would I display the values to the user in an array?????
for all three loans in my java code
import java.text.*; //20 May 2008, Revision ...many
import java.io.IOException;
class memortgage //program class name
public static void main(String[] args) throws IOException
double amount,moPay,totalInt,principal = 200000; //monthly payment, total interest and principal
double rate [ ] = {.0535, .055, .0575}; //the three interest rates
int [ ] term = {7,15,30}; //7, 15 and 30 year term loans
int time,ratePlace = 0,i,pmt=1,firstIterate = 0,secondIterate = 0,totalMo=0;
char answer,test;
boolean validChoice;
System.in.skip(System.in.available()); //clear the stream for the next entered character
do
validChoice = true;
System.out.println("What Choice would you Like\n");
System.out.println("1-Interest rate of 5.35% for 7 years?"); //just as it reads for each to select from
System.out.println("2-Interest rate of 5.55% for 15 years?");
System.out.println("3-Interest rate of 5.75% for 30 years?");
System.out.println("4-Quit");
answer = (char)System.in.read();
if (answer == '1') //7 yr loan at 5.35%
ratePlace = 0;
firstIterate = 4;
secondIterate = 21;
totalMo= 84;
else if (answer == '2') //15 yr loan at 5.55%
ratePlace = 1;
firstIterate = 9; //it helps If I have the correct numbers to calcualte as in 9*20 to equal 180...that why I was off -24333.76
secondIterate = 20; //now it is only of -0.40 cents....DAMN ME
totalMo = 180;
else if (answer == '3') //30 yr loan at 5.75%
ratePlace = 2;
firstIterate = 15;
secondIterate = 24;
totalMo = 360;
else if (answer == '4') //exit or quit
System.exit(0);
else
System.in.skip(System.in.available()); //validates choice
System.out.println("Invalid choice, try again.\n\n");
validChoice = false;
}while(!validChoice); //when a valid choice is found calculate the following, ! means not, similar to if(x != 4)
for(int x = 0; x < 25; x++)System.out.println();
amount = (principal + (principal * rate[ratePlace] * term[ratePlace] ));
moPay = (amount / totalMo);
totalInt = (principal * rate[ratePlace] * term[ratePlace]);
DecimalFormat df = new DecimalFormat("0.00");
System.out.println("The Interest on $" + (df.format(principal) + " at " + rate[ratePlace]*100 +
"% for a term of "+term[ratePlace]+" years is \n" +"$"+ (df.format(totalInt) +" Dollars\n")));
System.out.println("\nThe total amount of loan plus interest is $"+(df.format(amount)+" Dollars.\n"));
System.out.println("\nThe Payments spread over "+term[ratePlace]* 12+" months would be $"+
(df.format (moPay) + " Dollars a month\n\n"));
System.in.skip(System.in.available());
System.out.println("\nWould you like to see a planned payment schedule? y for Yes, or x to Exit");
answer = (char)System.in.read();
if (answer == 'y')
System.out.println((term[ratePlace]*12) + " monthly payments:");
String monthlyPayment = df.format(moPay);
for (int a = 1; a <= firstIterate; a++)
System.out.println(" Payment Schedule \n\n ");
System.out.println("Month Payment Balance\n");
for (int b = 1; b <= secondIterate; b++)
amount -= Double.parseDouble(monthlyPayment);
System.out.println(""+ pmt++ +"\t"+ monthlyPayment + "\t"+df.format(amount));
System.in.skip(System.in.available());
System.out.println(("This Page Is Complete Press [ENTER] to Continue"));
System.in.read();
}skull_innocent wrote:
whooooooo...dang....just tell me nicely .
Sorry.
I thought that this question I submitted in the wrong area previously
There are better ways to correct me in my errors for posting
I am sorry.Okay, no harm done.
I hope that you understand that a major beef of contributors here is to spend time answering a question, only to later discover that somebody else has posted a similar answer in another thread. Hence the annoyance at crossposters.
In the future, if you think you've posted in the wrong forum, or if for whatever reason you decide to post in multiple forums, pick one thread as the "main" one and provide a link to it in the others. -
Sending command apdu with a byte array as CDATA
Hi,
I am learning java card as part of my final year project. So far I think I can do most of the basic things but I have got stuck at one particular point.
I know that there are different constructors for creating a command apdu object and a number of these constructors take an array of bytes as CDATA values.
My problem is, how to access this array of data in the card side because apdu.getBuffer() returns an array of integers (bytes)? And what is actually on apdu.getBuffer()[ISO7816.OFFSET_CDATA)] location when you send command apdu object using such a constuctor?
regards
Edited by: 992194 on 06-Mar-2013 06:12992194 wrote:
(..) I should have mentioned earlier that my card use jc 2.2.1 version, and i have read from different places that this version does not support ExtendedLength facility.Indeed.
Also I understand the semantics of apdu.getBuffer()[ISO7816.OFFSET_CDATA] that is the first byte of the command data. My question is, this command data was initially supplied as an array of bytes. Something like this:
+new CommandAPDU(CLA, INS, P1, P2, DATA_ARRAY, Le)+
So when you call:
byte [] buffer = apdu.getBuffer()
So does this mean that the byte values inside DATA_ARRAY automatically occupy locations +buffer[ISO7816.OFFSET_CDATA]+ onwards inside the buffer?Yes. The length would be<tt> (short)(buffer[ISO7816.OFFSET_LC]&0xFF) </tt>. Notice the<tt> &0xFF </tt> is a must above 127 bytes.
Or their is a mechanism of extracting the DATA_ARRAY array itself?No.
In fact, in the interest of performance and portability in environments with little memory, the usual coding style is to pass<tt> buffer </tt>, an offset within that, and the length; rather than making an object, which would require a copy. Welcome to the real world of Java Card. -
Help with comparing string array with parameters
I've posted my code in full so hopefully everyone can see exactly what I have been doing.
Note - my code uses the observer/observable model. The method I am having the problem with the if statement is in the class HSBC.
Basically when the pin count reaches 4 (in the atm class) it sends the userid & pincode) over to the checkPinAndUserId(String pinCode, String userCode) method. Here the if statement should check the userid to see if the string parameter matches a string in the array. If it does it should check in the same position in the pin array to check the pin no is correct and then return true.
* @(#)BankAssignment.java 1.0 03/04/06
* This apllication l
package myprojects.bankassignment;
import java.awt.*; // import the component library
import java.awt.event.*; // import the evnet library
import javax.swing.*;
import java.util.*;
class Correct1v16 extends Frame // make a new application
public Correct1v16() // this is the constructor method
HSBC HSBCobj = new HSBC();
public static void main(String args[]) // this invokes the constructor of the class and creates a runable object 'mainframe'
Correct1v16 mainFrame = new Correct1v16(); // the constructor call of the class which creates an object of that class
class HSBC implements Observer, ActionListener
Frame f5;
JLabel refill, launch;
TextField tRefill, tLaunch;
JButton refillbut, launchbut;
int count;
String [] userId=new String [10];
String [] pin=new String [10];
public boolean authenticate = false;
int i;
public HSBC()
drawFrame();
Atm Atmobj = new Atm(this);
System.out.println("Starting HSBC constructor");
public void drawFrame()
System.out.println("Start HSBC drawframe method...");
f5=new Frame("HSBC");
f5.setLayout(new FlowLayout());
f5.setSize(200, 200);
f5.addWindowListener(new WindowAdapter()
public void windowClosing(WindowEvent e)
f5.dispose();
System.exit(0);
refill=new JLabel("Refill ATM");
launch=new JLabel("Launch new ATM");
tRefill=new TextField(20);
tLaunch=new TextField(10);
refillbut=new JButton("Refill ATM");
refillbut.addActionListener(this);
launchbut=new JButton("Launch new ATM");
launchbut.addActionListener(this);
f5.add(refill);
f5.add(tRefill);
f5.add(refillbut);
f5.add(launch);
f5.add(tLaunch);
f5.add(launchbut);
f5.setVisible(true);
//*********** POPULATE THE ARRAYS */
pin[0]="1234";
pin[1]="2345";
pin[2]="3456";
pin[3]="4567";
pin[4]="5678";
pin[5]="6789";
pin[6]="7890";
pin[7]="8901";
pin[8]="9012";
pin[9]="0123";
userId[0]="0";
userId[1]="1";
userId[2]="2";
userId[3]="3";
userId[4]="4";
userId[5]="5";
userId[6]="6";
userId[7]="7";
userId[8]="8";
userId[9]="9";
}// end drawframe method
// public Atm atmLink = (Atm)o;
public void update(Observable gm1, Object o)
Atm atmLink = (Atm)o;
tRefill.setText("Refill ATM ?");
atmLink.refill();
}//end update method
public void actionPerformed(ActionEvent ae)
if(ae.getSource() == refillbut)
// Atm Atmobj.refill();
// tRefill.setText("text area");
// atmLink.refill();
// Atmobj.refill();
// setChanged();
// notifyObservers();
if(ae.getSource() == launchbut)
tLaunch.setText("new ATM opened");
Atm Atmobj1 = new Atm(this);
//******** THIS METHOD RECEIVES THE PARAMETERS FROM THE ATM METHOD (LINE 580) (PINCODE AND USERCODE) BUT
//******** IT ONLY THE ARRAY CALLED USERID (WHICH HOLDS THE USER CODE MATCHES ONE OF THE USERID'S)
//******** I DO WANT IT TO DO THIS BUT I ALSO WANT IT TO MOVE ON AND CHECK THE PINCODE WITH THE PIN ARRAY)
//******** IF THEY ARE BOTH TRUE I WANT IT TO RETURN TRUE - ELSE FALSE. */
public boolean checkPinAndUserId(String userCode, String pinCode)
boolean found = false;
System.out.println("in checkpin method");
System.out.println("userCode = "+ userCode);
System.out.println("pinCode = " + pinCode);
for (int i = 0; i < userId.length; i++)
System.out.println("in the userid array" + userId);
if (userCode.equals(userId[i]))
System.out.println("checking user code array");
if (pinCode.equals(pin[i]))
System.out.println("checking the pin array" + pinCode);
System.out.println("pin[i] = "+pin[i]);
found = true;
return found;
}// end HSBC class
class Atm extends Observable implements ActionListener
Frame f1;
TextField t3, t5;
JTextArea display = new JTextArea("Welcome to HSBC Bank. \n Please enter your User Identification number \n", 5, 40);
JPanel p1, p2, p3,p4;
private JButton but1, but2, but3, but4,but5,but6,but7,but8,but9,but0,enter,
cancel,fivepounds,tenpounds,twentypounds,fiftypounds,clearbut, refillbut;
int state = 1;
public String pinCode ="";
public String userCode ="";
int userCodeCount = 0;
int PINCount = 0;
String withdrawAmount = "";
int atmBalance =200;
private HSBC HSBCobj;
//ATM constructor that receives the HSBCobj g1 reference to where the HSBC class
// in in the program
// Calls the drawATMFrame method
// add the observer to the HSBCobj reference so that the ATM can tell HSBC that
// something has changed
public Atm(HSBC g1)
HSBCobj = g1;
drawATMFrame();
System.out.println("Starting Atm constructor");
addObserver(HSBCobj);
// this is the method that draws the ATM interface
// also apply the Border Layout to the frame
public void drawATMFrame()
f1=new Frame("ATM");
f1.setLayout(new BorderLayout());
f1.setSize(350, 250);
f1.addWindowListener(new WindowAdapter()
public void windowClosing(WindowEvent e)
f1.dispose();
System.exit(0);
// declare & instantiate all the buttons that will be used on the ATM
but1 =new JButton("1");
but1.addActionListener(this);
but2 =new JButton("2");
but2.addActionListener(this);
but3 =new JButton("3");
but3.addActionListener(this);
but4 =new JButton("4");
but4.addActionListener(this);
but5 =new JButton("5");
but5.addActionListener(this);
but6 =new JButton("6");
but6.addActionListener(this);
but7 =new JButton("7");
but7.addActionListener(this);
but8 =new JButton("8");
but8.addActionListener(this);
but9 =new JButton("9");
but9.addActionListener(this);
but0 =new JButton("0");
but0.addActionListener(this);
enter=new JButton("Enter");
enter.addActionListener(this);
cancel=new JButton("Cancel/ \n Restart");
cancel.addActionListener(this);
fivepounds =new JButton("?5");
fivepounds.addActionListener(this);
tenpounds = new JButton("?10");
tenpounds.addActionListener(this);
twentypounds = new JButton("?20");
twentypounds.addActionListener(this);
fiftypounds = new JButton("?50");
fiftypounds.addActionListener(this);
clearbut = new JButton("Clear");
clearbut.addActionListener(this);
refillbut = new JButton("Refill");
refillbut.addActionListener(this);
//declare & instantiate a textfield
t3=new TextField(5);
// instantiate 4 JPanels
p1=new JPanel();
p2=new JPanel();
p3=new JPanel();
p4=new JPanel();
// add some buttons to p1
p1.add(but1);
p1.add(but2);
p1.add(but3);
p1.add(but4);
p1.add(but5);
p1.add(but6);
p1.add(but7);
p1.add(but8);
p1.add(but9);
p1.add(but0);
//add the text area field to p2
p2.add(display);
// apply the grid layout to p3
GridLayout layout3 = new GridLayout(4,1,5,5);
p3.setLayout(layout3);
p3.add(fivepounds);
p3.add(tenpounds);
p3.add(twentypounds);
p3.add(fiftypounds);
// apply grid layout to p4
GridLayout layout4 = new GridLayout(4,1,5, 5);
p4.setLayout(layout4);
p4.add(clearbut);
p4.add(enter);
p4.add(cancel);
p4.add(refillbut);
//add the panels to the different parts of the screen
f1.add("North", display);
f1.add("Center", p1);
f1.add("East", p4);
f1.add("West", p3);
f1.setVisible(true);
}// end drawATMframe method
public void actionPerformed(ActionEvent ae)
if(state == 1)
getUserIdNo(ae);
else if(state == 2)
doPINInput(ae);
else
withdrawCash(ae);
}// end action performed method
//******** STATE 1 events*/
//******** USER ID INPUT*/
public void getUserIdNo (ActionEvent ae)
if (ae.getSource() == but1)
display.append("*");
userCode = userCode + "1";
userCodeCount++;
if (ae.getSource() == but2)
display.append("*");
userCode = userCode + "2";
userCodeCount++;
if (ae.getSource() == but3)
display.append("*");
userCode = userCode + "3";
userCodeCount++;
System.out.println("user id ="+userCode);
if (ae.getSource() == but4)
display.append("*");
userCode = userCode = "4";
userCodeCount++;
System.out.println("user id ="+userCode);
if (ae.getSource() == but5)
display.append("*");
userCode = userCode + "5";
userCodeCount++;
System.out.println("user id ="+userCode);
if (ae.getSource() == but6)
display.append("*");
userCode = userCode + "6";
userCodeCount++;
System.out.println("user id ="+userCode);
if (ae.getSource() == but7)
display.append("*");
userCode = userCode + "7";
userCodeCount++;
System.out.println("user id ="+userCode);
if (ae.getSource() == but8)
display.append("*");
userCode = userCode + "8";
userCodeCount++;
System.out.println("user id ="+userCode);
if (ae.getSource() == but9)
display.append("*");
userCode = userCode + "9";
userCodeCount++;
System.out.println("user id ="+userCode);
if (ae.getSource() == but0)
display.append("*");
userCode = userCode + "0";
userCodeCount++;
System.out.println("user id ="+userCode);
if (ae.getSource() == cancel)
display.setText("Welcome to HSBC Bank.\n Please enter your User Identification number \n");
userCode = "";
state = 2;
if (ae.getSource() == clearbut)
display.setText("Please enter your user ID number again\n");
userCode = "";
userCodeCount = 0;
if (ae.getSource() == refillbut)
refill();
if (ae.getSource() == enter)
display.setText("Please enter your PIN \n");
state = 2;
System.out.println(" User id enter button = " + userCode);
if (userCodeCount == 1)
display.setText("Please enter your PIN \n");
//userCode = "";
userCodeCount = 0;
state = 2;
//******** STATE 2 */
//******** PIN INPUT*/
public void doPINInput(ActionEvent ae)
if (ae.getSource() == but1)
{ pinCode = pinCode.concat("1");
display.append("*");
PINCount++;
if (ae.getSource() == but2)
{ pinCode = pinCode.concat("2");
display.append("*");
PINCount++;
if (ae.getSource() == but3)
{ pinCode = pinCode.concat("3");
display.append("*");
PINCount++;
if (ae.getSource() == but4)
{ pinCode = pinCode.concat("4");
display.append("*");
PINCount++;
if (ae.getSource() == but5)
{ pinCode = pinCode.concat("5");
display.append("*");
PINCount++;
if (ae.getSource() == but6)
{ pinCode = pinCode.concat("6");
display.append("*");
PINCount++;
if (ae.getSource() == but7)
{ pinCode = pinCode.concat("7");
display.append("*");
PINCount++;
if (ae.getSource() == but8)
{ pinCode = pinCode.concat("8");
display.append("*");
PINCount++;
if (ae.getSource() == but9)
{ pinCode = pinCode.concat("9");
display.append("*");
PINCount++;
if (ae.getSource() == but0)
{ pinCode = pinCode.concat("0");
display.append("*");
PINCount++;
if (ae.getSource() == clearbut)
display.setText("Please enter your PIN number again \n");
pinCode = "";
PINCount = 0;
if (ae.getSource() == cancel)
display.setText("Welcome to HSBC Bank.\n Please enter your User Identification number \n");
state = 1;
pinCode ="";
PINCount = 0;
if (ae.getSource() == refillbut)
refill();
/// ************************ THIS BUTTON SENDS THE PIN & USER CODE OVER TO THE MAIN BANK*/
/// ************************ (LINE 152) */
if (ae.getSource() == enter)
// if(HSBCobj.checkPinAndUserId(pinCode, userCode))
// display.setText("How much would you like to withdraw \n");
// else
// display.setText("Your UserId and Pin code do not match");
if(PINCount ==4)
if(HSBCobj.checkPinAndUserId(userCode,pinCode))
display.setText("Enter the amount you \n want to withdraw \n ?");
PINCount=0;
else
display.setText("Your User Identification Number \n and PIN number do not match! \n please try again\n");
//*********** STATE 3 events*/
//*********** withdrawCash*/
public void withdrawCash(ActionEvent ae)
// if (ae.getSource() == but1)
// display.append("1");
/// withdrawAmount = withdrawAmount+1;
// pinCode = pinCode.concat("2");
// System.out.println("Withdrawal Amount = "+withdrawAmount);
if(ae.getSource( ) == but1)
withdrawAmount = withdrawAmount + "1";
display.setText(withdrawAmount);
if(ae.getSource( ) == but2)
withdrawAmount = withdrawAmount + "2";
display.setText(withdrawAmount);
if(ae.getSource( ) == but3)
withdrawAmount = withdrawAmount + "3";
display.setText(withdrawAmount);
if(ae.getSource( ) == but4)
withdrawAmount = withdrawAmount + "4";
display.setText(withdrawAmount);
if(ae.getSource( ) == but5)
withdrawAmount = withdrawAmount + "5";
display.setText(withdrawAmount);
if(ae.getSource( ) == but6)
withdrawAmount = withdrawAmount + "6";
display.setText(withdrawAmount);
if(ae.getSource( ) == but7)
withdrawAmount = withdrawAmount + "7";
display.setText(withdrawAmount);
if(ae.getSource( ) == but8)
withdrawAmount = withdrawAmount + "8";
display.setText(withdrawAmount);
if(ae.getSource( ) == but9)
withdrawAmount = withdrawAmount + "9";
display.setText(withdrawAmount);
if(ae.getSource( ) == but0)
withdrawAmount = withdrawAmount + "0";
display.setText(withdrawAmount);
if (ae.getSource() == fivepounds)
withdrawAmount = withdrawAmount + "5";
display.setText(withdrawAmount);
atmBalance();
if (ae.getSource() == tenpounds)
withdrawAmount = withdrawAmount + "10";
display.setText(withdrawAmount);
atmBalance();
if (ae.getSource() == twentypounds)
withdrawAmount = withdrawAmount + "20";
display.setText(withdrawAmount);
atmBalance();
if (ae.getSource() == fiftypounds)
withdrawAmount = withdrawAmount + "50";
display.setText(withdrawAmount);
atmBalance();
// if (ae.getSource() == tenpounds)
// display.append("10");
// withdrawAmount = 10;
// pinCode = pinCode.concat("2");
// System.out.println("10 pound button pressed");
// atmBalance();
if (ae.getSource() == enter)
atmBalance();
if (ae.getSource() == refillbut)
System.out.println("refill but pressed");
refill();
if (ae.getSource() == clearbut)
System.out.println("clear but pressed");
display.setText("Enter the amount you want to withdraw \n ?");
withdrawAmount="";
if (ae.getSource() == cancel)
display.setText("Welcome to HSBC Bank.\n Please enter your User Identification number \n");
withdrawAmount="";
pinCode ="";
PINCount = 0;
userCode = "";
userCodeCount = 0;
state = 1;
}// end withdraw cash input method
// checks balace of atm and withdraws cash. Also notifies onserver if atm balance is low
public void atmBalance()
String s = withdrawAmount;
int n = Integer.parseInt(s);
if ( atmBalance >= n)
atmBalance = atmBalance - n;
System.out.println("atm balance = "+ atmBalance);
display.setText("Thankyou for using HSBC. \nYou have withdrawn ?"+n);
if (atmBalance<40)
System.out.println("atm balance is less than 40 - notify HSBC" );
setChanged();
notifyObservers(this);
/// note the refil should send a message to the controller
// advising a refil is needed. The Bank will send an engineer
// out who will fill the atm up
}// end atmBalance method
/// note the refil should send a message to the controller
/// then th coontroller will send a message to this method to fill machine
/// (this is simulating a clerk filling atm)
public void refill()
System.out.println("in refill method" );
atmBalance = 200;
System.out.println("Atm has been refilled. Atm balance = " + atmBalance);
// setChanged();
// notifyObservers(this);
}// end refill method
// NOTE SURE ABOUT THIS - DO I USE THE UPDATE METHOD TO NOTIFY HSBC THAT ATM REQUIRES FILLING
// THIS IS THE WRONG PART OF THE PROGRAM (SHOULD BE IN HSBC) - IGNORE
public void update(Observable gm1, Object gameObj)
display.setText("Congratulations");
}//end update method
}// end Atm method
}// end Assignment2 clas
[\code]I wasn't trying to annoy anyone at all.
I'm new to java and have been told that using the observer/observable model is not considered basic java. So that is the only reason I posted it in this section. At the same time i feel that the bit I'm struggling with is actually basic - hence posting it in the basic section. I'm not sure if people of all abilities check all forums or just the ones they feel at at their standard.
So appologies if you've taken offence. -
Help with DIgital Output Array with 6062E DAQ CARD...
Good morning, folks... I need some help with digital output of the 6062E PCMCIA card... I can output 1 line without problems... I need to control a 4066 with my digital outputs... I am doing this without greater problems... but there's something... I need that when one of my outputs is high, the others become low, unchangeably... so I tried to use an array to control my output and I couldn't do that... some errors showed up... can you help me please? Maybe there's any errors at my software, then I thank you if you help me... the vi is anexed...
Best Regards...
Attachments:
Untitled 3.vi 20 KBSee below for one of many methods. Change the "lines" string for your setup.
Also, please explore the Examples that ship with LabVIEW, and read your card's manual.
Richard
Maybe you are looking for
-
Calling Sql*Loader from oracle Form builder
How do i call sql* loader from my forms to import the external data in different formats into my existing database? Specify the flexibility of sql* loader to import external data from .txt files or .xls files. Would be thankful if certain examples ar
-
NAT on Multilayer Switch 3560 and 3750
Hi , Wish you happy new year all.. I tried configure NAT over 3560 Switch, unfortunately NAT is not supported. Is possible configure NAT on 3750? Maybe I can change my 3560 by one 3750, but I need NAT feature. Please help on this.. Thanks in advance!
-
Photoshop Elements 7 neu PDF Miniaturen
Plötzlich bekomme ich beim Öffnen eines Dokuments oder Bildes durch Emails ein zweites Fenster PDF Importieren mit Miniaturen. Wenn ich sie vergrössern will, kommen sie als weiss/graues Schachbrett und das in der letzten Zeit immer, dazwischen kommt
-
Battery not working !!!! Need help !!!!!
I have a Macbook Pro- 2GHZ with 2 GB of Ram, from week 11. Yesterday , I downloaded all the updates and now my MBP works only when connected to an a A/C source. It tells me that is full charged and Coconut battery: 74% battery capacity 99% charged 8
-
Hi, Is there any way to control the test run order by priority ? Without using ordered tests file. I am using CodedUI tests with VS2012 and MTM 2012. The tests are triggered from a build definition using the LabDefaultTemplate.11.xaml where the test