public static HTTPRange parseRangeHeader(String header, long fileSize) {
		long rangeBeginLong = 0;
		long rangeEndLong = fileSize - 1;
		long rangeLength = (rangeEndLong - rangeBeginLong) + 1;
		
		if (header == null) {
			return new HTTPRange (rangeBeginLong, rangeEndLong, rangeLength);
		}

		if (header.length() == 0) {
			return new HTTPRange (rangeBeginLong, rangeEndLong, rangeLength);
		};

		
		String rangeHeader = header;


		try {
			//System.out.println("1 Range header is =" + rangeHeader);
			rangeHeader = rangeHeader.substring(rangeHeader.indexOf('=') + 1);
			//System.out.println("2 Range header is now =" + rangeHeader);
			String rangeBegin = rangeHeader.substring(0, rangeHeader
					.indexOf('-'));
			//System.out.println("3 Range begin is =" + rangeBegin);
			String rangeEnd = rangeHeader
					.substring(rangeHeader.indexOf('-') + 1);
			//System.out.println("4 Range end is =" + rangeEnd);

			if (rangeBegin.length() > 0) {
				rangeBeginLong = Long.parseLong(rangeBegin);
			}

			if (rangeEnd.length() > 0) {
				rangeEndLong = Long.parseLong(rangeEnd);
			}

			rangeLength = (rangeEndLong - rangeBeginLong) + 1; // BLA

			// swap if other ranges
			if (rangeBeginLong > rangeEndLong) {
				long t = rangeEndLong;
				rangeEndLong = rangeBeginLong;
				rangeBeginLong = t;
				
			}
			
			long from = rangeBeginLong;
			long to = rangeEndLong;
			long len = rangeLength;

			return new HTTPRange (from, to, len);
			
		} catch (Exception e) {
			e.printStackTrace();
			rangeBeginLong = 0;
			rangeEndLong = fileSize - 1;
			rangeLength = (rangeEndLong - rangeBeginLong) + 1;

			return new HTTPRange (rangeBeginLong, rangeEndLong, rangeLength);
		}
		

	}