Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

Java: invalid type code

  • 12-04-2008 1:10am
    #1
    Registered Users, Registered Users 2 Posts: 590 ✭✭✭


    Hi.

    I'm trying to write a piece of code that reads a file (a serialized java object) from a ftp server. It works perfectly in Linux but for some reason will not work on any Windows machine I've tried. It throws a StreamCorruptedException saying invalid type code 0A. This seems to be happening in the reading of the object using the ObjectInputStream object. Below you can see two different methods I've attempted. I also tried using the InputStream = ftp.retrieve(String fileName) method with the same results. Anyone have any ideas as to what's going on here? It seems to be a Windows specific problem. Note that neither Windows or Linux has any problems writing to the ftp server. And Linux can read the file written by Windows fine.
    try {
    			ftp.connect("ftp.hostname.com");
    
    			int reply = ftp.getReplyCode();
    			if (!FTPReply.isPositiveCompletion(reply)) {
    				ftp.disconnect();
    				JOptionPane.showMessageDialog(null,
    						"FTP server refused connection.");
    				throw new IOException();
    			}
    
    			ftp.login("username", "password");
    
    			ftp.changeWorkingDirectory(folderLocation);
    		
    			/*
    			FileOutputStream fos = new FileOutputStream("C:\\rankings.ser");
    			ftp.retrieveFile(fileName, fos);
    			fos.flush();
    			JOptionPane.showMessageDialog(null, "finished output");
    			ObjectInputStream ois = new ObjectInputStream(new FileInputStream("C:\\rankings.ser"));
    			JOptionPane.showMessageDialog(null, "About to read object");
    			readObject = ois.readObject();
    			JOptionPane.showMessageDialog(null, "object read");
    			fos.close();
    			ois.close();
    			*/
    			
    			ByteArrayOutputStream baos = new ByteArrayOutputStream();			
    			ftp.retrieveFile(fileName, baos);
    			ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
    			ObjectInputStream ois = new ObjectInputStream(bais);
    			readObject = ois.readObject();
    			baos.close();
    			ois.close();
    			
    			ftp.logout();
    		} catch (StreamCorruptedException e) {
    			JOptionPane.showMessageDialog(null, "Stream Corrupted Exception");
    			GamePanel.errorMsg += e.getMessage();
    			GamePanel.errorMsg += e.getStackTrace();	
    		} catch (SocketException e) {
    			JOptionPane.showMessageDialog(null, "Socket exception");
    			GamePanel.errorMsg += e.getMessage();
    			GamePanel.errorMsg += e.getStackTrace();
    		} catch (IOException e) {
    			JOptionPane.showMessageDialog(null, "IO exception");
    			GamePanel.errorMsg += e.getMessage();
    			GamePanel.errorMsg += e.getStackTrace();
    		} catch (ClassNotFoundException e) {
    			JOptionPane.showMessageDialog(null, "Class not found");
    			GamePanel.errorMsg += e.getMessage();
    			GamePanel.errorMsg += e.getStackTrace();
    		} finally {
    			if (ftp.isConnected()) {
    				try {
    					ftp.disconnect();
    				} catch (IOException ioe) {
    					JOptionPane.showMessageDialog(null,
    							"Error disconnecting. Details: "
    									+ ioe.getStackTrace());
    				}
    			}
    		}
    

    Any help would be appreciated as I'm really stuck on this one!


Comments

  • Registered Users, Registered Users 2 Posts: 590 ✭✭✭bman


    Got the answer elsewhere. Had to put the connection into binary mode (in case someone else ever gets stuck on this one).


Advertisement