How to replicate Ruby´s binary file reading with Java?


 
Thread Tools Search this Thread
Top Forums Programming How to replicate Ruby´s binary file reading with Java?
# 8  
Old 11-21-2014
Quote:
Originally Posted by shamrock
The C language doesn't have the regular expressions that Perl uses but it has its own built-in regular expressions the same as sed and awk so look up the man page of regexec / regcomp etc...
Hi shamrock,

Thanks for answer.

Yes, I've tried regex of C but are not powerfull enough. The regex I'm using are a kind of complex and use backreference, greedy, non-greedy options, etc. The C regexs does'nt support these kind of things from what I know.

Basically I'd like to process each chunk at a time from binary using as delimiter 0xFF65, but it seems java doesn't have the option to change the line separator when read a binary, similarly as I did with ruby in sample code I show in first post.

I'm not sure, maybe someone knows an alternative or a 3rd party library that could read binary and set a custom separator.

Regards
# 9  
Old 11-21-2014
How about using java's "next" method with a regex as argument to read the entire input string up to the delimiter 0xff65...
# 10  
Old 11-21-2014
Quote:
Originally Posted by shamrock
How about using java's "next" method with a regex as argument to read the entire input string up to the delimiter 0xff65...
Hi shamrock,

I found this method "java.util.Scanner.next()" but this scanner only works with text files.

do you have a reference of the next() method you say to see examples?

Thanks again
# 11  
Old 11-21-2014
Hi.
Quote:
Originally Posted by Ophiuchus
... I'm afraid I cannot use C for this task since I thinks it doesn't has support for Perl regular expressions fashion, I'm not sure ...
I think I have used this indirectly PCRE - Perl Compatible Regular Expressions

Best wishes ... cheers, drl
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Solaris

Reading binary content

Dear Gurus I am stuck with the peice of work and do not know from where to start. I get a machine generated file which is binary file contain binary data, i want to read binary data as it is without converting into any other format. i want to read byte by byte. Please let me know what... (24 Replies)
Discussion started by: guddu_12
24 Replies

2. Programming

help with reading a binary file and fseek

this is my code and no matter what record number the user enters i cant get any of the records fields to read into the structure acct. What am i doing wrong? #include <stdio.h> typedef struct { char name; int number; float balance; } acct_info_t; int main (int... (0 Replies)
Discussion started by: bjhum33
0 Replies

3. Programming

reading binary files

#include <stdio.h> /* typedef struct { char name; int number; float balance; } acct_info_t; */ int main() { FILE *fptr; fptr = fopen("acct_info", "r"); int magic = 5; fseek(fptr,3,SEEK_SET); fread(&magic,sizeof(int),1,fptr);... (7 Replies)
Discussion started by: robin_simple
7 Replies

4. Shell Programming and Scripting

Running remote system shell script and c binary file from windows machine using java

Hi, I have an shell script program in a remote linux machine which will do some specific monitoring functionality. Also, have some C executables in that machine. From a windows machine, I want to run the shell script program (If possible using java). I tried with SSH for this. but, in... (1 Reply)
Discussion started by: ram.sj
1 Replies

5. Shell Programming and Scripting

reading fixed length flat file and calling java code using shell scripting

I am new to shell scripting and I have to to the following I have a flat file with storename(lenth 20) , emailaddress(lenth 40), location(15). There is NO delimiters in that file. Like the following str00001.txt StoreName emailaddress location... (3 Replies)
Discussion started by: willywilly
3 Replies

6. Programming

Reading a binary file in text or ASCII format

Hi All, Please suggest me how to read a binary file in text or ASCII format. thanks Nagendra (3 Replies)
Discussion started by: Nagendra
3 Replies

7. Shell Programming and Scripting

Reading Numerical Binary Data using KSH

Hi, I've searched and couldn't find anyone else with this problem. Is there anyway (preferably using ksh - but other script languages would do) that I can read in binary float data into a text file. The data (arrays from various stages of radar processing) comes in various formats, but mainly... (3 Replies)
Discussion started by: Jonny2Vests
3 Replies

8. Programming

Binary not getting executed from Java on Solaris environment

In the Java programme, I am calling function, "Runtime.getRuntime().exec( cmdarray ); " with the array of arguments in which first argument is the binary(C-executable) file and argv1,argv2 and so on. This will be executed on Sun OS system.. I can execute using "sh -c cmdarray" on the shell... (0 Replies)
Discussion started by: shafi2all
0 Replies

9. Programming

Reading from a binary file

I'm having trouble with reading information back into a program from a binary file. when i try to display the contents of the file i get a Memory fault(coredump). would anyone be able to assist? this is my fread line fread(&file_data,sizeof(struct book_type),1,fileSave); ive also tried it without... (3 Replies)
Discussion started by: primal
3 Replies
Login or Register to Ask a Question