I am using chronicle-queue (5.16.13) to write and read json values to a chronicle file.
To write objects I use the following in a loop
try (final DocumentContext dc = appender.writingDocument()) {
dc.wire().write(() -> "msg").text("Hallo asdf");
System.out.println("your data was store to index="+ dc.index());
return true;
} catch (Exception e) {
logger.warn("Unable to store value to chronicle", e);
return false;
}
and to read items I do the following call in a loop
DocumentContext documentContext;
do {
documentContext = tailer.readingDocument();
currentOffset = documentContext.index();
System.out.println("Current offset: " + currentOffset);
} while (!documentContext.isData());
What I observe is that the variable currentOffsetdoes not change and after some time (depending on the payload size, it seems) the loop goes infinite and the current offset has crazy values.
The output (shortened) for the first loop is
Writing 0
your data was store to index=76385993359360
Writing 1
your data was store to index=76385993359361
Writing 2
your data was store to index=76385993359362
Writing 3
your data was store to index=76385993359363
Writing 4
your data was store to index=76385993359364
Writing 5
your data was store to index=76385993359365
Writing 6
your data was store to index=76385993359366
Writing 7
your data was store to index=76385993359367
Writing 8
your data was store to index=76385993359368
Writing 9
your data was store to index=76385993359369
Writing 10
your data was store to index=76385993359370
Writing 11
your data was store to index=76385993359371
Writing 12
your data was store to index=76385993359372
Writing 13
your data was store to index=76385993359373
Writing 14
your data was store to index=76385993359374
Writing 15
your data was store to index=76385993359375
Writing 16
your data was store to index=76385993359376
Writing 17
your data was store to index=76385993359377
Writing 18
your data was store to index=76385993359378
Writing 19
your data was store to index=76385993359379
Writing 20
your data was store to index=76385993359380
Writing 21
your data was store to index=76385993359381
Writing 22
your data was store to index=76385993359382
Writing 23
your data was store to index=76385993359383
Writing 24
your data was store to index=76385993359384
Writing 25
your data was store to index=76385993359385
Writing 26
your data was store to index=76385993359386
And for the second loop
Reading 0
Current offset: 76385993359360
Reading 1
Current offset: 76385993359360
Reading 2
Current offset: 76385993359360
Reading 3
Current offset: 76385993359360
Reading 4
Current offset: 76385993359360
Reading 5
Current offset: 76385993359360
Reading 6
Current offset: 76385993359360
Reading 7
Current offset: 76385993359360
Reading 8
Current offset: 76385993359360
Reading 9
Current offset: 76385993359360
Reading 10
Current offset: 76385993359360
Reading 11
Current offset: 76385993359360
Reading 12
Current offset: 76385993359360
Reading 13
Current offset: 76385993359360
Reading 14
Current offset: 76385993359360
Reading 15
Current offset: 76385993359360
Reading 16
Current offset: 76385993359360
Reading 17
Current offset: 76385993359360
Reading 18
Current offset: 76385993359360
Reading 19
Current offset: 76385993359360
Reading 20
Current offset: 76385993359360
Reading 21
Current offset: 76385993359360
Reading 22
Current offset: 76385993359360
Reading 23
Current offset: 76385993359360
Reading 24
Current offset: 76385993359360
Reading 25
Current offset: -9223372036854775808
Am I doing something completely wrong?
Can then anyobody hint me to the correct usage?
Thanks a lot!
Edit: Added minimal working example
The following unit test fails for me.
#Test
public void fails() throws Exception {
String basePath = System.getProperty("java.io.tmpdir");
String path = Files.createTempDirectory(Paths.get(basePath), "chronicle-")
.toAbsolutePath()
.toString();
logger.info("Using temp path '{}'", path);
SingleChronicleQueue chronicleQueue = SingleChronicleQueueBuilder
.single()
.path(path)
.build();
// Create Appender
ExcerptAppender appender = chronicleQueue.acquireAppender();
// Create Tailer
ExcerptTailer tailer = chronicleQueue.createTailer();
tailer.toStart();
int numberOfRecords = 10;
// Write
for (int i = 0; i <= numberOfRecords; i++) {
System.out.println("Writing " + i);
try (final DocumentContext dc = appender.writingDocument()) {
dc.wire().write(() -> "msg").text("Hello World!");
System.out.println("your data was store to index=" + dc.index());
} catch (Exception e) {
logger.warn("Unable to store value to chronicle", e);
}
}
// Read
for (int i = 0; i <= numberOfRecords; i++) {
System.out.println("Reading " + i);
DocumentContext documentContext = tailer.readingDocument();
long currentOffset = documentContext.index();
System.out.println("Current offset: " + currentOffset);
Wire wire = documentContext.wire();
if (wire != null) {
String msg = wire
.read("msg")
.text();
}
}
chronicleQueue.close();
}
Output is
Writing 0
your data was store to index=76385993359360
Writing 1
your data was store to index=76385993359361
Writing 2
your data was store to index=76385993359362
Writing 3
your data was store to index=76385993359363
Writing 4
your data was store to index=76385993359364
Writing 5
your data was store to index=76385993359365
Writing 6
your data was store to index=76385993359366
Writing 7
your data was store to index=76385993359367
Writing 8
your data was store to index=76385993359368
Writing 9
your data was store to index=76385993359369
Writing 10
your data was store to index=76385993359370
Reading 0
Current offset: 76385993359360
Reading 1
Current offset: 76385993359360
Reading 2
Current offset: 76385993359360
Reading 3
Current offset: 76385993359360
Reading 4
Current offset: -9223372036854775808
Reading 5
Current offset: -9223372036854775808
Reading 6
Current offset: -9223372036854775808
Reading 7
Current offset: -9223372036854775808
Reading 8
Current offset: -9223372036854775808
Reading 9
Current offset: -9223372036854775808
Reading 10
Current offset: -9223372036854775808
Using DocumentContext is intended to be one of the lower level interfaces and not to everyone's taste. I favour using the MethodReader/MethodWriter approach unless you have a reason to work at the lower level.
#Test
public void works() {
String path = OS.TMP + "/chronicle-" + System.nanoTime();
System.out.println("Using temp path " + path);
try (SingleChronicleQueue queue = SingleChronicleQueueBuilder
.single()
.path(path)
.build()) {
ExcerptAppender appender = queue.acquireAppender();
Messager messager = appender.methodWriter(Messager.class);
int numberOfRecords = 10;
// Write
for (int i = 0; i <= numberOfRecords; i++) {
System.out.print("Writing " + i);
messager.msg("Hello World!");
System.out.println(", your data was stored at index=" + appender.lastIndexAppended());
}
ExcerptTailer tailer = queue.createTailer();
MethodReader reader = tailer.methodReader((Messager) msg -> {
System.out.println("Current offset: " + tailer.index()
+ " msg: " + msg);
});
// Read
while (reader.readOne()) {
// busy wait.
}
}
}
This prints
Using temp path C:\Users\peter\AppData\Local\Temp\/chronicle-412979753710181
[main] DEBUG net.openhft.chronicle.bytes.MappedFile - Allocation of 0 chunk in C:\Users\peter\AppData\Local\Temp\chronicle-412979753710181\metadata.cq4t took 15.418 ms.
[main] DEBUG net.openhft.chronicle.bytes.MappedFile - Allocation of 0 chunk in C:\Users\peter\AppData\Local\Temp\chronicle-412979753710181\20181226.cq4 took 25.061 ms.
Writing 0, your data was stored at index=76841259892736
Writing 1, your data was stored at index=76841259892737
Writing 2, your data was stored at index=76841259892738
Writing 3, your data was stored at index=76841259892739
Writing 4, your data was stored at index=76841259892740
Writing 5, your data was stored at index=76841259892741
Writing 6, your data was stored at index=76841259892742
Writing 7, your data was stored at index=76841259892743
Writing 8, your data was stored at index=76841259892744
Writing 9, your data was stored at index=76841259892745
Writing 10, your data was stored at index=76841259892746
Current offset: 76841259892736 msg: Hello World!
Current offset: 76841259892737 msg: Hello World!
Current offset: 76841259892738 msg: Hello World!
Current offset: 76841259892739 msg: Hello World!
Current offset: 76841259892740 msg: Hello World!
Current offset: 76841259892741 msg: Hello World!
Current offset: 76841259892742 msg: Hello World!
Current offset: 76841259892743 msg: Hello World!
Current offset: 76841259892744 msg: Hello World!
Current offset: 76841259892745 msg: Hello World!
Current offset: 76841259892746 msg: Hello World!
[main] DEBUG net.openhft.chronicle.queue.impl.single.SingleChronicleQueueBuilder - File released C:\Users\peter\AppData\Local\Temp\chronicle-412979753710181\20181226.cq4
[main] DEBUG net.openhft.chronicle.queue.impl.single.SingleChronicleQueueBuilder - File released C:\Users\peter\AppData\Local\Temp\chronicle-412979753710181\20181226.cq4
NOTE: This writes the same data as the original post.
An advantage of using this interface approach is that you can implement your business component entirely using interfaces of methods with DTOs and not use Chronicle (or at transport) at all. This simplifies testing business logic as you remove the transport from the tests.
I found the answer myself using the Suggestion from #PeterLawrey and wrapping the Document Context in try-with-resources. This solves the issue.
See the corrected snippet below
#Test
public void works() throws Exception {
String basePath = System.getProperty("java.io.tmpdir");
String path = Files.createTempDirectory(Paths.get(basePath), "chronicle-")
.toAbsolutePath()
.toString();
logger.info("Using temp path '{}'", path);
SingleChronicleQueue chronicleQueue = SingleChronicleQueueBuilder
.single()
.path(path)
.build();
// Create Appender
ExcerptAppender appender = chronicleQueue.acquireAppender();
// Create Tailer
ExcerptTailer tailer = chronicleQueue.createTailer();
tailer.toStart();
int numberOfRecords = 10;
// Write
for (int i = 0; i <= numberOfRecords; i++) {
System.out.println("Writing " + i);
try (final DocumentContext dc = appender.writingDocument()) {
dc.wire().write(() -> "msg").text("Hello World!");
System.out.println("your data was store to index=" + dc.index());
} catch (Exception e) {
logger.warn("Unable to store value to chronicle", e);
}
}
// Read
for (int i = 0; i <= numberOfRecords; i++) {
System.out.println("Reading " + i);
try (DocumentContext documentContext = tailer.readingDocument()) {
long currentOffset = documentContext.index();
System.out.println("Current offset: " + currentOffset);
Wire wire = documentContext.wire();
if (wire != null) {
String msg = wire
.read("msg")
.text();
}
}
}
chronicleQueue.close();
}
which produces the expected output
Writing 0
your data was store to index=76385993359360
Writing 1
your data was store to index=76385993359361
Writing 2
your data was store to index=76385993359362
Writing 3
your data was store to index=76385993359363
Writing 4
your data was store to index=76385993359364
Writing 5
your data was store to index=76385993359365
Writing 6
your data was store to index=76385993359366
Writing 7
your data was store to index=76385993359367
Writing 8
your data was store to index=76385993359368
Writing 9
your data was store to index=76385993359369
Writing 10
your data was store to index=76385993359370
Reading 0
Current offset: 76385993359360
Reading 1
Current offset: 76385993359361
Reading 2
Current offset: 76385993359362
Reading 3
Current offset: 76385993359363
Reading 4
Current offset: 76385993359364
Reading 5
Current offset: 76385993359365
Reading 6
Current offset: 76385993359366
Reading 7
Current offset: 76385993359367
Reading 8
Current offset: 76385993359368
Reading 9
Current offset: 76385993359369
Reading 10
Current offset: 76385993359370
Hope this helps someone else.
Related
I am trying to develop and application to read and write to RF tags. Reading is flawless, but I'm having issues with writing. Specifically the error "GetStatus Write RFID_API_UNKNOWN_ERROR data(x)- Field can Only Take Word values"
I have tried reverse-engineering the Zebra RFID API Mobile by obtaining the .apk and decoding it, but the code is obfuscated and I am not able to decypher why that application's Write works and mine doesn't.
I see the error in the https://www.ptsmobile.com/rfd8500/rfd8500-rfid-developer-guide.pdf at page 185, but I have no idea what's causing it.
I've tried forcefully changing the writeData to Hex, before I realized that the API does that on its own, I've tried changing the Length of the writeData as well, but it just gets a null value. I'm so lost.
public boolean WriteTag(String sourceEPC, long Password, MEMORY_BANK memory_bank, String targetData, int offset) {
Log.d(TAG, "WriteTag " + targetData);
try {
TagData tagData = null;
String tagId = sourceEPC;
TagAccess tagAccess = new TagAccess();
tagAccess.getClass();
TagAccess.WriteAccessParams writeAccessParams = tagAccess.new WriteAccessParams();
String writeData = targetData; //write data in string
writeAccessParams.setAccessPassword(Password);
writeAccessParams.setMemoryBank(MEMORY_BANK.MEMORY_BANK_USER);
writeAccessParams.setOffset(offset); // start writing from word offset 0
writeAccessParams.setWriteData(writeData);
// set retries in case of partial write happens
writeAccessParams.setWriteRetries(3);
// data length in words
System.out.println("length: " + writeData.length()/4);
System.out.println("length: " + writeData.length());
writeAccessParams.setWriteDataLength(writeData.length()/4);
// 5th parameter bPrefilter flag is true which means API will apply pre filter internally
// 6th parameter should be true in case of changing EPC ID it self i.e. source and target both is EPC
boolean useTIDfilter = memory_bank == MEMORY_BANK.MEMORY_BANK_EPC;
reader.Actions.TagAccess.writeWait(tagId, writeAccessParams, null, tagData, true, useTIDfilter);
} catch (InvalidUsageException e) {
System.out.println("INVALID USAGE EXCEPTION: " + e.getInfo());
e.printStackTrace();
return false;
} catch (OperationFailureException e) {
//System.out.println("OPERATION FAILURE EXCEPTION");
System.out.println("OPERATION FAILURE EXCEPTION: " + e.getResults().toString());
e.printStackTrace();
return false;
}
return true;
}
With
Password being 00
sourceEPC being the Tag ID obtained after reading
Memory Bank being MEMORY_BANK.MEMORY_BANK_USER
target data being "8426017056458"
offset being 0
It just keeps giving me "GetStatus Write RFID_API_UNKNOWN_ERROR data(x)- Field can Only Take Word values" and I have no idea why this is the case, nor I know what a "Word value" is, and i've searched for it. This is all under the "OperationFailureException", as well. Any help would be appreciated, as there's almost no resources online for this kind of thing.
Even this question is a bit older, I had the same problem so as far as I know this should be the answer.
Your target data "8426017056458" length is 13 and at writeAccessParams.setWriteDataLength(writeData.length()/4)
you are devide it with four. Now if you are trying to write the target data it is longer than the determined WriteDataLength. And this throws the Error.
One 'word' is 4 Hex => 16 Bits long. So your Data have to be filled up first and convert it to Hex.
I am using batch processing to write into InfluxDB and below is my code for doing that.
String dbName = "test";
influxDB.query(new Query("CREATE DATABASE " + dbName, dbName));
Stopwatch watch = Stopwatch.createStarted();
influxDB.enableBatch(2000, 100, TimeUnit.MILLISECONDS);
for (int j = 0; j < 100000; j++) {
Point point = Point.measurement("cpu")
.addField("idle", (double) j)
.addField("system", 3.0 * j).build();
influxDB.write(dbName, "autogen", point);
}
influxDB.disableBatch();
System.out.println("Write for " + 100000 + " Points took:" + watch);
}
Here i am writing 100000 points and which is taking very reasonable time to write, however only few records are written into DB instead of expected 100000 records.
select count(idle) from cpu gives me only "89" i am expecting it to be "100000"
While select * from cpu gives me following:
cpu
time idle system
2016-10-06T23:57:41.184Z 8 24
2016-10-06T23:57:41.185Z 196 588
2016-10-06T23:57:41.186Z 436 1308
2016-10-06T23:57:41.187Z 660 1980
2016-10-06T23:57:41.188Z 916 2748
2016-10-06T23:57:41.189Z 1278 3834
2016-10-06T23:57:41.19Z 1405 4215
2016-10-06T23:57:41.191Z 1409 4227
2016-10-06T23:57:41.192Z 1802 5406
2016-10-06T23:57:41.193Z 1999 5997
2016-10-06T23:57:41.456Z 3757 11271
2016-10-06T23:57:41.457Z 3999 11997
2016-10-06T23:57:41.858Z 4826 14478 and so on.....
Here my question is why the values of idle are missing, for example, after 8 it should 9, 10, 11, and so on but these values were not persisted and comes directly 196 and then missing in between and then 436. Any idea how to persist all value of loop variable "j" in this situation?
This line
influxDB.enableBatch(2000, 100, TimeUnit.MILLISECONDS);
says that it will flush input data if there are more than 2000 samples per 100 ms period. Since you are trying to write 100k samples then logically most of them get flushed.
Instead, write less samples in a single batch. My recommendation would be to write 5000 samples in a single batch, and make multiple batches until all your data is in the db.
// Batch 1
influxDB.enableBatch(5000, 100, TimeUnit.MILLISECONDS);
for (int j = 0; j < 5000; j++) {
Point point = Point.measurement("cpu")
.addField("idle", (double) j)
.addField("system", 3.0 * j).build();
influxDB.write(dbName, "autogen", point);
}
influxDB.disableBatch();
// Batch 2
// ...
I am trying to insert csv file in postgresql database using java
the code is
CopyManager copyManager = new CopyManager((BaseConnection) conn);
FileReader fileReader = new FileReader(filename);
copyManager.copyIn("COPY meta.fk_payment_temp(\n"+
"settlement_ref_no, order_type, fulfilment_type, seller_sku, wsn, \n" +
" order_id, order_item_id, order_date, dispatch_date, delivery_date, \n" +
" cancellation_date, settlement_date, order_status, quantity, order_item_value, \n" +
" refund, protection_fund, total_marketplace_fee, service_tax, \n" +
" settlement_value, commission_rate, commission, fee_discount, \n" +
" cancellation_fee, fixed_fee, emi_fee, total_weight, shipping_fee, \n" +
" reverse_shipping_fee, shipping_zone, token_of_apology, pick_and_pack_fee, \n" +
" storage_fee, removal_fee, invoice_id, invoice_date, invoice_amount, \n" +
" sub_category, total_offer_amount, my_offer_share, flipkart_offer_share)\n" +
" FROM STDIN with csv header delimiter ','", fileReader );
there is 41 column in csv file and as well as in table
the error detail is:
Where: COPY fk_payment_temp, line 2:
"NFT-150331087GN00107XXXXXXX,prepaid,NON-FA,BD46-157,,OD102411813209536003,166288248,"Mar
25, 2015","..."
as we seen error is in "Mar 25, 2015" but the data is
NFT-150331087GN00107XXXXXXX prepaid NON-FA BD46-157 OD102411813209536003 166288248 25-Mar-15 26-Mar-15 27-Mar-15 31-Mar-15 delivered 1 339 339 0 0 -85.26 -10.54 243.2 15 -50.86 0 0 -5 0 0.3 -29.4 0 LOCAL 0 0 0 0 IN27248 26-Mar-15 309 babydoll 0 0 0
how i can solve this ?
My experience is that this is almost always caused by malformed csv data. There really is no substitute for knowing the format, how to review material for proper escaping, etc. And CSV is not simple. There are lots of rules regarding things like embedded end of line characters and the like.
A good place to start (if you hadn't already found your answer) would be running the data through a spreadsheet and see what seems to end up on the wrong columns.
When I have a PDF formatted like so (abbreviated)
"JVBERi0xLjQKJf////8KMzIgMCBvYmoKPDwvTGVuZ3RoIDI0ODIKL1N1YnR5cGUgL1hNTAovVHlwZSAvTWV0YWRhdGEKPj4Kc3RyZWFtCjw/eHBhY2tldCBiZWdpbj0n77u/JyBpZD0nVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkJz8+Cjx4OnhtcG1ldGEgeDp4bXB0az0iMy4xLTcwMSIgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iPgogIDxyZGY6UkRGIHhtbG5zOnJkZj0iaHR0cDovL3d3dy53My5vcmcvMTk5OS8wMi8yMi1yZGYtc3ludGF4LW5zIyI+CiAgICA8cmRmOkRlc2NyaXB0aW9uIHJkZjphYm91dD0iIiB4bWxuczp4bXA9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC8iPgogICAgICA8eG1wOkNyZWF0ZURhdGU+MjAxMi0wOS0yNlQxNzoxOTo0OVo8L3htcDpDcmVhdGVEYXRlPgogICAgICA8eG1wOkNyZWF0b3JUb29sPk5pdHJvIFJlYWRlciAyICAoMi4gNS4gMC4gNDApPC94bXA6Q3JlYXRvclRvb2w+CiAgICAgIDx4bXA6TW9kaWZ5RGF0ZT4yMDEyLTA5LTI2VDE3OjE5OjQ5WjwveG1wOk1vZGlmeURhdGU+CiAgICAgIDx4bXA6TWV0YWRhdGFEYXRlPjIwMTItMDktMjZUMTc6MTk6NDlaPC94bXA6TWV0YWRhdGFEYXRlPgogICAgPC9yZGY6RGVzY3JpcHRpb24+CiAg
I am able to write it to the sd card with this code, and then open it.
File file = new File(eqnxPath.getAbsolutePath(), FileId + FileName);
Log.d(TAG, "looking for file...");
if (file.exists())
{
Log.d(TAG, "fiel exists, returning file");
return file;
}
else
{
Log.d(TAG, "file does not exist, making file");
byte[] pdfAsBytes = Base64.decode(this.FileContent, Base64.DEFAULT);
try
{
FileOutputStream os = new FileOutputStream(file);
try
{
os.write(pdfAsBytes);
os.flush();
os.close();
Log.d(TAG, "returning file");
return file;
} catch (IOException e)
{
Log.d(TAG, "IOException...");
e.printStackTrace();
}
} catch (FileNotFoundException e)
{
Log.d(TAG, "FileNotFoundException...");
e.printStackTrace();
}
However when I get a pdf that looks like this (again abbreviated)
%PDF-1.3
%����
1 0 obj
<undefined</Metadata 35 0 R/Pages 2 0 R/Type/Catalog>>
endobj
2 0 obj
<</MediaBox[0.0 0.0 609.12 788.88]/Count 1/Type/Pages/Kids[4 0 R]>>
endobj
4 0 obj
<undefined</Parent 2 0 R/Contents 29 0 R/PieceInfo<undefined</MRC<undefined</Private<undefined</B[1 1 3 1]/I[3 8 300 300]/P[2 0.45]/Q 0.1/S[2 0]/U 0/Y 15/b 20/v 2.31>>/LastModified(D:20121102151622-06'00')>>/PSL<undefined</Private<undefined</V(3.1.902)>>/LastModified(D:20121102211626-00'00')>>>>/MediaBox[0 0.0 609.12 788.88]/Resources<undefined</XObject<</4 28 0 R/5 27 0 R/6 26 0 R/7 23 0 R/8 22 0 R/9 21 0 R/A 20 0 R/B 19 0 R/C 18 0 R/D 17 0 R/E 16 0 R/F 15 0 R/G 14 0 R/H 13 0 R/I 12 0 R/J 11 0 R/K 10 0 R/L 9 0 R/M 8 0 R/N 7 0 R/O 6 0 R/P 5 0 R>>/ProcSet[/PDF/ImageC/ImageI/ImageB]>>/Type/Page/LastModified(D:20121102151622-06'00')>>
endobj
5 0 obj
<undefined</Subtype/Image/Length 20602/Filter/CCITTFaxDecode/ImageMask true/BitsPerComponent 1/Width 2320/DecodeParms<undefined</K -1/Columns 2320>>/Height 2960/Type/XObject>>stream
����KH�r�f(A�:FD���;!�(CǕ��:!������v�p���������������?w�A�?I<��
#� b��r�P�����������O��̓�Gcb��ɘ�("El%A�#���r��S����3����h� �� �Ȑc"#�.�0DE��2PA�.(A�a�8k�)%���L��#A�c'd�Ȑh*f� `�M �(�f�C6���� ��xN��� �0 xA��� `�A�h�2�&�y�TA�x'A��zp����4L a��� 駬?OO�S�������xA���~��N,'��AƐN-;���i����[�[OD~�Zo��q�"2-��*v��[���m�q�!֓rM�'��g8rC�1�`�����%�G� :!r��"�4fB� G��h�)2c&�tpO��O ��W��GSAA���:�O!�ɧ�`��5��n#�'���zM�ap���_�&�I�J �n��L8OA�����&�=W ��xN���H=7 �=7
�!xV��n����n�]7���I�n��.�����&�[���O[���z�Kn~���_�������I�����V��������Z�������������������������"A����������
���ܫ��������������e��� a������/����H3?���������_�ߐq������������ �7�������O�����/��/�!�E���������"�u���������� D���� ���肋��������� ������� ������U����D����Ai��������������_�����\6i������ݿ�K����V�/� c������_���m���0K���"�zo��������c���������������_�������������_���]��������k����_�~�����������������������D������������w��k�������]���������o�J������E����/ۯ����
�_�Z�BA/��^�Jյ���KJ��/���k��[�յm+Xui��������i{a[K�:lڤ�IZ���Z�����k%
v�
��^�0}���$}��cRCRCH�4�l+iCY
m/�a~
)6� L�� ޖ%�lW��3��ȑ�+ �m)�Hb�a/�?��b�67د
5�?�*����**(1_��5��^�[�2
/����5U_쁈�S[�
.�^ �����P��/��A���
B
n������/�va�Bk
���/�
E�����a4"9���"+�
0� �"�&���Xk�aa��`�!� ���2�=��j� ��A��� ����l��e�A������SǨ�����/�_�������:���������
���a!VSZ��������!*�H7龓��W��̓�
��"Ő1��)%
#�;D��)9!� #AAld �`�>�P�u�"D�
9|�rundefined<azv�z�0����zi����za;���L'�קj�A��OT�7^-�'���4�M��\�� G���v�c�<�P��O �o���I�t��M� ������ �zN�y�0�>�:]=����2�5�:O�Ӿ��ivAA?[�ut���S��7a�^���^���P�N����n��Upa�_X�����
���_ޗ�<����Zo��o�[��U�e�X�����_��7��D�]m������#ٷ��_\��������������/u����������������SP+��������#ڧ���������������{��_����^��]�;���^����h�������W����������������د�n����������i[_��]�ڵ�[]�
����K��J�J����m-���յ��]�xk��J�X/�����1V����0�����V!�����_�h5
o�����P�/��O����P����_R�13��RBL���G"Cn�l���K���d���}kV������eP�����Z��� _�e�*Bl� 0ed�3;Z`��9i*��5%����d�iw�z���u����$�~4�߅��o�Q���������ܧ2H.x�X�џ)��Ρ�p�8S�4g'� 0hGS'�<� �=B`�;��u=< �4�?M4� �S��^�ń���M>/�N���ӽPh�v��� ��#�t�܉�Dt!9���O��"��#�����=$��龃A�n�#�7M�o����I=>��t��U:N����T���}7��[WT�+������ .�_�C�=>��=p����������6c6zVf�ޥ�mB� ��?����D^�j��G������������?������-�_������W������$�$c��L� �ד�����FGJFG���鷷��o���u���u��u_^�/����_��}-���ki}�w�u.���Z�v�����Z�]�~��mv�V��Nڶ��k�Z���I��&����L5`�]�}�`˃�lSTW��LS�HM�����
��ڦ�� �i����a���
a��k�����4���+a�A�^��ӴװX0D�&A�M!iq��D�"#������Sz�~�_j�#���������������s\�
٪3��B��)_Q���-Of��^��������?���������_�������_�%����̔����}��EW���TY�~.�5�q�������������������l����:���#��ddj��\φ%�(RFvjɺ� �Oe;j��Yrundefined<W4���j�ddP3S7�`�DNN!K�����0��H!���j�i����!�:3XR��Ä �0���Au�M���M=>&��MQ>!H�\�At�O��8w
{��Z�
$�%N����7�����6r�7�����u��ץ�5�o#��y tO�6 M6��s1�� ���D��v�".9�k&�O*'�d�e�_�0��t�J��U����Fe'ۗ6�ӧk߄����q�+��i����.�w��_�xA��:�}��&��q��oҽ/�Y��!�ҿ_�?�_��1�����M�?�/�ӏ}�_~�_���T����==iid�������W���7�WO�������������_�o����:�����R�_���!����Azվ���z�ȉ�W���Z�]b����W����o���-k�d?�_������~���M����p�_�$��uMR�&-��)����.��o�.�Ip��������$�����������k_��/y/�W���#�~��M�+�,�7��^��5�� �"_ҧ�����qqZ�ﭨ5#��g�{��|A�Σ���J�/�I/��zm'�un�}��������II�)�����_�t�Hw��}���%_�W���K�'�������
�u|^���'�+��/�v�ߧ聟���9�~�Z���w��Z�/�K�\?��^����}-t����ץ��u���v6֟��������]h/^�ƕ{���]��^�R��mwUV�R�Y�%�yѯ�����ۮ�Z���N����}p�5�]+K����U�����y�vҤ
*�����&��I1\���:!���f�0�|V�/��I5���[ˋ�`��SH��a%�b!�
�Ay����aWZU�`�rG�����A��+��E!q��
/����-��X`�0��\�V��E'���[�_��I?���-yᅿ�_�0[�L,4�Imt��zB"8��������0�
;P���)�,��lE�f4�qZ��^��MUZhDb?����j|��"�\���TY*jFǟ�"!D�b���!.�Fdv��*�NdX!6(�����
0����Y�A���gSDԇ��Û�V�A�x �ja��=5��T���C�����ih4�a=4Ӫ����D��|��[�Ӈpk�wڧ��:Dp��O(��¥c�?֗OY(|�Q�r;�` �������t6��M���K0�����'ϒƲ��'��"%ԏ��(+��n�+������u���
��A�e֛�oKH_��۽������OW��������[_���RYC��kh����I�o&�G�ѪZ����w~�-��?���U/���������i/��W߮��[_�����������|$��.��խ������JA6������^D �ҥ����A��J��*���O���5���~�������o�[�T����m/��_����]r �����R���I%����/��lz/M�����0�����W���\��Pa���O��^G��6��%�����z��a�u���U�D0�9��
���Ҧ�K�p�έ����[����Z��?�3������߂��<��XJ�����Km/�����:�#��I~�R�I�]���^���#������ץ���/����ޕ����A'^�.�/�k~��Z �k��դ��-źJ���~�v����k��AWK�������֯�_��^��U�0�Natˉ��%�ܘ�3�V��0_����y��xk��!���d��)#�undefined<BJ-��1QE��(����A��`�QR�H���jCG
4E�i�װ�
}K1(>�1\;�*��������8[�k
��n�[ }�%�
�h��7]���Xk�i�ͅ�+�DG�CB
�pf�����E��d*c��4z�I*���J��P�!��
My method does not work. How would I write this type of .pdf to the sd card? I dont even know what type of data I am looking at...
A PDF "formatted" like in your first example is base64 encoded (an encoding used to transport binary data via a channel that can only handle text properly).
Before writing to card, therefore, it has to be decoded which your method does by means of a ' Base64.decode' call.
A PDF "formatted" like in your second example is already in its unencoded state. Thus, no further decoding is necessary and the data has to be written to card as is.
I hope your member variable ' this.FileContent' is not a string but a byte array, or that its byte array representation is present in yet another member. Otherwise the second, unencoded form surely already is broken.
For this kind of data your method shall not call the base64 decode method before saving but instead save the data as is.
I run a small online gaming community and deal with a database of accounts.
The setup is this:
Folder named Accounts
Inside the Accounts directory, there is 200,000+ text files organized by player name. Access to this folder manually is a pain because of the needed RAM to get in and search files. I find this very inconvenient.
I access this directory to send password reminders or for highscores on who has been playing the longest.
Here is an example of an account file. This file is named Falcon.txt
[ACCOUNT]
character-username = Falcon
character-password = falconpassword
[INFO]
character-coordx = 3252
character-coordy = 3432
character-active = yes
character-ismember = 1
character-messages = 5
character-lastconnection = [removed]
character-lastlogin = 2009-11-29
character-energy = 100
character-gametime = 193
character-gamecount = 183
[EQUIPMENT]
character-equip = 0 4724 0
character-equip = 1 1052 0
character-equip = 2 6585 0
character-equip = 3 4151 0
character-equip = 4 4720 0
character-equip = 5 1215 0
character-equip = 6 -1 0
character-equip = 7 4722 0
character-equip = 8 -1 0
character-equip = 9 775 0
character-equip = 10 1837 0
character-equip = 11 -1 0
character-equip = 12 6735 0
character-equip = 13 -1 0
[APPEARANCE]
character-look = 0 1
character-look = 1 1
character-look = 2 2
character-look = 3 3
character-look = 4 5
character-look = 5 2
[STATS]
character-skill = 0 1 0
character-skill = 1 1 0
character-skill = 2 1 0
character-skill = 3 1 0
character-skill = 4 1 0
character-skill = 5 1 0
character-skill = 6 1 0
character-skill = 7 1 0
character-skill = 8 1 0
character-skill = 9 1 0
character-skill = 10 1 0
character-skill = 11 1 0
character-skill = 12 1 0
character-skill = 13 1 0
character-skill = 14 1 0
character-skill = 15 1 0
character-skill = 16 1 0
character-skill = 17 1 0
character-skill = 18 1 0
character-skill = 19 1 0
character-skill = 20 1 0
[ITEMS]
[BANK]
[FRIENDS]
[IGNORES]
[END]
There is a huge database of these and search through the directory in the files for values.
Values I mean by item ID's or IP addresses to find and track other accounts.
However I have a new problem and my development for this is crashing.
As you can see in the file the lines are organized by tabs.
character-equip = 0 4724 1
If I put the value 4724 in my search application, I want it to print out the value 1 tab to the right of the found search result. I want it to print out the value for the found results only, not extra results.
So the search could look like this:
1 "Enter item to find:"
2 "Enter item to find: 4724"
3 "Account Falcon.txt has 1!"
press any key to continue...
Or if there was more quantity of that equipped item
character-equip = 5 1239 102
1. "Enter item to find:"
2. "Enter item to find: 1239"
3. "Account Falcon2.txt has 102!"
press any key to continue...
I simply want to input an item ID, and have it display the value after the found value. The white space is a tab. I have tried doing this and the only successful way of getting any result is to put a tab in between the search term. So if I want to find item 1239 id type this in the cmd line:
Enter item to find:<tab>1239<tab>
It would then search for that and will display the accounts with that item in it. However I still have to individually open up the accounts to find out the quantity of that item. I want the search results to display the quantity of the item if the value is found. However if the value is a quantity and it trys to search one tab over, I want it to either skip it or say zero.
This is what I mean.
character-equip = 0 1024 1239
Enter item to find: 1239
If it hits this account I want to make the search results display a zero if it cannot tab over or view any values in the white space. So it will display as null or zero
Account Falcon3.txt has null!
or
Account Falcon3.txt has 0!
I've attempted to do this but I am unsure how to achieve this.
Here is my code.
import java.io.*;
import java.util.*;
public class ItemDatabase {
public static void main(String args[]) {
System.out.print("Enter item to find: ");
Scanner sc = new Scanner(System.in);
find(sc.nextLine());
}
public static void find(String delim) {
File dir = new File("accounts");
if (dir.exists()) {
String read;
try {
File files[] = dir.listFiles();
for (int i = 0; i < files.length; i++) {
File loaded = files[i];
if (loaded.getName().endsWith(".txt")) {
BufferedReader in = new BufferedReader(new FileReader(loaded));
StringBuffer load = new StringBuffer();
while ((read = in.readLine()) != null) {
load.append(read + "\n");
}
String delimiter[] = new String(load).split(delim);
if(delimiter.length > 1) {
System.out.println("Account " + loaded.getName() + "has " + delimiter[1] + "!");
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
} else {
System.out.println("error: dir wasn't found!");
}
}
}
Thanks guys I hope you can help me.
This is simply crying out for a database. If your entire back end is running in a single java process I'd recommend going with something like Apache Derby or H2.
If you'd rather not move to a database, and the main problem is the act of listing all the entries in a single directory, could you split it into a heirarchy. Your Falcon account could then be located in F/FA/Falcon.txt - each directory would then contain a more manageable number of files.
Aside from the need for a database, you could probably implement your solution more intuitively and easily using commandline utilities such as find, grep, etc. or a text-processing language such as perl.
Maybe
grep '[0-9]+\t[0-9]+\t1239' Account_Falcon3.txt
Would return
character-equip = 0 1024 1239
You could then easily see that the value is 0 for that item.
I cannot emphasize enough the need to not write a Java program to do this - you won't do as good a job as the authors of the standard shell utilities. Let's face it, the fact that you are asking this question indicates that you are a newb! :) (We are all newbs depending on the topic).