Some files I can't read and write to my socket!?

I have the following code that writes files to my socket:
OutputStream out = new BufferedOutputStream(socket.getOutputStream());
File f = new File(SOME_PATH);
InputStream fin = new FileInputStream(f);
int n;
while((n = fin.read()) > 0) {
  out.write(n);
out.flush();
fin.close();And the following reads this file from the socket, and writes it to another file on the server:
InputStream in = new BufferedInputStream(socket.getInputStream());
File f = new File(SOME_PATH);
OutputStream vos = new FileOutputStream(f);
int n;
for(int i=0;i<fileSize;i++) {
  n = in.read();
  vos.write(n);
vos.close();
vos = null;"fileSize" is always the size of the file, I'm pretty sure here.
I can transfer both binary and text files, but not all text files. Why is that? How do I fix it?

Another way is to have an object that represents the file...and then it can contain the filename and other stuff...
public class MyFile
   private String filename = "";
   private byte[] filecontents = null;
}If you then use an ObjectOutput/InputStream then you can read the file in wholesale...
However if you are having "other" commands that you read from the stream then it wouldn't solve that problem!
Another way is to use the ISDN method, more complex but effective, that is to have a control channel and a data channel...i.e. one stream for sending commands, another for sending data in response to commands...one issue there though is that of synchronization...
Another potential method is to use XML to provide a "data envelope" that encapsulates the file...
i.e.
<file filename="[name]">
<![CDATA[
   <!-- File contents go here, could be binary/plain text -->
]]>
</file>Of course using XML in this way has it's own problems...
Overall if you already have a working system in place then I'd stick with that, but those are some ideas!!!

Similar Messages

  • How can I read and write text in rings that are inside an array?

    Hello All!!!
    How can I read and write text in rings that are inside an array?
    Regards and thanks in advance.

    Use a Property Node linked to the Ring inside the array.
    Of course, all elements in the array will have the same text values.
    B-)
    Message Edited by LabViewGuruWannabe on 12-13-2007 09:47 AM
    Message Edited by LabViewGuruWannabe on 12-13-2007 09:48 AM
    Message Edited by LabViewGuruWannabe on 12-13-2007 09:49 AM
    Attachments:
    Strings-BD.PNG ‏17 KB
    Strings-FP1.PNG ‏23 KB

  • I have an excel file,i want to read and write this file to xml

    hello,
    i have an excel file,i want to read excel data and write to xml file .i also have an exisitng xml file and i want to appened the excel data to the exisiting xml.please give some example code.
    thanks

    GoOgLe

  • How can I read and write a Word document keeping the formatting properties

    Hi everybody,
    I am reading a word document and writting it into a XML document. I need to keep the text formatting. Which properties and how I
    can access them using HWPF POI?

    Note: I am already using HWPF POI with java to read the word document.

  • What Languages Can Tiger Read and Write?

    The tech specs for Tiger provide info on the languages for which Tiger is localized (i.e. to which its menus and dialogues can be switched), but nothing on the much longer list of languages for which fonts and keyboards are provided to enable reading and writing. These are:
    Arabic, Azeri, Armenian, Bulgarian, Byelorussian, Cherokee, Chinese (simplified and traditional), Croatian, Czech, Danish, Dari, Devanagari, Dutch, English, Estonian, Faroese, Finnish, French, German, Greek (regular and polytonic), Gujarati, Gurmurkhi (Punjabi), Hawaiian, Hebrew, Hungarian, Icelandic, Inuktitut, Irish, Italian, Japanese, Korean, Latvian, Lithuanian, Macedonian, Maori, Nepali, Northern Sami, Norwegian, Pashto, Persian, Polish, Portuguese, Romanian, Russian, Serbian, Slovak, Slovenian, Spanish, Swedish, Tamil, Thai, Turkish, Ukrainian, Uzbek, Vietnamese, and Welsh
    Additional languages can also be supported by downloading other fonts and keyboard layouts.

    You can read photos and videos on some flash drives (if they don't require too much power) and copy them to the Photos app, you can't copy other content or copy anything off the iPad.
    If your iPad has the new lightning connector then it's an iPad 4.

  • How can I read and write encrypted Mails with my iPhone?

    Thanks for any help.

    Hello;
    The only way for you to have your DAQ file is by using MAX and save the configuration to a file. In case you have the configuration beforehand, you don't even need to load MAX, you can pre-save the configuration file and copy it to the Window Registry location where the current file pointer is stored.
    Hope this helps.
    Filipe A.
    Applications Engineer
    National Instruments

  • How come a USB will work with both Mac and Windows (as in that there are already files from Windows and Mac can still read and write onto it) but a external Hard Drive won't (as in there are files from Windows on there but Mac can read but not write)?

    I have a Seagate Drive that I'm hoping to copy some movies from my Mac onto (because it only has a 512 SSD and I'd rather keep that empty and handy for more readily needed files) but it won't work. It shows up as a drive when connected (with the orange USB drive icon popping up) and is appropirately labeled "FreeAgent Drive", but when I try to copy files onto it it won't work. There are already windows files on there, such as some windows backups and lot's and lot's of pictures and videos. However, I have several USBs which already have windows files on them (namely movies, music, and other stuff) and copying and stuff works fine. Why won't it work with this hard drive and would work with USBs? Please help me out here guys, I am not experienced with Hard disks and formatting and stuff like that. 10 points for whoever helps me out the most. Thanks.

    We will need to reformat your EXT, but it will then work on both Mac and Win
    Connect the drive to your Mac, open disk utility
    Go to the partiton tab and select '1' ... format should be ExFAT ... in options select MBR
    Format the drive
    It should now work on both OSs; report back

  • Can I read and write a Word/excel document on an iMac ?

    Will an iMac replace my existing non apple computer?

    Yes.
    You have a number of options -
    A new Mac comes with iWork for free - this includes Pages (Word Processor), Numbers (Spreadsheet) and Keynote (Presentation software) which will import and export Word and Excel files.  You MAY have some issues with formatting and recent version of iWork is rather cut-down.
    If you want maximum compatibility with Word and Excel, there are Mac versions to buy as downloads from Microsoft.
    Finally, there are a couple of rather good free Office suites - Open Office and Libre Office are both well thought of and will handle Word and Excel files - you cansearch for these via Google.
    Hope this helps.

  • How can we read and write data into plist using javascript in a html5 widget to be implemented into iBooks?

    I had been trying to read from a plist to get file names of data files and it works fine when i run it in safari but after making its widget and putting it into iBooks it doesnot works. Please tell me any new method to read p list or correct my function if there is any correction. my function is following.
    function plistread(n)
              if (window.XMLHttpRequest)
                   xhttp = new XMLHttpRequest();
               else
            xhttp = new ActiveXObject("Microsoft.XMLHTTP");
                   xhttp.open("GET", "Spell_Check_3.plist", false);
        xhttp.send();
        xmlDoc = xhttp.responseXML;
        var x = xmlDoc.getElementsByTagName("dict");
        var imgnamex = x[n].getElementsByTagName("string")[0].childNodes[0].nodeValue;
        xlength=x.length;
              return imgnamex;

    See i need to access a plist file in my html5 widget, i implemented it in java script but it's not working so is there any other way to take out values from a plist file.

  • Read and write data from content repository .

    Hi All,
    We are using content repository to store some document and images on web center server .
    So we have created/setup a content repository on web center .
    Please proivde me some documnet /wiki page to get some idea how can i read and write date in
    content repository .
    You are most welocme to provide some idea /suggestion .
    Thanks,
    Arun.

    Have you already configured webcenter spaces so it can use content server?
    Have you installed the content server seperatly from webcenter or as a part of the webcenter installation?
    Check if you have the webcenter spaces component installed in content server because without i don't think it will work...
    If you already have configured UCM to work with spaces it's quiet easy.
    From your groupspace, open the settings page of your groupspace. Go to the services tab. In the left hand side you can enable the documents services. WHen you have done that, you are able to add the document services taskflows to your pages. Just go to a page in your pagegroup and edit it. Open the resource catalog and you will find some extra taskflows you can add.
    If you haven't configured UCM and webcenter to work together, here some steps that will help you:
    * Integrating UCM with Spaces
         * They both need to use the same LDAP store.
         * Since there is no LDAP server available, we choose for embedded WLS LDAP.
         * Integrating the ucm into apache
              * Stop UCM
              * In /oracle/product/wls10320/WebCenter/ucm/config/config.cfg, check the SocketHostAddressSecurityFilter to contain 127.0.0.1
              * Add the SocketHostAddressSecurityFilter to /oracle/product/wls10320/WebCenter/ucm/admin/bin/intradoc.cfg
              * Add to /oracle/product/wls10320/WebTier/instances/instance1/config/OHS/ohs1/httpd.conf
                   include /oracle/product/wls10320/WebCenter/ucm/data/users/apache22/apache.conf
              * Change the mod_wl_ohs.conf file to
                   <IfModule weblogic_module>
                         WebLogicHost localhost
                         WebLogicPort 7001
                         Debug ON
                         WLLogFile /tmp/weblogic.log
                   </IfModule>
                   <Location /webcenter>
                      SetHandler weblogic-handler
                      WebLogicCluster localhost:8888
                   </Location>
                   <Location /webcenterhelp>
                      SetHandler weblogic-handler
                      WebLogicCluster localhost:8888
                   </Location>
                   <Location /owc_discussions>
                      SetHandler weblogic-handler
                      WebLogicCluster localhost:8890
                   </Location>
                   <Location /em>
                      SetHandler weblogic-handler
                   </Location>
                   <Location /console>
                      SetHandler weblogic-handler
                   </Location>
                   <Location /consolehelp>
                      SetHandler weblogic-handler
                   </Location>
              * Restart UCM & WebTier
              * Test URL: http://yourServer:7777/idc
         * Configure the Identity Store for UCM & WebCenter
              * Set the password for the embedded ldap in WLS
                   Console => Domain Name => Security tab => Embedded LDAP tab => reset credentials
              * Restart AdminServer
              * Stop UCM
              * Add the following to /oracle/product/wls10320/WebCenter/ucm/config/jps-config.xml
                      <serviceInstance name="idstore.oid" provider="idstore.ldap.provider">
                          <property name="subscriber.name" value="ou=myrealm,dc=webcenter_domain"/>
                          <property name="idstore.type" value="WLS_OVD"/>
                          <property name="security.principal.key" value="ldap.credential"/>
                          <property name="security.principal.alias" value="JPS"/>
                              <property name="ldap.url" value="ldap://yourServer:7001"/>
                          <extendedProperty>
                              <name>user.search.bases</name>
                              <values><value>ou=people,ou=myrealm,dc=webcenter_domain</value></values>
                          </extendedProperty>
                          <extendedProperty>
                              <name>group.search.bases</name>
                              <values><value>ou=groups,ou=myrealm,dc=webcenter_domain</value></values>
                          </extendedProperty>
                          <property name="username.attr" value="uid"/>
                          <property name="user.login.attr" value="uid"/>
                          <property name="groupname.attr" value="cn"/>
                      </serviceInstance>
              * In the same file, change the serviceInstanceRef ref="idstore.ldap" to "idstore.oid"
              * Go to /oracle/product/wls10320/WebCenter/ucm/custom/FustionLibraries/tools
              * ./run_credtool.sh
                   Alias: default
                   Key: default
                   User Name: cn=Admin
                   Password: weblogic123
                   JPS Config: default
              * Start UCM
              * Check Provider:
                   * Go to http://yourServer:7777/idc
                   * Login : sysadmin/idc
                   * Administration -> Providers
                   * jpsuser should be good
                   * When a ldapuser exist, disable it!!
         * Configuring UCM for content search
              * Change the file /products/WebCenter11gR1/WebCenter/ucm/config/config.cfg
                  SearchIndexerEngineName=DATABASE.METADATA to SearchIndexerEngineName=DATABASE.FULLTEXT
              * Restart UCM server
              * Run the /products/WebCenter11gR1/WebCenter/ucm/database/oracle/admin/batchsnippet.sql in the wcbepsc_ocserver schema
              * Restart UCM server
              * Open the /products/WebCenter11gR1/WebCenter/ucm/bin/RepositoryManager (sysadmin/idc)
              * Recreate the indexes
         * Registering UCM with WebCenter
              * Go to http://yourServer:7777/em
              * Login with weblogic/weblogicPassword
              * Go to WebCenter - WebCenter Spaces - webcenter (WLS_Spaces)
              * From the top menu, select Settings - Service Configuration     
              * Select Content Repository
              * Add
                   Connection Name: ucm_connection
                   Repository Type: Oracle Content Server
                   Active Connection: checked
                   Administrator User Name: sysadmin
                   Root Folder: /WebCenterSpaces
                   Application Name: Spaces
                   CIS Socket Type: Socket
                   Server Host: localhost
                   Server Port: 4444
                   Authentication Method: Identity Propagation
              * Restart WLS_Spaces
         * Test the connection by creating a new group space and upload a document to the document page of this group spaceHope this helps.

  • Can I change Read and Write Permissions?

    I'm trying to get as much of my old Windows stuff onto my iMac.
    It's all stored on a Seagate 300GB External HD that is partitioned 150GB Mac and 150GB Windows NTFS. I can see and copy Folders and Files from the Windows Partition, but cannot delete once copied, this is very inconvenient as it means I have to keep unplugging the hard drive from the iMac and plugging it into my MacBook Pro (with Windoze installed) to remove the Files/Folders I have copied onto the iMac. Does anyone know how I can change the read write permissions on the Windows Partition so that I can copy then delete off it without constantly swapping computers. Thanks

    Unfortunately, this isn't a permission problem. The thing is, OS X can read NTFS partitions, but not write to them. The only filesystem that both OS X and Windows can both read and write (without third party drivers/apps anyway) is FAT32.

  • HT2963 I have a 1 TG external drive that is formatted to Windows NTFS and is read only, how do i get it to read and write on my Mac OS X 10.6.3?

    I I have a 1 TG external drive that is formatted to Windows NTFS and is read only, how do i get it to read and write on my Mac OS X 10.6.3?

    Install software such as Paragon NTFS, or reformat it as Mac OS Extended (Journaled) or FAT32. Mac OS X 10.6.5 and newer can also read and write exFAT partitions.
    (97498)

  • How to read and write on sockets?

    Hi.
    I want to read and write data from sockets, Can anybody help me.
    Regards.
    Bilal Ghazi.

    You need 3 classes. Receiver, RemoteThread and Sender. These classes are not tested by me
    //these classes are on the clientside
    public class Receiver{//listens to connections
    ServerSocket serverSocket = new ServerSocket(port);
    while (...){
    Socket client=serverSocket.accept();//waits for new connection
    RemoteThread thread=new RemoteThread(client);
    thread.start();
    serverSocket.close();
    public class RemoteThread{
    final static int BUSYWAITTIME=10;//10 ms
    Socket socket;
    public RemoteThread(Socket _socket) {
    this.socket = _socket;
    public void run() {
    BufferedOutputStream out = new java.io.BufferedOutputStream(socket.getOutputStream(),socket.getSendBufferSize());
    int inBuffSize=socket.getReceiveBufferSize();
    BufferedInputStream in = new java.io.BufferedInputStream(socket.getInputStream(),inBuffSize);//wait until get enuff
    byte[] buff=new byte[inBuffSize];
    while (...) {
    //read
    while(in.available()<=0 && !stopped){//just wait for it to become ready
    try{wait(BUSYWAITTIME);}catch(InterruptedException e){}
    int readBytes=in.read(buff);
    //do something with the bytes in buff
    //This class is on the clientside
    public class Sender{
    Socket socket = new Socket(host, port);//connects to server
    OutputStream out = socket.getOutputStream();
    PrintWriter outPrinter=new PrintWriter(out,true);
    InputStream in = socket.getInputStream();
    //use out or outPrinter to write to server
    Gil

  • Seperate read and write thread example

    hi.
    can anyone tell me a simplest way to implement thread to read and write from the socket seperately without blocing each other?
    how do i create seperate threads for a client to write and read from a serversocket?
    maskeeeee

    hi.
    can anyone tell me a simplest way to implement thread
    to read and write from the socket seperately without
    blocing each other?
    how do i create seperate threads for a client to write
    and read from a serversocket?Extend java.lang.Thread or implement java.lang.Runnable
    and RTFM for both of them. Lots of nice code examples in them thar
    API docs.
    matfud

  • Can't read or write some files, internet is failing, youtube won't load, software I tried to install was in Slovenian, not dutch or english like in my systempreferences settings, pictures and files won't preview with spacebar, etc. Malware?

    Specs:
    iMac 10.8.5
    3,4 GHz Intel Core i7
    32 GB 1600 MHz DDR3
    Can't read or write some files, internet is failing, youtube won't load, security software I tried to install was in Slovenian, not dutch or english like in my systempreferences settings, pictures and files won't preview with spacebar and are randomly corrupted, when I entered something in the Youtube searchbar (when it was still working) it send me to a site with sexadds.
    I tried restart my iMac and when I was logged back in, my dock preferences were reset.
    Also tried to download some security software to check my Mac for malware, but when I did, I tried several, I got a notification that said something like 'dumpfiles (don't know if this is the right translation...) damaged'.
    I'm taking screenshots from all the weird notifications I get and even three quarters off the screenshots I took in the last three hours are already unreadable.
    It started this morning when I tried opening a Premiere Pro file on which I worked the night before.
    When I tried opening it, it said the file was damaged and could not be openend.
    I tried opening it with AE or importing the file in a new project but nothing helped.
    When I tried looking for autosaves, this is the really weird part, there were none.
    Even though there are autosaves from my other projects, this one was completely gone.
    It looked like the day before never happened on my computer.
    Also when I openend Premiere all the recent projects had been wiped.
    So at first I thought it was a Premiere Pro failure.
    But than, later on the day, I tried loading some RAW files from my compact flash card.
    This is where I would get an error (error -36) which said some data cannot be read or written.
    I tried importing the files with a view different technics, from dragging to importing via Lightroom and I succeeded with Image Browser.
    But when I tried moving the files to an other folder the same error occurred.
    While dealing with this issue I wanted to put on some soothing music on youtube.
    This is when the next weird thing occurred: youtube wasn't completely loading in Chrome. I refreshed a view times, checked the internet connection and still no difference.
    When I tried in Safari it did work but when I clicked enter on the searchbar in Youtube, a page with sexadds appeared (I didn't install AdBlock in Safari...).
    I read about this 'phishing' where you are redirected to a site were a possible malware installment can take place...
    I don't know if it's connected to any of the problems I've been having but I just never experienced this on a mac, I have been a Mac user for 10 years now.
    On top of it all, internet started working worse and worse and now it's not even working at all. I had to fill in the password over and over, normally it remembers.
    Just like my system preferences, all the preferences I had with Chrome where also reset.
    Also somewhere in between I got this notification: Mac OS X must restore library to run programs. Type your password to allow.
    To me this is all very weird and suspicious. I have clearly no idea what's going on. Could this be another sort of trojan horse or malware?
    Some background info which could be helpful for solving this mystery:
    two months ago the one year old Fusion Drive in my iMac just broke out of nowhere.
    I got it replaced by a qualified apple repair store.
    When I got my computer back, all the files where gone.
    I got on the internet without AdBlock installed yet.
    A game or whatever it was, can't clearly remember, got installed by accident.
    I deleted it immediately.
    Only two weeks later, I couldn't log in to my account. It didn't recognize my password and username. 
    So I brought my mac back to the store.
    Here the repair guy said it was a minor thing and he just needed to reconnect my account. He also mentioned he found a downloaded game name Sparta and it probably had something to do with the error.
    I asked him; could it be a virus? He replied no way.
    I don't know why I couldn't be a virus, just because it's a mac doesn't mean it cannot be done.
    So today I tried installing anti virus software (such as avast- was in a weird language looked like slovenian, clamxav - was in slovenian) but I couldn't install them.
    PLEASE help me! I don't know what to do anymore, I work fulltime and I need my computer, I have no time to bring it in for repair, are there other perhaps easier ways?
    Could this be the work of a virus or a malware? Or is it a disk permissions issue?

    It sounds like you may have multiple problems, but none of them are likely to be caused by malware.
    First, the internet-related issues may be related to adware or a network compromise. I tend to lean more towards the latter, based on your description of the problem. See:
    http://www.adwaremedic.com/kb/baddns.php
    http://www.adwaremedic.com/kb/hackedrouter.php
    If investigation shows that this is not a network-specific issue, then it's probably adware. See my Adware Removal Guide for help finding and removing it. Note that you mention AdBlock as if it should have prevented this, but it's important to understand that ad blockers do not protect you against adware in any way. Neither would any kind of anti-virus software, which often doesn't detect adware.
    As for the other issues, it sounds like you've got some serious corruption. I would be inclined to say it sounds like a failing drive, except it sounds like you just got it replaced. How did you get all your files back after the new drive was installed?
    (Fair disclosure: I may receive compensation from links to my sites, TheSafeMac.com and AdwareMedic.com, in the form of buttons allowing for donations. Donations are not required to use my site or software.)

Maybe you are looking for

  • How to get proper breakthrough in SAP ABAP

    hi experts , i was going through different threads that getting job as SAP ABAP fresher is very tough .If i consider my profile i have only 3.5 years of software development experience .If i do ABAP then i will be fresher in SAP . 1)so how should i p

  • Parental Controls - Internet Access Stopped!

    My wife has a white MacBook running Leopard 10.5.8.  It has worked fine for two years.  Nothing was changed.  She could not change anythign due to being logged into a managed account. It could always access the internet over our home (or any availabl

  • How to remove old iTunes store I'd?

    Can not make an updates for apps. asking for a password of a previous user How ow to change it?

  • How do I change Save to Desktop to Apple+D

    I used to be able to tell any SAVE window to "save to the desktop" by hitting Apple+D. That is broken in Mavericks. How do I change the command, Apple+D, to save to my desktop in Mavericks Save Window?

  • OSX Leopard enormous icons

    Just a general ruminating question. Anyone know why OSX Leopard (or any other OSX version that I recall) starts out life with absolutely ENORMOUS icons? I have no idea how to feed comments back to Apple, or indeed if they are interested, but I am sea