This repository was archived by the owner on Mar 31, 2026. It is now read-only.
forked from ib-ruby/ib-ruby
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathEReader.java
More file actions
817 lines (731 loc) · 30.3 KB
/
Copy pathEReader.java
File metadata and controls
817 lines (731 loc) · 30.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
/*
* EReader.java
*
*/
package com.ib.client;
import java.io.DataInputStream;
import java.io.IOException;
public class EReader extends Thread {
// incoming msg id's
static final int TICK_PRICE = 1;
static final int TICK_SIZE = 2;
static final int ORDER_STATUS = 3;
static final int ERR_MSG = 4;
static final int OPEN_ORDER = 5;
static final int ACCT_VALUE = 6;
static final int PORTFOLIO_VALUE = 7;
static final int ACCT_UPDATE_TIME = 8;
static final int NEXT_VALID_ID = 9;
static final int CONTRACT_DATA = 10;
static final int EXECUTION_DATA = 11;
static final int MARKET_DEPTH = 12;
static final int MARKET_DEPTH_L2 = 13;
static final int NEWS_BULLETINS = 14;
static final int MANAGED_ACCTS = 15;
static final int RECEIVE_FA = 16;
static final int HISTORICAL_DATA = 17;
static final int BOND_CONTRACT_DATA = 18;
static final int SCANNER_PARAMETERS = 19;
static final int SCANNER_DATA = 20;
static final int TICK_OPTION_COMPUTATION = 21;
static final int TICK_GENERIC = 45;
static final int TICK_STRING = 46;
static final int TICK_EFP = 47;
static final int CURRENT_TIME = 49;
static final int REAL_TIME_BARS = 50;
static final int FUNDAMENTAL_DATA = 51;
static final int CONTRACT_DATA_END = 52;
private EClientSocket m_parent;
private DataInputStream m_dis;
protected EClientSocket parent() { return m_parent; }
private EWrapper eWrapper() { return (EWrapper)parent().wrapper(); }
public EReader( EClientSocket parent, DataInputStream dis) {
this("EReader", parent, dis);
}
protected EReader( String name, EClientSocket parent, DataInputStream dis) {
setName( name);
m_parent = parent;
m_dis = dis;
}
public void run() {
try {
// loop until thread is terminated
while( !isInterrupted() && processMsg(readInt()));
}
catch ( Exception ex ) {
parent().wrapper().error( ex);
//parent().wrapper().connectionClosed();
// closed connection would be reported anyway by the line below
}
m_parent.close();
}
/** Overridden in subclass. */
protected boolean processMsg(int msgId) throws IOException{
if( msgId == -1) return false;
switch( msgId) {
case TICK_PRICE: {
int version = readInt();
int tickerId = readInt();
int tickType = readInt();
double price = readDouble();
int size = 0;
if( version >= 2) {
size = readInt();
}
int canAutoExecute = 0;
if (version >= 3) {
canAutoExecute = readInt();
}
eWrapper().tickPrice( tickerId, tickType, price, canAutoExecute);
if( version >= 2) {
int sizeTickType = -1 ; // not a tick
switch (tickType) {
case 1: // BID
sizeTickType = 0 ; // BID_SIZE
break ;
case 2: // ASK
sizeTickType = 3 ; // ASK_SIZE
break ;
case 4: // LAST
sizeTickType = 5 ; // LAST_SIZE
break ;
}
if (sizeTickType != -1) {
eWrapper().tickSize( tickerId, sizeTickType, size);
}
}
break;
}
case TICK_SIZE: {
int version = readInt();
int tickerId = readInt();
int tickType = readInt();
int size = readInt();
eWrapper().tickSize( tickerId, tickType, size);
break;
}
case TICK_OPTION_COMPUTATION: {
int version = readInt();
int tickerId = readInt();
int tickType = readInt();
double impliedVol = readDouble();
if (impliedVol < 0) { // -1 is the "not yet computed" indicator
impliedVol = Double.MAX_VALUE;
}
double delta = readDouble();
if (Math.abs(delta) > 1) { // -2 is the "not yet computed" indicator
delta = Double.MAX_VALUE;
}
double modelPrice, pvDividend;
if (tickType == TickType.MODEL_OPTION) { // introduced in version == 5
modelPrice = readDouble();
pvDividend = readDouble();
} else {
modelPrice = pvDividend = Double.MAX_VALUE;
}
eWrapper().tickOptionComputation( tickerId, tickType, impliedVol, delta, modelPrice, pvDividend);
break;
}
case TICK_GENERIC: {
int version = readInt();
int tickerId = readInt();
int tickType = readInt();
double value = readDouble();
eWrapper().tickGeneric( tickerId, tickType, value);
break;
}
case TICK_STRING: {
int version = readInt();
int tickerId = readInt();
int tickType = readInt();
String value = readStr();
eWrapper().tickString( tickerId, tickType, value);
break;
}
case TICK_EFP: {
int version = readInt();
int tickerId = readInt();
int tickType = readInt();
double basisPoints = readDouble();
String formattedBasisPoints = readStr();
double impliedFuturesPrice = readDouble();
int holdDays = readInt();
String futureExpiry = readStr();
double dividendImpact = readDouble();
double dividendsToExpiry = readDouble();
eWrapper().tickEFP( tickerId, tickType, basisPoints, formattedBasisPoints,
impliedFuturesPrice, holdDays, futureExpiry, dividendImpact, dividendsToExpiry);
break;
}
case ORDER_STATUS: {
int version = readInt();
int id = readInt();
String status = readStr();
int filled = readInt();
int remaining = readInt();
double avgFillPrice = readDouble();
int permId = 0;
if( version >= 2) {
permId = readInt();
}
int parentId = 0;
if( version >= 3) {
parentId = readInt();
}
double lastFillPrice = 0;
if( version >= 4) {
lastFillPrice = readDouble();
}
int clientId = 0;
if( version >= 5) {
clientId = readInt();
}
String whyHeld = null;
if( version >= 6) {
whyHeld = readStr();
}
eWrapper().orderStatus( id, status, filled, remaining, avgFillPrice,
permId, parentId, lastFillPrice, clientId, whyHeld);
break;
}
case ACCT_VALUE: {
int version = readInt();
String key = readStr();
String val = readStr();
String cur = readStr();
String accountName = null ;
if( version >= 2) {
accountName = readStr();
}
eWrapper().updateAccountValue(key, val, cur, accountName);
break;
}
case PORTFOLIO_VALUE: {
int version = readInt();
Contract contract = new Contract();
if (version >= 6) {
contract.m_conId = readInt();
}
contract.m_symbol = readStr();
contract.m_secType = readStr();
contract.m_expiry = readStr();
contract.m_strike = readDouble();
contract.m_right = readStr();
if (version >= 7) {
contract.m_multiplier = readStr();
contract.m_primaryExch = readStr();
}
contract.m_currency = readStr();
if ( version >= 2 ) {
contract.m_localSymbol = readStr();
}
int position = readInt();
double marketPrice = readDouble();
double marketValue = readDouble();
double averageCost = 0.0;
double unrealizedPNL = 0.0;
double realizedPNL = 0.0;
if (version >=3 ) {
averageCost = readDouble();
unrealizedPNL = readDouble();
realizedPNL = readDouble();
}
String accountName = null ;
if( version >= 4) {
accountName = readStr();
}
if(version == 6 && m_parent.serverVersion() == 39) {
contract.m_primaryExch = readStr();
}
eWrapper().updatePortfolio(contract, position, marketPrice, marketValue,
averageCost, unrealizedPNL, realizedPNL, accountName);
break;
}
case ACCT_UPDATE_TIME: {
int version = readInt();
String timeStamp = readStr();
eWrapper().updateAccountTime(timeStamp);
break;
}
case ERR_MSG: {
int version = readInt();
if(version < 2) {
String msg = readStr();
m_parent.error( msg);
} else {
int id = readInt();
int errorCode = readInt();
String errorMsg = readStr();
m_parent.error(id, errorCode, errorMsg);
}
break;
}
case OPEN_ORDER: {
// read version
int version = readInt();
// read order id
Order order = new Order();
order.m_orderId = readInt();
// read contract fields
Contract contract = new Contract();
if (version >= 17) {
contract.m_conId = readInt();
}
contract.m_symbol = readStr();
contract.m_secType = readStr();
contract.m_expiry = readStr();
contract.m_strike = readDouble();
contract.m_right = readStr();
contract.m_exchange = readStr();
contract.m_currency = readStr();
if ( version >= 2 ) {
contract.m_localSymbol = readStr();
}
// read order fields
order.m_action = readStr();
order.m_totalQuantity = readInt();
order.m_orderType = readStr();
order.m_lmtPrice = readDouble();
order.m_auxPrice = readDouble();
order.m_tif = readStr();
order.m_ocaGroup = readStr();
order.m_account = readStr();
order.m_openClose = readStr();
order.m_origin = readInt();
order.m_orderRef = readStr();
if(version >= 3) {
order.m_clientId = readInt();
}
if( version >= 4 ) {
order.m_permId = readInt();
if ( version < 18) {
// will never happen
/* order.m_ignoreRth = */ readBoolFromInt();
}
else {
order.m_outsideRth = readBoolFromInt();
}
order.m_hidden = readInt() == 1;
order.m_discretionaryAmt = readDouble();
}
if ( version >= 5 ) {
order.m_goodAfterTime = readStr();
}
if ( version >= 6 ) {
// skip deprecated sharesAllocation field
readStr();
}
if ( version >= 7 ) {
order.m_faGroup = readStr();
order.m_faMethod = readStr();
order.m_faPercentage = readStr();
order.m_faProfile = readStr();
}
if ( version >= 8 ) {
order.m_goodTillDate = readStr();
}
if ( version >= 9) {
order.m_rule80A = readStr();
order.m_percentOffset = readDouble();
order.m_settlingFirm = readStr();
order.m_shortSaleSlot = readInt();
order.m_designatedLocation = readStr();
order.m_auctionStrategy = readInt();
order.m_startingPrice = readDouble();
order.m_stockRefPrice = readDouble();
order.m_delta = readDouble();
order.m_stockRangeLower = readDouble();
order.m_stockRangeUpper = readDouble();
order.m_displaySize = readInt();
if ( version < 18) {
// will never happen
/* order.m_rthOnly = */ readBoolFromInt();
}
order.m_blockOrder = readBoolFromInt();
order.m_sweepToFill = readBoolFromInt();
order.m_allOrNone = readBoolFromInt();
order.m_minQty = readInt();
order.m_ocaType = readInt();
order.m_eTradeOnly = readBoolFromInt();
order.m_firmQuoteOnly = readBoolFromInt();
order.m_nbboPriceCap = readDouble();
}
if ( version >= 10) {
order.m_parentId = readInt();
order.m_triggerMethod = readInt();
}
if (version >= 11) {
order.m_volatility = readDouble();
order.m_volatilityType = readInt();
if (version == 11) {
int receivedInt = readInt();
order.m_deltaNeutralOrderType = ( (receivedInt == 0) ? "NONE" : "MKT" );
} else { // version 12 and up
order.m_deltaNeutralOrderType = readStr();
order.m_deltaNeutralAuxPrice = readDouble();
}
order.m_continuousUpdate = readInt();
if (m_parent.serverVersion() == 26) {
order.m_stockRangeLower = readDouble();
order.m_stockRangeUpper = readDouble();
}
order.m_referencePriceType = readInt();
}
if (version >= 13) {
order.m_trailStopPrice = readDouble();
}
if (version >= 14) {
order.m_basisPoints = readDouble();
order.m_basisPointsType = readInt();
contract.m_comboLegsDescrip = readStr();
}
if (version >= 15) {
if (version >= 20) {
order.m_scaleInitLevelSize = readIntMax();
order.m_scaleSubsLevelSize = readIntMax();
}
else {
/* int notSuppScaleNumComponents = */ readIntMax();
order.m_scaleInitLevelSize = readIntMax();
}
order.m_scalePriceIncrement = readDoubleMax();
}
if (version >= 19) {
order.m_clearingAccount = readStr();
order.m_clearingIntent = readStr();
}
if (version >= 20) {
if (readBoolFromInt()) {
UnderComp underComp = new UnderComp();
underComp.m_conId = readInt();
underComp.m_delta = readDouble();
underComp.m_price = readDouble();
contract.m_underComp = underComp;
}
}
OrderState orderState = new OrderState();
if (version >= 16) {
order.m_whatIf = readBoolFromInt();
orderState.m_status = readStr();
orderState.m_initMargin = readStr();
orderState.m_maintMargin = readStr();
orderState.m_equityWithLoan = readStr();
orderState.m_commission = readDoubleMax();
orderState.m_minCommission = readDoubleMax();
orderState.m_maxCommission = readDoubleMax();
orderState.m_commissionCurrency = readStr();
orderState.m_warningText = readStr();
}
eWrapper().openOrder( order.m_orderId, contract, order, orderState);
break;
}
case NEXT_VALID_ID: {
int version = readInt();
int orderId = readInt();
eWrapper().nextValidId( orderId);
break;
}
case SCANNER_DATA: {
ContractDetails contract = new ContractDetails();
int version = readInt();
int tickerId = readInt();
int numberOfElements = readInt();
for (int ctr=0; ctr < numberOfElements; ctr++) {
int rank = readInt();
if (version >= 3) {
contract.m_summary.m_conId = readInt();
}
contract.m_summary.m_symbol = readStr();
contract.m_summary.m_secType = readStr();
contract.m_summary.m_expiry = readStr();
contract.m_summary.m_strike = readDouble();
contract.m_summary.m_right = readStr();
contract.m_summary.m_exchange = readStr();
contract.m_summary.m_currency = readStr();
contract.m_summary.m_localSymbol = readStr();
contract.m_marketName = readStr();
contract.m_tradingClass = readStr();
String distance = readStr();
String benchmark = readStr();
String projection = readStr();
String legsStr = null;
if (version >= 2) {
legsStr = readStr();
}
eWrapper().scannerData(tickerId, rank, contract, distance,
benchmark, projection, legsStr);
}
eWrapper().scannerDataEnd(tickerId);
break;
}
case CONTRACT_DATA: {
int version = readInt();
int reqId = -1;
if (version >= 3) {
reqId = readInt();
}
ContractDetails contract = new ContractDetails();
contract.m_summary.m_symbol = readStr();
contract.m_summary.m_secType = readStr();
contract.m_summary.m_expiry = readStr();
contract.m_summary.m_strike = readDouble();
contract.m_summary.m_right = readStr();
contract.m_summary.m_exchange = readStr();
contract.m_summary.m_currency = readStr();
contract.m_summary.m_localSymbol = readStr();
contract.m_marketName = readStr();
contract.m_tradingClass = readStr();
contract.m_summary.m_conId = readInt();
contract.m_minTick = readDouble();
contract.m_summary.m_multiplier = readStr();
contract.m_orderTypes = readStr();
contract.m_validExchanges = readStr();
if (version >= 2) {
contract.m_priceMagnifier = readInt();
}
eWrapper().contractDetails( reqId, contract);
break;
}
case BOND_CONTRACT_DATA: {
int version = readInt();
int reqId = -1;
if (version >= 3) {
reqId = readInt();
}
ContractDetails contract = new ContractDetails();
contract.m_summary.m_symbol = readStr();
contract.m_summary.m_secType = readStr();
contract.m_cusip = readStr();
contract.m_coupon = readDouble();
contract.m_maturity = readStr();
contract.m_issueDate = readStr();
contract.m_ratings = readStr();
contract.m_bondType = readStr();
contract.m_couponType = readStr();
contract.m_convertible = readBoolFromInt();
contract.m_callable = readBoolFromInt();
contract.m_putable = readBoolFromInt();
contract.m_descAppend = readStr();
contract.m_summary.m_exchange = readStr();
contract.m_summary.m_currency = readStr();
contract.m_marketName = readStr();
contract.m_tradingClass = readStr();
contract.m_summary.m_conId = readInt();
contract.m_minTick = readDouble();
contract.m_orderTypes = readStr();
contract.m_validExchanges = readStr();
if (version >= 2) {
contract.m_nextOptionDate = readStr();
contract.m_nextOptionType = readStr();
contract.m_nextOptionPartial = readBoolFromInt();
contract.m_notes = readStr();
}
eWrapper().bondContractDetails( reqId, contract);
break;
}
case EXECUTION_DATA: {
int version = readInt();
int orderId = readInt();
// read contract fields
Contract contract = new Contract();
if (version >= 5) {
contract.m_conId = readInt();
}
contract.m_symbol = readStr();
contract.m_secType = readStr();
contract.m_expiry = readStr();
contract.m_strike = readDouble();
contract.m_right = readStr();
contract.m_exchange = readStr();
contract.m_currency = readStr();
contract.m_localSymbol = readStr();
Execution exec = new Execution();
exec.m_orderId = orderId;
exec.m_execId = readStr();
exec.m_time = readStr();
exec.m_acctNumber = readStr();
exec.m_exchange = readStr();
exec.m_side = readStr();
exec.m_shares = readInt();
exec.m_price = readDouble();
if ( version >= 2 ) {
exec.m_permId = readInt();
}
if ( version >= 3) {
exec.m_clientId = readInt();
}
if ( version >= 4) {
exec.m_liquidation = readInt();
}
if (version >= 6) {
exec.m_cumQty = readInt();
exec.m_avgPrice = readDouble();
}
eWrapper().execDetails( orderId, contract, exec);
break;
}
case MARKET_DEPTH: {
int version = readInt();
int id = readInt();
int position = readInt();
int operation = readInt();
int side = readInt();
double price = readDouble();
int size = readInt();
eWrapper().updateMktDepth(id, position, operation,
side, price, size);
break;
}
case MARKET_DEPTH_L2: {
int version = readInt();
int id = readInt();
int position = readInt();
String marketMaker = readStr();
int operation = readInt();
int side = readInt();
double price = readDouble();
int size = readInt();
eWrapper().updateMktDepthL2(id, position, marketMaker,
operation, side, price, size);
break;
}
case NEWS_BULLETINS: {
int version = readInt();
int newsMsgId = readInt();
int newsMsgType = readInt();
String newsMessage = readStr();
String originatingExch = readStr();
eWrapper().updateNewsBulletin( newsMsgId, newsMsgType, newsMessage, originatingExch);
break;
}
case MANAGED_ACCTS: {
int version = readInt();
String accountsList = readStr();
eWrapper().managedAccounts( accountsList);
break;
}
case RECEIVE_FA: {
int version = readInt();
int faDataType = readInt();
String xml = readStr();
eWrapper().receiveFA(faDataType, xml);
break;
}
case HISTORICAL_DATA: {
int version = readInt();
int reqId = readInt();
String startDateStr;
String endDateStr;
String completedIndicator = "finished";
if (version >= 2) {
startDateStr = readStr();
endDateStr = readStr();
completedIndicator += "-" + startDateStr + "-" + endDateStr;
}
int itemCount = readInt();
for (int ctr = 0; ctr < itemCount; ctr++) {
String date = readStr();
double open = readDouble();
double high = readDouble();
double low = readDouble();
double close = readDouble();
int volume = readInt();
double WAP = readDouble();
String hasGaps = readStr();
int barCount = -1;
if (version >= 3) {
barCount = readInt();
}
eWrapper().historicalData(reqId, date, open, high, low,
close, volume, barCount, WAP,
Boolean.valueOf(hasGaps).booleanValue());
}
// send end of dataset marker
eWrapper().historicalData(reqId, completedIndicator, -1, -1, -1, -1, -1, -1, -1, false);
break;
}
case SCANNER_PARAMETERS: {
int version = readInt();
String xml = readStr();
eWrapper().scannerParameters(xml);
break;
}
case CURRENT_TIME: {
/*int version =*/ readInt();
long time = readLong();
eWrapper().currentTime(time);
break;
}
case REAL_TIME_BARS: {
/*int version =*/ readInt();
int reqId = readInt();
long time = readLong();
double open = readDouble();
double high = readDouble();
double low = readDouble();
double close = readDouble();
long volume = readLong();
double wap = readDouble();
int count = readInt();
eWrapper().realtimeBar(reqId, time, open, high, low, close, volume, wap, count);
break;
}
case FUNDAMENTAL_DATA: {
/*int version =*/ readInt();
int reqId = readInt();
String data = readStr();
eWrapper().fundamentalData(reqId, data);
break;
}
case CONTRACT_DATA_END: {
/*int version =*/ readInt();
int reqId = readInt();
eWrapper().contractDetailsEnd(reqId);
break;
}
default: {
m_parent.error( EClientErrors.NO_VALID_ID, EClientErrors.UNKNOWN_ID.code(), EClientErrors.UNKNOWN_ID.msg());
return false;
}
}
return true;
}
protected String readStr() throws IOException {
StringBuffer buf = new StringBuffer();
while( true) {
byte c = m_dis.readByte();
if( c == 0) {
break;
}
buf.append( (char)c);
}
String str = buf.toString();
return str.length() == 0 ? null : str;
}
boolean readBoolFromInt() throws IOException {
String str = readStr();
return str == null ? false : (Integer.parseInt( str) != 0);
}
protected int readInt() throws IOException {
String str = readStr();
return str == null ? 0 : Integer.parseInt( str);
}
protected int readIntMax() throws IOException {
String str = readStr();
return (str == null || str.length() == 0) ? Integer.MAX_VALUE
: Integer.parseInt( str);
}
protected long readLong() throws IOException {
String str = readStr();
return str == null ? 0l : Long.parseLong(str);
}
protected double readDouble() throws IOException {
String str = readStr();
return str == null ? 0 : Double.parseDouble( str);
}
protected double readDoubleMax() throws IOException {
String str = readStr();
return (str == null || str.length() == 0) ? Double.MAX_VALUE
: Double.parseDouble( str);
}
}