if ("oracle".equals(ConfigurationManager.getProperty("db.name"))) { bitstream.setColumn("size_bytes", (int) file.length()); } else { bitstream.setColumn("size", (int) file.length()); }
bitstream.setColumn("size_bytes", (int) file.length());
	public static int register(Context context, int assetstore,				String bitstreamPath) throws SQLException, IOException {		// mark this bitstream as a registered bitstream		String sInternalId = REGISTERED_FLAG + bitstreamPath;		// Create a deleted bitstream row, using a separate DB connection		TableRow bitstream;		Context tempContext = null;		try {			tempContext = new Context();			bitstream = DatabaseManager.create(tempContext, "Bitstream");			bitstream.setColumn("deleted", true);			bitstream.setColumn("internal_id", sInternalId);			bitstream.setColumn("store_number", assetstore);			DatabaseManager.update(tempContext, bitstream);			tempContext.complete();		} catch (SQLException sqle) {			if (tempContext != null) {				tempContext.abort();			}			throw sqle;		}		// get a reference to the file		GeneralFile file = getFile(bitstream);		// read through a DigestInputStream that will work out the MD5		//		// DSpace refers to checksum, writes it in METS, and uses it as an		// AIP filename (!), but never seems to validate with it. Furthermore,		// DSpace appears to hardcode the algorithm to MD5 in some places--see 		// METSExport.java.		//		// To remain compatible with DSpace we calculate an MD5 checksum on 		// LOCAL registered files. But for REMOTE (e.g. SRB) files we 		// calculate an MD5 on just the fileNAME. The reasoning is that in the 		// case of a remote file, calculating an MD5 on the file itself will		// generate network traffic to read the file's bytes. In this case it 		// would be better have a proxy process calculate MD5 and store it as 		// an SRB metadata attribute so it can be retrieved simply from SRB.		//		// TODO set this up as a proxy server process so no net activity				// FIXME this is a first class HACK! for the reasons described above		if (file instanceof LocalFile) 		{			// get MD5 on the file for local file			DigestInputStream dis = null;			try 			{				dis = new DigestInputStream(FileFactory.newFileInputStream(file), 						MessageDigest.getInstance("MD5"));			} 			catch (NoSuchAlgorithmException e) 			{				log.warn("Caught NoSuchAlgorithmException", e);				throw new IOException("Invalid checksum algorithm");			}			catch (IOException e) 			{				log.error("File: " + file.getAbsolutePath() 						+ " to be registered cannot be opened - is it "						+ "really there?");				throw e;			}			final int BUFFER_SIZE = 1024 * 4;			final byte[] buffer = new byte[BUFFER_SIZE];			while (true) 			{				final int count = dis.read(buffer, 0, BUFFER_SIZE);				if (count == -1) 				{					break;				}			}			bitstream.setColumn("checksum", Utils.toHex(dis.getMessageDigest()					.digest()));			dis.close();		} 		else if (file instanceof SRBFile)		{			if (!file.exists())			{				log.error("File: " + file.getAbsolutePath() 						+ " is not in SRB MCAT");				throw new IOException("File is not in SRB MCAT");			}			// get MD5 on just the filename (!) for SRB file			int iLastSlash = bitstreamPath.lastIndexOf('/');			String sFilename = bitstreamPath.substring(iLastSlash + 1);			MessageDigest md = null;			try 			{				md = MessageDigest.getInstance("MD5");			} 			catch (NoSuchAlgorithmException e) 			{				log.error("Caught NoSuchAlgorithmException", e);				throw new IOException("Invalid checksum algorithm");			}			bitstream.setColumn("checksum", 					Utils.toHex(md.digest(sFilename.getBytes())));		}		else		{			throw new IOException("Unrecognized file type - "					+ "not local, not SRB");		}		bitstream.setColumn("checksum_algorithm", "MD5");		// oracle v. postgresql - 'size' (legacy) is reserved word in oracle		if ("oracle".equals(ConfigurationManager.getProperty("db.name"))) 		{			bitstream.setColumn("size_bytes", (int) file.length());		} 		else 		{			bitstream.setColumn("size", (int) file.length());		}		bitstream.setColumn("deleted", false);		DatabaseManager.update(context, bitstream);		int bitstream_id = bitstream.getIntColumn("bitstream_id");		if (log.isDebugEnabled()) 		{			log.debug("Stored bitstream " + bitstream_id + " in file "					+ file.getAbsolutePath());		}		return bitstream_id;	}