public void validate(Object obj, Errors errors) { FileBucket file = (FileBucket) obj; if (file.getFile() != null) { if (file.getFile().getSize() == 0) { errors.rejectValue("file", "missing.file"); } } }
private Entry getEntry(Long key) { int hash = (key == null) ? 0 : hash(key); FileBucket fb = table[indexFor(hash, table.length)]; for (Entry e = fb.getEntry(); e != null; e = e.next) { Long k; if (e.getKey().equals(key)) return e; } return null; }
private void addEntry(int hash, Long key, String value, int bucketIndex) { FileBucket fb = table[bucketIndex]; if ((fb.getFileSize() >= getBucketSizeLimit()) && (null != table[bucketIndex])) { resize(2 * table.length); hash = (null != key) ? hash(key) : 0; bucketIndex = indexFor(hash, table.length); } createEntry(hash, key, value, bucketIndex); }
@Override public boolean containsValue(String value) { if (value == null) return false; for (FileBucket fb : table) { for (Entry e = fb.getEntry(); e != null; e = e.next) if (e.getValue().equals(value)) { return true; } } return false; }
@Override public Long getKey(String value) { if (value == null) return 0L; for (FileBucket fb : table) for (Entry e = fb.getEntry(); e != null; e = e.next) { if (e.getValue().equals(value)) { return e.getKey(); } } return null; }
private void transfer(FileBucket[] newTable) { int newCapacity = newTable.length; for (FileBucket fb : table) { Entry e = fb.getEntry(); while (null != e) { Entry next = e.next; int i = indexFor(e.hash, newCapacity); e.next = newTable[i].getEntry(); newTable[i].putEntry(e); e = next; } } }
@Override public void put(Long key, String value) { if (key == null) return; int hash = hash(key); int i = indexFor(hash, table.length); FileBucket fb = table[i]; for (Entry e = fb.getEntry(); e != null; e = e.next) { Long k; if (e.hash == hash && ((k = e.key) == key || key.equals(k))) { e.value = value; return; } } addEntry(hash, key, value, i); }
@RequestMapping(method = RequestMethod.POST) public String uploadFile( @ModelAttribute FileBucket fileBucket, HttpServletRequest request, Model model) { List<MultipartFile> files = fileBucket.getFiles(); for (MultipartFile file : files) { try { File f = new File(context.getRealPath("") + "/" + file.getOriginalFilename()); if (!f.exists()) f.createNewFile(); file.transferTo(f); } catch (IOException e) { e.printStackTrace(); } } return "result"; }
private void createEntry(int hash, Long key, String value, int bucketIndex) { FileBucket fb = table[bucketIndex]; Entry e = fb.getEntry(); fb.putEntry(new Entry(hash, key, value, e)); size++; }